diff --git a/lib/synth-audio.js b/lib/synth-audio.js index 7b64f24..edee6bd 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -146,7 +146,7 @@ async function synthAudio(client, logger, stats, { account_sid, ) || ( !process.env.JAMBONES_DISABLE_TTS_STREAMING && - vendor === 'elevenlabs' + ['elevenlabs', 'deepgram'].includes(vendor) ) ) { filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`; @@ -212,7 +212,9 @@ async function synthAudio(client, logger, stats, { account_sid, if (audioBuffer?.filePath) return audioBuffer; break; case 'deepgram': - audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text}); + audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text, + renderForCaching, disableTtsStreaming}); + if (audioBuffer?.filePath) return audioBuffer; break; case vendor.startsWith('custom') ? vendor : 'cant_match_value': ({ audioBuffer, filePath } = await synthCustomVendor(logger, @@ -720,8 +722,22 @@ const synthWhisper = async(logger, {credentials, stats, voice, text, renderForCa } }; -const synthDeepgram = async(logger, {credentials, stats, model, text}) => { +const synthDeepgram = async(logger, {credentials, stats, model, text, renderForCaching, disableTtsStreaming}) => { const {api_key} = credentials; + if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) { + let params = ''; + params += `{api_key=${api_key}`; + params += ',vendor=deepgram'; + params += `,voice=${model}`; + params += ',write_cache_file=1'; + params += '}'; + + return { + filePath: `say:${params}${text.replace(/\n/g, ' ')}`, + servedFromCache: false, + rtt: 0 + }; + } try { const post = bent('https://api.deepgram.com', 'POST', 'buffer', { 'Authorization': `Token ${api_key}`, diff --git a/test/synth.js b/test/synth.js index 44c4782..2fe922b 100644 --- a/test/synth.js +++ b/test/synth.js @@ -595,6 +595,7 @@ test('Deepgram speech synth tests', async(t) => { }, model: 'aura-asteria-en', text, + renderForCaching: true }); t.ok(!opts.servedFromCache, `successfully synthesized deepgram audio to ${opts.filePath}`);