From 5328a60de86c7887655bac498cf91a1138fa0da9 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Wed, 3 Sep 2025 06:35:20 +0700 Subject: [PATCH] support custom tts Stream --- lib/synth-audio.js | 22 ++++++++++++++++++++-- test/synth.js | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/synth-audio.js b/lib/synth-audio.js index 7130972..2fb1cf6 100644 --- a/lib/synth-audio.js +++ b/lib/synth-audio.js @@ -271,7 +271,7 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc break; case vendor.startsWith('custom') ? vendor : 'cant_match_value': audioData = await synthCustomVendor(logger, - {credentials, stats, language, voice, key, text}); + {credentials, stats, language, voice, key, text, renderForCaching, disableTtsStreaming}); break; default: assert(`synthAudio: unsupported speech vendor ${vendor}`); @@ -818,9 +818,27 @@ const synthNvidia = async(client, logger, { }; -const synthCustomVendor = async(logger, {credentials, stats, language, voice, text, filePath}) => { +const synthCustomVendor = async(logger, {credentials, stats, language, voice, + text, filePath, renderForCaching, disableTtsStreaming, key}) => { const {vendor, auth_token, custom_tts_url} = credentials; + if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) { + let params = '{'; + params += `auth_token=${auth_token}`; + params += `,playback_id=${key}`; + params += `,custom_tts_url=${custom_tts_url}`; + params += ',vendor=custom'; + params += `,voice=${voice}`; + params += ',write_cache_file=1'; + params += '}'; + + return { + filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`, + servedFromCache: false, + rtt: 0 + }; + } + try { const post = bent('POST', { 'Authorization': `Bearer ${auth_token}`, diff --git a/test/synth.js b/test/synth.js index fddad81..8f088e4 100644 --- a/test/synth.js +++ b/test/synth.js @@ -554,6 +554,7 @@ test('Custom Vendor speech synth tests', async(t) => { language: 'en-US', voice: 'English-US.Female-1', text: 'This is a test. This is only a test', + renderForCaching: true }); t.ok(!opts.servedFromCache, `successfully synthesized custom vendor audio to ${opts.filePath}`); t.ok(opts.filePath.endsWith('wav'), 'audio is cached as wav file'); @@ -575,6 +576,7 @@ test('Custom Vendor speech synth tests', async(t) => { language: 'en-US', voice: 'English-US.Female-1', text: 'This is a test. This is only a test', + renderForCaching: true }); t.ok(opts.servedFromCache, `successfully get custom vendor cached audio to ${opts.filePath}`); t.ok(opts.filePath.endsWith('wav'), 'audio is cached as wav file'); @@ -589,6 +591,7 @@ test('Custom Vendor speech synth tests', async(t) => { language: 'en-US', voice: 'English-US.Female-1', text: 'This is a test. This is only a test', + renderForCaching: true }); t.ok(!opts.servedFromCache, `successfully synthesized Custom Vendor audio to ${opts.filePath}`); obj = await getJSON(`http://127.0.0.1:3100/lastRequest/somethingnew2`);