mod_deepgra_tts

This commit is contained in:
Quan HL
2024-04-03 20:46:52 +07:00
parent fbed59e5de
commit f3cc38089c
2 changed files with 19 additions and 2 deletions

View File

@@ -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}`,

View File

@@ -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}`);