UNPKG

@wiro-ai/n8n-nodes-wiroai

Version:

n8n community node for Wiro AI's Generative AI APIs.

127 lines 4.93 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GenerateSpeechTts = void 0; const n8n_workflow_1 = require("n8n-workflow"); const auth_1 = require("../utils/auth"); const polling_1 = require("../utils/polling"); class GenerateSpeechTts { constructor() { this.description = { displayName: 'Wiro - Generate Speech', name: 'generateSpeechTts', icon: { light: 'file:wiro.svg', dark: 'file:wiro.svg' }, group: ['transform'], version: 1, description: 'Converts text to speech using Wiro AI', defaults: { name: 'Wiro - Generate Speech', }, inputs: ["main"], outputs: ["main"], usableAsTool: true, credentials: [ { name: 'wiroApi', required: true, }, ], properties: [ { displayName: 'Prompt', name: 'prompt', type: 'string', default: '', required: true, description: 'The text prompt to convert into speech audio', }, { displayName: 'Voice', name: 'voice', type: 'options', options: [ { name: 'Alloy', value: 'af_alloy' }, { name: 'Heart', value: 'af_heart' }, { name: 'Jessica', value: 'af_jessica' }, { name: 'Nova', value: 'af_nova' }, { name: 'Santa', value: 'am_santa' }, ], default: 'af_heart', required: true, description: 'Choose a voice character for the generated speech', }, { displayName: 'Language', name: 'langCode', type: 'options', options: [ { name: 'American English', value: 'a' }, { name: 'Brazilian Portuguese', value: 'p' }, { name: 'British English', value: 'b' }, { name: 'French', value: 'f' }, { name: 'Hindi', value: 'h' }, { name: 'Italian', value: 'i' }, { name: 'Spanish', value: 'e' }, ], default: 'a', required: true, description: 'Select the language variant for the spoken output', }, ], }; } async execute() { const returnData = []; const prompt = this.getNodeParameter('prompt', 0); const voice = this.getNodeParameter('voice', 0); const langCode = this.getNodeParameter('langCode', 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/kokoro_tts', headers: { ...headers, 'Content-Type': 'application/json', }, body: { prompt, voice, langCode, }, 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.GenerateSpeechTts = GenerateSpeechTts; //# sourceMappingURL=GenerateSpeechTts.node.js.map