@jambonz/speech-utils 0.0.41 → 0.0.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/synth-audio.js +29 -14
- package/package.json +1 -1
- package/test/synth.js +1 -1
package/lib/synth-audio.js
CHANGED
|
@@ -77,7 +77,7 @@ const trimTrailingSilence = (buffer) => {
|
|
|
77
77
|
*/
|
|
78
78
|
async function synthAudio(client, logger, stats, { account_sid,
|
|
79
79
|
vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId,
|
|
80
|
-
disableTtsCache, renderForCaching, options
|
|
80
|
+
disableTtsCache, renderForCaching, disableTtsStreaming, options
|
|
81
81
|
}) {
|
|
82
82
|
let audioBuffer;
|
|
83
83
|
let servedFromCache = false;
|
|
@@ -200,17 +200,14 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|
|
200
200
|
break;
|
|
201
201
|
case 'elevenlabs':
|
|
202
202
|
audioBuffer = await synthElevenlabs(logger, {
|
|
203
|
-
credentials, options, stats, language, voice, text, renderForCaching, filePath
|
|
203
|
+
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming, filePath
|
|
204
204
|
});
|
|
205
|
-
if (
|
|
206
|
-
return audioBuffer;
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
audioBuffer = await synthElevenlabs(logger, {credentials, options, stats, language, voice, text, filePath});
|
|
210
|
-
}
|
|
205
|
+
if (audioBuffer?.filePath) return audioBuffer;
|
|
211
206
|
break;
|
|
212
207
|
case 'whisper':
|
|
213
|
-
audioBuffer = await synthWhisper(logger, {
|
|
208
|
+
audioBuffer = await synthWhisper(logger, {
|
|
209
|
+
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
|
210
|
+
if (audioBuffer?.filePath) return audioBuffer;
|
|
214
211
|
break;
|
|
215
212
|
case 'deepgram':
|
|
216
213
|
audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text});
|
|
@@ -607,12 +604,14 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
|
|
607
604
|
}
|
|
608
605
|
};
|
|
609
606
|
|
|
610
|
-
const synthElevenlabs = async(logger, {
|
|
607
|
+
const synthElevenlabs = async(logger, {
|
|
608
|
+
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
|
609
|
+
}) => {
|
|
611
610
|
const {api_key, model_id, options: credOpts} = credentials;
|
|
612
611
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
|
613
612
|
|
|
614
613
|
/* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
|
|
615
|
-
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching) {
|
|
614
|
+
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
616
615
|
let params = '';
|
|
617
616
|
params += `{api_key=${api_key}`;
|
|
618
617
|
params += `,model_id=${model_id}`;
|
|
@@ -656,8 +655,24 @@ const synthElevenlabs = async(logger, {credentials, options, stats, language, vo
|
|
|
656
655
|
}
|
|
657
656
|
};
|
|
658
657
|
|
|
659
|
-
const synthWhisper = async(logger, {credentials, stats, voice, text}) => {
|
|
660
|
-
const {api_key, model_id, baseURL, timeout} = credentials;
|
|
658
|
+
const synthWhisper = async(logger, {credentials, stats, voice, text, renderForCaching, disableTtsStreaming}) => {
|
|
659
|
+
const {api_key, model_id, baseURL, timeout, speed} = credentials;
|
|
660
|
+
/* if the env is set to stream then bag out, unless we are specifically rendering to generate a cache file */
|
|
661
|
+
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
662
|
+
let params = '';
|
|
663
|
+
params += `{api_key=${api_key}`;
|
|
664
|
+
params += `,model_id=${model_id}`;
|
|
665
|
+
params += `,voice=${voice}`;
|
|
666
|
+
params += ',write_cache_file=1';
|
|
667
|
+
if (speed) params += `,speed=${speed}`;
|
|
668
|
+
params += '}';
|
|
669
|
+
|
|
670
|
+
return {
|
|
671
|
+
filePath: `say:${params}${text.replace(/\n/g, ' ')}`,
|
|
672
|
+
servedFromCache: false,
|
|
673
|
+
rtt: 0
|
|
674
|
+
};
|
|
675
|
+
}
|
|
661
676
|
try {
|
|
662
677
|
const openai = new OpenAI.OpenAI({
|
|
663
678
|
apiKey: api_key,
|
|
@@ -682,7 +697,7 @@ const synthWhisper = async(logger, {credentials, stats, voice, text}) => {
|
|
|
682
697
|
const synthDeepgram = async(logger, {credentials, stats, model, text}) => {
|
|
683
698
|
const {api_key} = credentials;
|
|
684
699
|
try {
|
|
685
|
-
const post = bent('https://api.
|
|
700
|
+
const post = bent('https://api.deepgram.com', 'POST', 'buffer', {
|
|
686
701
|
'Authorization': `Token ${api_key}`,
|
|
687
702
|
'Accept': 'audio/mpeg',
|
|
688
703
|
'Content-Type': 'application/json'
|
package/package.json
CHANGED
package/test/synth.js
CHANGED
|
@@ -537,7 +537,7 @@ test('Deepgram speech synth tests', async(t) => {
|
|
|
537
537
|
credentials: {
|
|
538
538
|
api_key: process.env.DEEPGRAM_API_KEY
|
|
539
539
|
},
|
|
540
|
-
model: '
|
|
540
|
+
model: 'aura-asteria-en',
|
|
541
541
|
text,
|
|
542
542
|
});
|
|
543
543
|
t.ok(!opts.servedFromCache, `successfully synthesized deepgram audio to ${opts.filePath}`);
|