UNPKG

n8n-nodes-elevenlabs

Version:

Complete implementation of ElevenLabs AI voice generation into n8n workflows.

273 lines 9.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SpeechOperations = void 0; exports.SpeechOperations = [ { displayName: 'Operation', name: 'operation', type: 'options', noDataExpression: true, displayOptions: { show: { resource: ['speech'], }, }, options: [ { name: 'Text to Speech', value: 'text-to-speech', action: 'Generate speech from text', description: 'Generate a speech from a text', routing: { send: { preSend: [preSendText], }, }, }, { name: 'Speech to Speech', value: 'speech-to-speech', action: 'Generate speech from speech', description: 'Generate a speech from a speech', routing: { send: { preSend: [preSendUploadAudio], }, request: { headers: { 'Content-Type': 'multipart/form-data', }, }, output: { postReceive: [returnBinary], }, }, }, ], default: 'text-to-speech', routing: { request: { url: '={{"/" + $parameter["operation"] + "/" + $parameter["voice_id"]}}', qs: { optimize_streaming_latency: '={{$parameter["additionalFields"]["optimize_streaming_latency"]}}', output_format: '={{$parameter["additionalFields"]["output_format"]}}', }, returnFullResponse: true, encoding: 'arraybuffer', }, output: { postReceive: [returnBinary], }, }, }, { displayName: 'Text', description: 'The Text to transform into Speech', required: true, name: 'text', type: 'string', default: 'Be good to people!', displayOptions: { show: { operation: ['text-to-speech'], }, }, }, { displayName: 'Voice ID', description: 'The voice you want to use', name: 'voice_id', type: 'resourceLocator', default: { mode: 'list', value: null }, modes: [ { displayName: 'From list', name: 'list', type: 'list', hint: 'Choose from list', typeOptions: { searchListMethod: 'listVoices', searchable: true, }, }, { displayName: 'ID', name: 'id', type: 'string', hint: 'Enter an ID', placeholder: 'XYZ123', }, ], displayOptions: { show: { resource: ['speech'], }, }, required: true, }, { displayName: 'Additional Fields', name: 'additionalFields', type: 'collection', default: {}, placeholder: 'Add Fields', displayOptions: { show: { resource: ['speech'], }, }, options: [ { displayName: 'Binary Name', description: 'Change the output binary name', name: 'binary_name', type: 'string', default: 'data', }, { displayName: 'File Name', description: 'Change the output file name', name: 'file_name', type: 'string', default: 'voice', }, { displayName: 'Streaming Latency', description: 'Turn on latency optimizations at some cost of quality', name: 'optimize_streaming_latency', type: 'number', default: 0, typeOptions: { maxValue: 4, minValue: 0, numberStepSize: 1, }, }, { displayName: 'Output Format', description: 'Output format of the generated audio', name: 'output_format', type: 'string', default: 'mp3_44100_128', }, { displayName: 'Model Name or ID', description: 'Identifier of the model that will be used. Choose from the list, or specify an ID using an <a href="https://docs.n8n.io/code-examples/expressions/">expression</a>.', name: 'model_id', type: 'options', typeOptions: { loadOptionsMethod: 'listModels', }, default: '', }, { displayName: 'Stability', description: 'Define voice stability', name: 'stability', type: 'number', default: 0.5, typeOptions: { maxValue: 1, minValue: 0, numberStepSize: 0.01, }, }, { displayName: 'Similarity Boost', description: 'Define voice similarity boost', name: 'similarity_boost', type: 'number', default: 0.75, typeOptions: { maxValue: 1, minValue: 0, numberStepSize: 0.01, }, }, { displayName: 'Stitching', description: 'Whether stitching is activated', name: 'stitching', type: 'boolean', default: true, }, { displayName: 'Style', description: 'Exaggerate voice style', name: 'style', type: 'number', default: 0, typeOptions: { maxValue: 1, minValue: 0, numberStepSize: 0.01, }, }, { displayName: 'Speaker Boost', description: 'Whether speaker boost is activated', name: 'use_speaker_boost', type: 'boolean', default: false, }, { displayName: 'Seed', description: 'Define a fixed seed', name: 'seed', type: 'number', default: 0, }, ], }, ]; async function preSendUploadAudio(requestOptions) { const formData = new FormData(); const audioBuffer = await this.helpers.getBinaryDataBuffer('data'); formData.append('audio', new Blob([audioBuffer])); requestOptions.body = formData; return requestOptions; } async function preSendText(requestOptions) { var _a; const text = this.getNodeParameter('text'); const model_id = this.getNodeParameter('model_id', null); const seed = this.getNodeParameter('seed', 0); const stability = this.getNodeParameter('additionalFields.stability', 0.5); const similarity_boost = this.getNodeParameter('additionalFields.similarity_boost', 1); const style = this.getNodeParameter('additionalFields.style', 0); const use_speaker_boost = this.getNodeParameter('additionalFields.use_speaker_boost', true); const stitching = this.getNodeParameter('additionalFields.stitching', false); const data = { text: text, voice_settings: { stability: stability, similarity_boost: similarity_boost, style: style, use_speaker_boost: use_speaker_boost, }, }; if (stitching) { if (seed) data.seed = seed; if (model_id) data.model_id = model_id; const runIndex = this.getItemIndex(); const texts = []; (_a = this.getExecuteData().data.main[0]) === null || _a === void 0 ? void 0 : _a.forEach((text) => { texts.push(text.json.text); }); if (runIndex > 0) data.previous_text = texts[runIndex - 1]; if (runIndex < texts.length - 1) data.next_text = texts[runIndex + 1]; } requestOptions.body = data; return requestOptions; } async function returnBinary(items, responseData) { const binary_name = this.getNodeParameter('additionalFields["binary_name"]', 'data'); const file_name = this.getNodeParameter('additionalFields["file_name"]', 'voice'); const binaryData = await this.helpers.prepareBinaryData(responseData.body, file_name, 'audio/mp3'); return items.map(() => ({ json: responseData.headers, binary: { [binary_name]: binaryData } })); } //# sourceMappingURL=speech.js.map