From f3cc38089c1bab4c68e61a3a145a0f00de78ce73 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Wed, 3 Apr 2024 20:46:52 +0700 Subject: [PATCH 1/2] mod_deepgra_tts --- lib/synth-audio.js | 20 ++++++++++++++++++-- test/synth.js | 1 + 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/synth-audio.js b/lib/synth-audio.js index f7f4a96..c34cdb3 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -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, @@ -719,8 +721,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}`); From 0471b94ebe949eb664149ac08048904adf155140 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Thu, 4 Apr 2024 10:12:24 +0700 Subject: [PATCH 2/2] wip --- lib/synth-audio.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/synth-audio.js b/lib/synth-audio.js index c34cdb3..cb49653 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`;