@wiro-ai/n8n-nodes-wiroai
Version:
n8n community node for Wiro AI's Generative AI APIs.
163 lines • 6.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GenerateSoundEffectVideo = void 0;
const n8n_workflow_1 = require("n8n-workflow");
const auth_1 = require("../utils/auth");
const polling_1 = require("../utils/polling");
class GenerateSoundEffectVideo {
constructor() {
this.description = {
displayName: 'Wiro - Generate Sound Effects for Video',
name: 'generateSoundEffectVideo',
icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' },
group: ['transform'],
version: 1,
description: 'Generates sound effects for video using AI',
defaults: {
name: 'Wiro - Generate Sound Effects for Video',
},
inputs: ["main"],
outputs: ["main"],
usableAsTool: true,
credentials: [
{
name: 'wiroApi',
required: true,
},
],
properties: [
{
displayName: 'Input Video URL',
name: 'inputVideoUrl',
type: 'string',
default: '',
required: true,
description: 'URL of the video to which the sound effect will be applied',
},
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
default: '',
description: 'Prompt describing the sound effect style',
},
{
displayName: 'Negative Prompt',
name: 'negativePrompt',
type: 'string',
default: 'bad, blurry',
required: true,
description: 'Prompt to avoid undesired outputs',
},
{
displayName: 'Steps',
name: 'steps',
type: 'number',
typeOptions: {
minValue: 1,
maxValue: 100,
},
default: 30,
required: true,
description: 'Number of inference steps',
},
{
displayName: 'Duration',
name: 'duration',
type: 'number',
typeOptions: {
minValue: 1,
maxValue: 30,
},
default: 8.0,
required: true,
description: 'Duration of the generated video in seconds',
},
{
displayName: 'Strength',
name: 'strength',
type: 'number',
typeOptions: {
minValue: 1,
maxValue: 10,
},
default: 4.5,
required: true,
description: 'Strength of the visual effect',
},
{
displayName: 'Seed',
name: 'seed',
type: 'string',
default: '2873497',
required: true,
description: 'Random seed for reproducibility',
},
],
};
}
async execute() {
const returnData = [];
const inputVideoUrl = this.getNodeParameter('inputVideoUrl', 0);
const prompt = this.getNodeParameter('prompt', 0);
const negativePrompt = this.getNodeParameter('negativePrompt', 0);
const steps = this.getNodeParameter('steps', 0);
const duration = this.getNodeParameter('duration', 0);
const strength = this.getNodeParameter('strength', 0);
const seed = this.getNodeParameter('seed', 0);
const credentials = await this.getCredentials('wiroApi');
const apiKey = credentials.apiKey;
const apiSecret = credentials.apiSecret;
const headers = (0, auth_1.generateWiroAuthHeaders)(apiKey, apiSecret);
const response = await this.helpers.request({
method: 'POST',
url: 'https://api.wiro.ai/v1/Run/wiro/mmaudio',
headers: {
...headers,
'Content-Type': 'application/json',
},
body: {
inputVideo: '',
inputVideoUrl,
prompt,
negativePrompt,
steps,
duration,
strength,
seed,
},
json: true,
});
if (!(response === null || response === void 0 ? void 0 : response.taskid) || !(response === null || response === void 0 ? void 0 : response.socketaccesstoken)) {
throw new n8n_workflow_1.NodeApiError(this.getNode(), {
message: 'Wiro API did not return a valid task ID or socket access token ' +
JSON.stringify(response),
});
}
const taskid = response.taskid;
const socketaccesstoken = response.socketaccesstoken;
const result = await polling_1.pollTaskUntilComplete.call(this, socketaccesstoken, headers);
const responseJSON = {
taskid: taskid,
url: '',
status: '',
};
switch (result) {
case '-1':
case '-2':
case '-3':
case '-4':
responseJSON.status = 'failed';
break;
default:
responseJSON.status = 'completed';
responseJSON.url = result !== null && result !== void 0 ? result : '';
}
returnData.push({
json: responseJSON,
});
return [returnData];
}
}
exports.GenerateSoundEffectVideo = GenerateSoundEffectVideo;
//# sourceMappingURL=GenerateSoundEffectVideo.node.js.map