UNPKG

n8n-nodes-coze

Version:

n8n node for Coze(扣子), supporting AI chat, workflow automation, file processing, and text-to-speech.

77 lines 2.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.executeAudio = executeAudio; const stream_1 = require("stream"); async function executeAudio(i) { const operation = this.getNodeParameter('operation', i); const authentication = this.getNodeParameter('authentication', i); if (operation === 'speech') { const credentials = await this.getCredentials(authentication); const inputText = this.getNodeParameter('inputText', i); const voiceId = this.getNodeParameter('voiceId', i); const body = { input: inputText, voice_id: voiceId, }; const responseFormat = this.getNodeParameter('responseFormat', i); if (responseFormat) { body.response_format = responseFormat; } const speed = this.getNodeParameter('speed', i); if (speed) { body.speed = speed; } const sampleRate = this.getNodeParameter('sampleRate', i); if (sampleRate) { body.sample_rate = sampleRate; } const options = { baseURL: credentials.baseUrl, method: 'POST', url: `/v1/audio/speech`, body, json: true, encoding: null, }; const response = await this.helpers.requestWithAuthentication.call(this, authentication, options); const fileName = `speech.${responseFormat}`; const binaryData = await this.helpers.prepareBinaryData.call(this, response, fileName); return { json: {}, binary: { data: binaryData, }, }; } else if (operation === 'transcriptions') { const credentials = await this.getCredentials(authentication); const binaryPropertyName = this.getNodeParameter('binaryPropertyName', i); const item = this.getInputData(i)[0]; if (item.binary === undefined || item.binary[binaryPropertyName] === undefined) { throw new Error('No binary data found to transcribe!'); } const binaryData = item.binary[binaryPropertyName]; const buffer = await this.helpers.getBinaryDataBuffer(i, binaryPropertyName); const stream = stream_1.Readable.from(buffer); const options = { baseURL: credentials.baseUrl, method: 'POST', url: `/v1/audio/transcriptions`, headers: { 'Content-Type': 'multipart/form-data', }, formData: { file: { value: stream, options: { filename: binaryData.fileName, contentType: binaryData.mimeType, }, }, }, json: true, }; return this.helpers.requestWithAuthentication.call(this, authentication, options); } } //# sourceMappingURL=audio.js.map