From e0e4d47340d981ac8c7102ef3bc1fae81dbf5ec3 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Mon, 29 Jul 2024 20:53:55 +0700 Subject: [PATCH] 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;