UNPKG

n8n-nodes-salutespeech

Version:

User-friendly SaluteSpeech (Sber) community node

67 lines 2.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.post_text_synthesize = post_text_synthesize; const utils_1 = require("./utils"); const exception_1 = require("./exception"); function getRequestConfig({ text, voiceId, format, freq, accessToken, }) { const headers = { ...(0, utils_1.buildHeaders)(accessToken), 'Content-Type': 'application/text' }; const query = { format, voice: `${voiceId}_${freq}`, }; return { method: 'POST', url: '/text:synthesize', data: text, params: query, headers: headers, responseType: 'arraybuffer', }; } function mimeAndExtByFormat(format) { switch ((format || '').toLowerCase()) { case 'wav16': return { mime: 'audio/wav', ext: 'wav' }; case 'pcm16': return { mime: 'audio/L16', ext: 'pcm' }; case 'opus': return { mime: 'audio/ogg', ext: 'ogg' }; case 'alaw': return { mime: 'audio/PCMA', ext: 'alaw' }; case 'g729': return { mime: 'audio/G729', ext: 'g729' }; default: return { mime: 'application/octet-stream', ext: 'bin' }; } } function buildResponse(response, format) { var _a; if (response.status === 200) { const buffer = Buffer.from(response.data); const { mime, ext } = mimeAndExtByFormat(format); const fileName = `audio.${ext}`; return { buffer, mime, fileName, size: buffer.byteLength, headers: (_a = response.headers) !== null && _a !== void 0 ? _a : {}, }; } else if (response.status === 401) { console.error(response.data); throw new exception_1.AuthenticationError(response); } else { console.error(response.data); throw new exception_1.ResponseError(response); } } async function post_text_synthesize(client, args) { const config = getRequestConfig(args); console.log('post_text_synthesize.config', config); const response = await client.request(config); console.log('post_text_synthesize.response', response); return buildResponse(response, args.format) || []; } //# sourceMappingURL=PostTextSynthesize.js.map