deepgram tts support endpoint for on-premise

This commit is contained in:
Quan HL
2024-07-29 19:45:13 +07:00
parent 7f6a3d349c
commit a595faa378

View File

@@ -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;