@andresaya/n8n-nodes-edgetts
Version:
n8n node for Edge TTS - Text-to-Speech using Microsoft Edge capabilities
71 lines • 2.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.textToSpeech = textToSpeech;
const n8n_workflow_1 = require("n8n-workflow");
const edge_tts_1 = require("@andresaya/edge-tts");
async function textToSpeech(itemIndex) {
const inputText = this.getNodeParameter('inputText', itemIndex);
const inputType = this.getNodeParameter('inputType', itemIndex, 'auto');
const voice = this.getNodeParameter('voice', itemIndex, '');
const additionalOptions = this.getNodeParameter('additionalOptions', itemIndex, {});
const pitch = additionalOptions.pitch || '0Hz';
const rate = additionalOptions.rate || '0%';
const volume = additionalOptions.volume || '0%';
const includeAudioInfo = additionalOptions.includeAudioInfo;
const includeMetadata = additionalOptions.includeMetadata;
if (!inputText) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Input text is required');
}
if (inputType !== 'ssml' && !voice) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'Voice is required for text input');
}
try {
const startTime = Date.now();
const tts = new edge_tts_1.EdgeTTS();
const synthesizeOptions = {
pitch,
rate,
volume,
inputType,
};
const synthesizeStart = Date.now();
const voiceToUse = voice || 'en-US-AriaNeural';
await tts.synthesize(inputText, voiceToUse, synthesizeOptions);
const synthesizeTime = Date.now() - synthesizeStart;
const conversionStart = Date.now();
const audioBase64 = tts.toBase64();
const conversionTime = Date.now() - conversionStart;
const response = {
success: true,
voice: voice || 'SSML',
audio: audioBase64,
performance: {
synthesizeMs: synthesizeTime,
conversionMs: conversionTime,
totalMs: Date.now() - startTime,
},
};
if (includeAudioInfo) {
const audioInfo = tts.getAudioInfo();
response.audioInfo = {
size: audioInfo.size,
duration: audioInfo.estimatedDuration,
format: audioInfo.format,
};
}
if (includeMetadata) {
try {
const metadata = tts.getWordBoundaries();
response.metadata = metadata;
}
catch (error) {
response.metadata = null;
}
}
return response;
}
catch (error) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), `Failed to synthesize speech: ${error.message}`);
}
}
//# sourceMappingURL=textToSpeech.js.map