@jambonz/speech-utils 0.2.20 → 0.2.22
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 +43 -40
- package/package.json +1 -1
package/lib/synth-audio.js
CHANGED
|
@@ -53,9 +53,6 @@ const EXPIRES = JAMBONES_TTS_CACHE_DURATION_MINS;
|
|
|
53
53
|
const OpenAI = require('openai');
|
|
54
54
|
const getAwsAuthToken = require('./get-aws-sts-token');
|
|
55
55
|
|
|
56
|
-
/* counter for playback id */
|
|
57
|
-
let playbackIdCounter = 0;
|
|
58
|
-
|
|
59
56
|
const trimTrailingSilence = (buffer) => {
|
|
60
57
|
assert.ok(buffer instanceof Buffer, 'trimTrailingSilence - argument is not a Buffer');
|
|
61
58
|
|
|
@@ -207,74 +204,74 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
|
|
207
204
|
const startAt = process.hrtime();
|
|
208
205
|
switch (vendor) {
|
|
209
206
|
case 'google':
|
|
210
|
-
audioData = await synthGoogle(logger, {credentials, stats, language, voice, gender, text});
|
|
207
|
+
audioData = await synthGoogle(logger, {credentials, stats, language, voice, gender, key, text});
|
|
211
208
|
break;
|
|
212
209
|
case 'aws':
|
|
213
210
|
case 'polly':
|
|
214
211
|
vendorLabel = 'aws';
|
|
215
212
|
audioData = await synthPolly(createHash, retrieveHash, logger,
|
|
216
|
-
{credentials, stats, language, voice, text, engine, renderForCaching, disableTtsStreaming});
|
|
213
|
+
{credentials, stats, language, voice, key, text, engine, renderForCaching, disableTtsStreaming});
|
|
217
214
|
break;
|
|
218
215
|
case 'azure':
|
|
219
216
|
case 'microsoft':
|
|
220
217
|
vendorLabel = 'microsoft';
|
|
221
|
-
audioData = await synthMicrosoft(logger, {credentials, stats, language, voice, text, deploymentId,
|
|
218
|
+
audioData = await synthMicrosoft(logger, {credentials, stats, language, voice, key, text, deploymentId,
|
|
222
219
|
renderForCaching, disableTtsStreaming});
|
|
223
220
|
break;
|
|
224
221
|
case 'nuance':
|
|
225
222
|
model = model || 'enhanced';
|
|
226
|
-
audioData = await synthNuance(client, logger, {credentials, stats, voice, model, text});
|
|
223
|
+
audioData = await synthNuance(client, logger, {credentials, stats, voice, model, key, text});
|
|
227
224
|
break;
|
|
228
225
|
case 'nvidia':
|
|
229
|
-
audioData = await synthNvidia(client, logger, {credentials, stats, language, voice, model, text,
|
|
226
|
+
audioData = await synthNvidia(client, logger, {credentials, stats, language, voice, model, key, text,
|
|
230
227
|
renderForCaching, disableTtsStreaming});
|
|
231
228
|
break;
|
|
232
229
|
case 'ibm':
|
|
233
|
-
audioData = await synthIbm(logger, {credentials, stats, voice, text});
|
|
230
|
+
audioData = await synthIbm(logger, {credentials, stats, voice, key, text});
|
|
234
231
|
break;
|
|
235
232
|
case 'wellsaid':
|
|
236
|
-
audioData = await synthWellSaid(logger, {credentials, stats, language, voice, text});
|
|
233
|
+
audioData = await synthWellSaid(logger, {credentials, stats, language, voice, key, text});
|
|
237
234
|
break;
|
|
238
235
|
case 'elevenlabs':
|
|
239
236
|
audioData = await synthElevenlabs(logger, {
|
|
240
|
-
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
|
237
|
+
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
|
241
238
|
break;
|
|
242
239
|
case 'playht':
|
|
243
240
|
audioData = await synthPlayHT(client, logger, {
|
|
244
|
-
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
|
241
|
+
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
|
245
242
|
break;
|
|
246
243
|
case 'cartesia':
|
|
247
244
|
audioData = await synthCartesia(logger, {
|
|
248
|
-
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
|
245
|
+
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
|
249
246
|
break;
|
|
250
247
|
case 'inworld':
|
|
251
248
|
audioData = await synthInworld(logger, {
|
|
252
|
-
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
|
249
|
+
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
|
253
250
|
break;
|
|
254
251
|
case 'rimelabs':
|
|
255
252
|
audioData = await synthRimelabs(logger, {
|
|
256
|
-
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
|
253
|
+
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
|
257
254
|
break;
|
|
258
255
|
case 'whisper':
|
|
259
256
|
audioData = await synthWhisper(logger, {
|
|
260
|
-
credentials, stats, voice, text, instructions, renderForCaching, disableTtsStreaming});
|
|
257
|
+
credentials, stats, voice, key, text, instructions, renderForCaching, disableTtsStreaming});
|
|
261
258
|
break;
|
|
262
259
|
case 'verbio':
|
|
263
260
|
audioData = await synthVerbio(client, logger, {
|
|
264
|
-
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
|
261
|
+
credentials, stats, voice, key, text, renderForCaching, disableTtsStreaming});
|
|
265
262
|
if (audioData?.filePath) return audioData;
|
|
266
263
|
break;
|
|
267
264
|
case 'deepgram':
|
|
268
|
-
audioData = await synthDeepgram(logger, {credentials, stats, model, text,
|
|
265
|
+
audioData = await synthDeepgram(logger, {credentials, stats, model, key, text,
|
|
269
266
|
renderForCaching, disableTtsStreaming});
|
|
270
267
|
break;
|
|
271
268
|
case 'resemble':
|
|
272
269
|
audioData = await synthResemble(logger, {
|
|
273
|
-
credentials, stats, voice, text, options, renderForCaching, disableTtsStreaming});
|
|
270
|
+
credentials, stats, voice, key, text, options, renderForCaching, disableTtsStreaming});
|
|
274
271
|
break;
|
|
275
272
|
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
|
276
273
|
audioData = await synthCustomVendor(logger,
|
|
277
|
-
{credentials, stats, language, voice, text});
|
|
274
|
+
{credentials, stats, language, voice, key, text});
|
|
278
275
|
break;
|
|
279
276
|
default:
|
|
280
277
|
assert(`synthAudio: unsupported speech vendor ${vendor}`);
|
|
@@ -309,12 +306,13 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
|
|
309
306
|
}
|
|
310
307
|
|
|
311
308
|
const synthPolly = async(createHash, retrieveHash, logger,
|
|
312
|
-
{credentials, stats, language, voice, engine, text, renderForCaching, disableTtsStreaming}) => {
|
|
309
|
+
{credentials, stats, language, voice, engine, key, text, renderForCaching, disableTtsStreaming}) => {
|
|
313
310
|
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
|
314
311
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
315
312
|
|
|
316
313
|
let params = '{';
|
|
317
314
|
params += `language=${language}`;
|
|
315
|
+
params += `,playback_id=${key}`;
|
|
318
316
|
params += ',write_cache_file=1';
|
|
319
317
|
params += ',vendor=aws';
|
|
320
318
|
if (accessKeyId && secretAccessKey) {
|
|
@@ -562,6 +560,7 @@ const synthMicrosoft = async(logger, {
|
|
|
562
560
|
stats,
|
|
563
561
|
language,
|
|
564
562
|
voice,
|
|
563
|
+
key,
|
|
565
564
|
text,
|
|
566
565
|
renderForCaching,
|
|
567
566
|
disableTtsStreaming
|
|
@@ -593,6 +592,7 @@ const synthMicrosoft = async(logger, {
|
|
|
593
592
|
!renderForCaching && !disableTtsStreaming) {
|
|
594
593
|
let params = '{';
|
|
595
594
|
params += `api_key=${apiKey}`;
|
|
595
|
+
params += `,playback_id=${key}`;
|
|
596
596
|
params += `,language=${language}`;
|
|
597
597
|
params += ',vendor=microsoft';
|
|
598
598
|
params += `,voice=${voice}`;
|
|
@@ -769,12 +769,13 @@ const synthNuance = async(client, logger, {credentials, stats, voice, model, tex
|
|
|
769
769
|
};
|
|
770
770
|
|
|
771
771
|
const synthNvidia = async(client, logger, {
|
|
772
|
-
credentials, stats, language, voice, model, text, renderForCaching, disableTtsStreaming
|
|
772
|
+
credentials, stats, language, voice, model, key, text, renderForCaching, disableTtsStreaming
|
|
773
773
|
}) => {
|
|
774
774
|
const {riva_server_uri} = credentials;
|
|
775
775
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
776
776
|
let params = '';
|
|
777
777
|
params += `{riva_server_uri=${riva_server_uri}`;
|
|
778
|
+
params += `,playback_id=${key}`;
|
|
778
779
|
params += `,voice=${voice}`;
|
|
779
780
|
params += `,language=${language}`;
|
|
780
781
|
params += ',write_cache_file=1';
|
|
@@ -848,7 +849,7 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
|
|
848
849
|
};
|
|
849
850
|
|
|
850
851
|
const synthElevenlabs = async(logger, {
|
|
851
|
-
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
|
852
|
+
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
|
852
853
|
}) => {
|
|
853
854
|
const {api_key, model_id, options: credOpts} = credentials;
|
|
854
855
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
|
@@ -857,7 +858,7 @@ const synthElevenlabs = async(logger, {
|
|
|
857
858
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
858
859
|
let params = '{';
|
|
859
860
|
params += `api_key=${api_key}`;
|
|
860
|
-
params += `,playback_id=${
|
|
861
|
+
params += `,playback_id=${key}`;
|
|
861
862
|
params += ',vendor=elevenlabs';
|
|
862
863
|
params += `,voice=${voice}`;
|
|
863
864
|
params += `,model_id=${model_id}`;
|
|
@@ -912,7 +913,7 @@ const synthElevenlabs = async(logger, {
|
|
|
912
913
|
};
|
|
913
914
|
|
|
914
915
|
const synthPlayHT = async(client, logger, {
|
|
915
|
-
credentials, options, stats, voice, language, text, renderForCaching, disableTtsStreaming
|
|
916
|
+
credentials, options, stats, voice, language, key, text, renderForCaching, disableTtsStreaming
|
|
916
917
|
}) => {
|
|
917
918
|
const {api_key, user_id, voice_engine, playht_tts_uri, options: credOpts} = credentials;
|
|
918
919
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
|
@@ -948,7 +949,7 @@ const synthPlayHT = async(client, logger, {
|
|
|
948
949
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
949
950
|
let params = '{';
|
|
950
951
|
params += `api_key=${api_key}`;
|
|
951
|
-
params += `,playback_id=${
|
|
952
|
+
params += `,playback_id=${key}`;
|
|
952
953
|
params += `,user_id=${user_id}`;
|
|
953
954
|
params += ',vendor=playht';
|
|
954
955
|
params += `,voice=${voice}`;
|
|
@@ -1007,7 +1008,7 @@ const synthPlayHT = async(client, logger, {
|
|
|
1007
1008
|
};
|
|
1008
1009
|
|
|
1009
1010
|
const synthInworld = async(logger, {
|
|
1010
|
-
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
|
1011
|
+
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
|
1011
1012
|
}) => {
|
|
1012
1013
|
const {api_key, model_id, options: credOpts} = credentials;
|
|
1013
1014
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
|
@@ -1016,7 +1017,7 @@ const synthInworld = async(logger, {
|
|
|
1016
1017
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
1017
1018
|
let params = '{';
|
|
1018
1019
|
params += `api_key=${api_key}`;
|
|
1019
|
-
params += `,playback_id=${
|
|
1020
|
+
params += `,playback_id=${key}`;
|
|
1020
1021
|
params += `,model_id=${model_id}`;
|
|
1021
1022
|
params += ',vendor=inworld';
|
|
1022
1023
|
params += `,voice=${voice}`;
|
|
@@ -1072,7 +1073,7 @@ const synthInworld = async(logger, {
|
|
|
1072
1073
|
};
|
|
1073
1074
|
|
|
1074
1075
|
const synthRimelabs = async(logger, {
|
|
1075
|
-
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming
|
|
1076
|
+
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming
|
|
1076
1077
|
}) => {
|
|
1077
1078
|
const {api_key, model_id, options: credOpts} = credentials;
|
|
1078
1079
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
|
@@ -1081,7 +1082,7 @@ const synthRimelabs = async(logger, {
|
|
|
1081
1082
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
1082
1083
|
let params = '{';
|
|
1083
1084
|
params += `api_key=${api_key}`;
|
|
1084
|
-
params += `,playback_id=${
|
|
1085
|
+
params += `,playback_id=${key}`;
|
|
1085
1086
|
params += `,model_id=${model_id}`;
|
|
1086
1087
|
params += ',vendor=rimelabs';
|
|
1087
1088
|
params += `,language=${language}`;
|
|
@@ -1129,7 +1130,9 @@ const synthRimelabs = async(logger, {
|
|
|
1129
1130
|
throw err;
|
|
1130
1131
|
}
|
|
1131
1132
|
};
|
|
1132
|
-
const synthVerbio = async(client, logger, {
|
|
1133
|
+
const synthVerbio = async(client, logger, {
|
|
1134
|
+
credentials, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
|
1135
|
+
}) => {
|
|
1133
1136
|
//https://doc.speechcenter.verbio.com/#tag/Text-To-Speech-REST-API
|
|
1134
1137
|
if (text.length > 2000) {
|
|
1135
1138
|
throw new Error('Verbio cannot synthesize for the text length larger than 2000 characters');
|
|
@@ -1138,7 +1141,7 @@ const synthVerbio = async(client, logger, {credentials, stats, voice, text, rend
|
|
|
1138
1141
|
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
1139
1142
|
let params = '{';
|
|
1140
1143
|
params += `access_token=${token.access_token}`;
|
|
1141
|
-
params += `,playback_id=${
|
|
1144
|
+
params += `,playback_id=${key}`;
|
|
1142
1145
|
params += ',vendor=verbio';
|
|
1143
1146
|
params += `,voice=${voice}`;
|
|
1144
1147
|
params += ',write_cache_file=1';
|
|
@@ -1175,14 +1178,14 @@ const synthVerbio = async(client, logger, {credentials, stats, voice, text, rend
|
|
|
1175
1178
|
}
|
|
1176
1179
|
};
|
|
1177
1180
|
|
|
1178
|
-
const synthWhisper = async(logger, {credentials, stats, voice, text, instructions,
|
|
1181
|
+
const synthWhisper = async(logger, {credentials, stats, voice, key, text, instructions,
|
|
1179
1182
|
renderForCaching, disableTtsStreaming}) => {
|
|
1180
1183
|
const {api_key, model_id, baseURL, timeout, speed} = credentials;
|
|
1181
1184
|
/* if the env is set to stream then bag out, unless we are specifically rendering to generate a cache file */
|
|
1182
1185
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
1183
1186
|
let params = '{';
|
|
1184
1187
|
params += `api_key=${api_key}`;
|
|
1185
|
-
params += `,playback_id=${
|
|
1188
|
+
params += `,playback_id=${key}`;
|
|
1186
1189
|
params += `,model_id=${model_id}`;
|
|
1187
1190
|
params += ',vendor=whisper';
|
|
1188
1191
|
params += `,voice=${voice}`;
|
|
@@ -1224,12 +1227,12 @@ const synthWhisper = async(logger, {credentials, stats, voice, text, instruction
|
|
|
1224
1227
|
}
|
|
1225
1228
|
};
|
|
1226
1229
|
|
|
1227
|
-
const synthDeepgram = async(logger, {credentials, stats, model, text, renderForCaching, disableTtsStreaming}) => {
|
|
1230
|
+
const synthDeepgram = async(logger, {credentials, stats, model, key, text, renderForCaching, disableTtsStreaming}) => {
|
|
1228
1231
|
const {api_key, deepgram_tts_uri} = credentials;
|
|
1229
1232
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
1230
1233
|
let params = '{';
|
|
1231
1234
|
params += `api_key=${api_key}`;
|
|
1232
|
-
params += `,playback_id=${
|
|
1235
|
+
params += `,playback_id=${key}`;
|
|
1233
1236
|
params += ',vendor=deepgram';
|
|
1234
1237
|
params += `,voice=${model}`;
|
|
1235
1238
|
params += ',write_cache_file=1';
|
|
@@ -1265,7 +1268,7 @@ const synthDeepgram = async(logger, {credentials, stats, model, text, renderForC
|
|
|
1265
1268
|
};
|
|
1266
1269
|
|
|
1267
1270
|
const synthCartesia = async(logger, {
|
|
1268
|
-
credentials, options, stats, voice, language, text, renderForCaching, disableTtsStreaming
|
|
1271
|
+
credentials, options, stats, voice, language, key, text, renderForCaching, disableTtsStreaming
|
|
1269
1272
|
}) => {
|
|
1270
1273
|
const {api_key, model_id, embedding, options: credOpts} = credentials;
|
|
1271
1274
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
|
@@ -1273,7 +1276,7 @@ const synthCartesia = async(logger, {
|
|
|
1273
1276
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
1274
1277
|
let params = '{';
|
|
1275
1278
|
params += `api_key=${api_key}`;
|
|
1276
|
-
params += `,playback_id=${
|
|
1279
|
+
params += `,playback_id=${key}`;
|
|
1277
1280
|
params += `,model_id=${model_id}`;
|
|
1278
1281
|
params += ',vendor=cartesia';
|
|
1279
1282
|
params += `,voice=${voice}`;
|
|
@@ -1336,7 +1339,7 @@ const synthCartesia = async(logger, {
|
|
|
1336
1339
|
};
|
|
1337
1340
|
|
|
1338
1341
|
const synthResemble = async(logger, {
|
|
1339
|
-
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
|
1342
|
+
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
|
1340
1343
|
}) => {
|
|
1341
1344
|
const {api_key, resemble_tts_uri, resemble_tts_use_tls} = credentials;
|
|
1342
1345
|
const {project_uuid, use_hd} = options || {};
|
|
@@ -1345,7 +1348,7 @@ const synthResemble = async(logger, {
|
|
|
1345
1348
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
|
1346
1349
|
let params = '{';
|
|
1347
1350
|
params += `api_key=${api_key}`;
|
|
1348
|
-
params += `,playback_id=${
|
|
1351
|
+
params += `,playback_id=${key}`;
|
|
1349
1352
|
params += ',vendor=resemble';
|
|
1350
1353
|
params += `,voice=${voice}`;
|
|
1351
1354
|
params += ',write_cache_file=1';
|