From a595faa378d2d485686417b31e7f72d6d7294cb3 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Mon, 29 Jul 2024 19:45:13 +0700 Subject: [PATCH 1/3] deepgram tts support endpoint for on-premise --- lib/synth-audio.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/synth-audio.js b/lib/synth-audio.js index 516073c..32c4717 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -909,13 +909,14 @@ const synthWhisper = async(logger, {credentials, stats, voice, text, renderForCa }; const synthDeepgram = async(logger, {credentials, stats, model, text, renderForCaching, disableTtsStreaming}) => { - const {api_key} = credentials; + const {api_key, deepgram_tts_uri} = credentials; if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) { let params = ''; params += `{api_key=${api_key}`; params += ',vendor=deepgram'; params += `,voice=${model}`; params += ',write_cache_file=1'; + if (deepgram_tts_uri) params += `,endpoint=${deepgram_tts_uri}`; params += '}'; return { @@ -925,12 +926,19 @@ const synthDeepgram = async(logger, {credentials, stats, model, text, renderForC }; } try { - const post = bent('https://api.deepgram.com', 'POST', 'buffer', { + let host = 'https://api.deepgram.com'; + let path = '/v1/speak'; + if (deepgram_tts_uri) { + const arr = /^(https?:\/\/[^\/]+)(\/.*)?$/.exec(deepgram_tts_uri); + host = arr[1]; + path = arr[2]; + } + const post = bent(host, 'POST', 'buffer', { 'Authorization': `Token ${api_key}`, 'Accept': 'audio/mpeg', 'Content-Type': 'application/json' }); - const mp3 = await post(`/v1/speak?model=${model}`, { + const mp3 = await post(`${path}?model=${model}`, { text }); return mp3; From e0e4d47340d981ac8c7102ef3bc1fae81dbf5ec3 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Mon, 29 Jul 2024 20:53:55 +0700 Subject: [PATCH 2/3] wip --- lib/synth-audio.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/synth-audio.js b/lib/synth-audio.js index 32c4717..eff00d9 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -151,6 +151,11 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc assert.ok(voice, 'synthAudio requires voice when verbio is used'); assert.ok(credentials.client_id, 'synthAudio requires client_id when verbio is used'); assert.ok(credentials.client_secret, 'synthAudio requires client_secret when verbio is used'); + } else if ('deepgram' === vendor) { + if (!credentials.deepgram_tts_uri) { + assert.ok(credentials.api_key, 'synthAudio requires api_key when deepgram is used'); + } + } const key = makeSynthKey({ account_sid, @@ -926,19 +931,13 @@ const synthDeepgram = async(logger, {credentials, stats, model, text, renderForC }; } try { - let host = 'https://api.deepgram.com'; - let path = '/v1/speak'; - if (deepgram_tts_uri) { - const arr = /^(https?:\/\/[^\/]+)(\/.*)?$/.exec(deepgram_tts_uri); - host = arr[1]; - path = arr[2]; - } - const post = bent(host, 'POST', 'buffer', { - 'Authorization': `Token ${api_key}`, + const post = bent(deepgram_tts_uri || 'https://api.deepgram.com', 'POST', 'buffer', { + // on-premise deepgram does not require to have api_key + ...(api_key && {'Authorization': `Token ${api_key}`}), 'Accept': 'audio/mpeg', 'Content-Type': 'application/json' }); - const mp3 = await post(`${path}?model=${model}`, { + const mp3 = await post(`/v1/speak?model=${model}`, { text }); return mp3; From 461178e726e478170f00dfa419fa5e195ed7e0b0 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Mon, 29 Jul 2024 20:56:55 +0700 Subject: [PATCH 3/3] 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 eff00d9..f55c91d 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -155,7 +155,7 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc if (!credentials.deepgram_tts_uri) { assert.ok(credentials.api_key, 'synthAudio requires api_key when deepgram is used'); } - + } const key = makeSynthKey({ account_sid,