mirror of
https://github.com/jambonz/speech-utils.git
synced 2025-12-19 03:37:49 +00:00
use synth key as playback id
This commit is contained in:
@@ -53,9 +53,6 @@ const EXPIRES = JAMBONES_TTS_CACHE_DURATION_MINS;
|
||||
const OpenAI = require('openai');
|
||||
const getAwsAuthToken = require('./get-aws-sts-token');
|
||||
|
||||
/* counter for playback id */
|
||||
let playbackIdCounter = 0;
|
||||
|
||||
const trimTrailingSilence = (buffer) => {
|
||||
assert.ok(buffer instanceof Buffer, 'trimTrailingSilence - argument is not a Buffer');
|
||||
|
||||
@@ -207,74 +204,74 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
const startAt = process.hrtime();
|
||||
switch (vendor) {
|
||||
case 'google':
|
||||
audioData = await synthGoogle(logger, {credentials, stats, language, voice, gender, text});
|
||||
audioData = await synthGoogle(logger, {credentials, stats, language, voice, gender, key, text});
|
||||
break;
|
||||
case 'aws':
|
||||
case 'polly':
|
||||
vendorLabel = 'aws';
|
||||
audioData = await synthPolly(createHash, retrieveHash, logger,
|
||||
{credentials, stats, language, voice, text, engine, renderForCaching, disableTtsStreaming});
|
||||
{credentials, stats, language, voice, key, text, engine, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'azure':
|
||||
case 'microsoft':
|
||||
vendorLabel = 'microsoft';
|
||||
audioData = await synthMicrosoft(logger, {credentials, stats, language, voice, text, deploymentId,
|
||||
audioData = await synthMicrosoft(logger, {credentials, stats, language, voice, key, text, deploymentId,
|
||||
renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'nuance':
|
||||
model = model || 'enhanced';
|
||||
audioData = await synthNuance(client, logger, {credentials, stats, voice, model, text});
|
||||
audioData = await synthNuance(client, logger, {credentials, stats, voice, model, key, text});
|
||||
break;
|
||||
case 'nvidia':
|
||||
audioData = await synthNvidia(client, logger, {credentials, stats, language, voice, model, text,
|
||||
audioData = await synthNvidia(client, logger, {credentials, stats, language, voice, model, key, text,
|
||||
renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'ibm':
|
||||
audioData = await synthIbm(logger, {credentials, stats, voice, text});
|
||||
audioData = await synthIbm(logger, {credentials, stats, voice, key, text});
|
||||
break;
|
||||
case 'wellsaid':
|
||||
audioData = await synthWellSaid(logger, {credentials, stats, language, voice, text});
|
||||
audioData = await synthWellSaid(logger, {credentials, stats, language, voice, key, text});
|
||||
break;
|
||||
case 'elevenlabs':
|
||||
audioData = await synthElevenlabs(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'playht':
|
||||
audioData = await synthPlayHT(client, logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'cartesia':
|
||||
audioData = await synthCartesia(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'inworld':
|
||||
audioData = await synthInworld(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'rimelabs':
|
||||
audioData = await synthRimelabs(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'whisper':
|
||||
audioData = await synthWhisper(logger, {
|
||||
credentials, stats, voice, text, instructions, renderForCaching, disableTtsStreaming});
|
||||
credentials, stats, voice, key, text, instructions, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'verbio':
|
||||
audioData = await synthVerbio(client, logger, {
|
||||
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, stats, voice, key, text, renderForCaching, disableTtsStreaming});
|
||||
if (audioData?.filePath) return audioData;
|
||||
break;
|
||||
case 'deepgram':
|
||||
audioData = await synthDeepgram(logger, {credentials, stats, model, text,
|
||||
audioData = await synthDeepgram(logger, {credentials, stats, model, key, text,
|
||||
renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case 'resemble':
|
||||
audioData = await synthResemble(logger, {
|
||||
credentials, stats, voice, text, options, renderForCaching, disableTtsStreaming});
|
||||
credentials, stats, voice, key, text, options, renderForCaching, disableTtsStreaming});
|
||||
break;
|
||||
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
||||
audioData = await synthCustomVendor(logger,
|
||||
{credentials, stats, language, voice, text});
|
||||
{credentials, stats, language, voice, key, text});
|
||||
break;
|
||||
default:
|
||||
assert(`synthAudio: unsupported speech vendor ${vendor}`);
|
||||
@@ -309,13 +306,13 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
}
|
||||
|
||||
const synthPolly = async(createHash, retrieveHash, logger,
|
||||
{credentials, stats, language, voice, engine, text, renderForCaching, disableTtsStreaming}) => {
|
||||
{credentials, stats, language, voice, engine, key, text, renderForCaching, disableTtsStreaming}) => {
|
||||
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
|
||||
let params = '{';
|
||||
params += `language=${language}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += ',vendor=aws';
|
||||
if (accessKeyId && secretAccessKey) {
|
||||
@@ -563,6 +560,7 @@ const synthMicrosoft = async(logger, {
|
||||
stats,
|
||||
language,
|
||||
voice,
|
||||
key,
|
||||
text,
|
||||
renderForCaching,
|
||||
disableTtsStreaming
|
||||
@@ -594,7 +592,7 @@ const synthMicrosoft = async(logger, {
|
||||
!renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${apiKey}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,language=${language}`;
|
||||
params += ',vendor=microsoft';
|
||||
params += `,voice=${voice}`;
|
||||
@@ -771,13 +769,13 @@ const synthNuance = async(client, logger, {credentials, stats, voice, model, tex
|
||||
};
|
||||
|
||||
const synthNvidia = async(client, logger, {
|
||||
credentials, stats, language, voice, model, text, renderForCaching, disableTtsStreaming
|
||||
credentials, stats, language, voice, model, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
const {riva_server_uri} = credentials;
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{riva_server_uri=${riva_server_uri}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,voice=${voice}`;
|
||||
params += `,language=${language}`;
|
||||
params += ',write_cache_file=1';
|
||||
@@ -851,7 +849,7 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
||||
};
|
||||
|
||||
const synthElevenlabs = async(logger, {
|
||||
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
const {api_key, model_id, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
@@ -860,7 +858,7 @@ const synthElevenlabs = async(logger, {
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=elevenlabs';
|
||||
params += `,voice=${voice}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
@@ -915,7 +913,7 @@ const synthElevenlabs = async(logger, {
|
||||
};
|
||||
|
||||
const synthPlayHT = async(client, logger, {
|
||||
credentials, options, stats, voice, language, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, voice, language, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
const {api_key, user_id, voice_engine, playht_tts_uri, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
@@ -951,7 +949,7 @@ const synthPlayHT = async(client, logger, {
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,user_id=${user_id}`;
|
||||
params += ',vendor=playht';
|
||||
params += `,voice=${voice}`;
|
||||
@@ -1010,7 +1008,7 @@ const synthPlayHT = async(client, logger, {
|
||||
};
|
||||
|
||||
const synthInworld = async(logger, {
|
||||
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
const {api_key, model_id, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
@@ -1019,7 +1017,7 @@ const synthInworld = async(logger, {
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=inworld';
|
||||
params += `,voice=${voice}`;
|
||||
@@ -1075,7 +1073,7 @@ const synthInworld = async(logger, {
|
||||
};
|
||||
|
||||
const synthRimelabs = async(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
const {api_key, model_id, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
@@ -1084,7 +1082,7 @@ const synthRimelabs = async(logger, {
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=rimelabs';
|
||||
params += `,language=${language}`;
|
||||
@@ -1132,7 +1130,9 @@ const synthRimelabs = async(logger, {
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
const synthVerbio = async(client, logger, {credentials, stats, voice, text, renderForCaching, disableTtsStreaming}) => {
|
||||
const synthVerbio = async(client, logger, {
|
||||
credentials, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
//https://doc.speechcenter.verbio.com/#tag/Text-To-Speech-REST-API
|
||||
if (text.length > 2000) {
|
||||
throw new Error('Verbio cannot synthesize for the text length larger than 2000 characters');
|
||||
@@ -1141,7 +1141,7 @@ const synthVerbio = async(client, logger, {credentials, stats, voice, text, rend
|
||||
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `access_token=${token.access_token}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=verbio';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
@@ -1178,14 +1178,14 @@ const synthVerbio = async(client, logger, {credentials, stats, voice, text, rend
|
||||
}
|
||||
};
|
||||
|
||||
const synthWhisper = async(logger, {credentials, stats, voice, text, instructions,
|
||||
const synthWhisper = async(logger, {credentials, stats, voice, key, text, instructions,
|
||||
renderForCaching, disableTtsStreaming}) => {
|
||||
const {api_key, model_id, baseURL, timeout, speed} = credentials;
|
||||
/* if the env is set to stream then bag out, unless we are specifically rendering to generate a cache file */
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=whisper';
|
||||
params += `,voice=${voice}`;
|
||||
@@ -1227,12 +1227,12 @@ const synthWhisper = async(logger, {credentials, stats, voice, text, instruction
|
||||
}
|
||||
};
|
||||
|
||||
const synthDeepgram = async(logger, {credentials, stats, model, text, renderForCaching, disableTtsStreaming}) => {
|
||||
const synthDeepgram = async(logger, {credentials, stats, model, key, text, renderForCaching, disableTtsStreaming}) => {
|
||||
const {api_key, deepgram_tts_uri} = credentials;
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=deepgram';
|
||||
params += `,voice=${model}`;
|
||||
params += ',write_cache_file=1';
|
||||
@@ -1268,7 +1268,7 @@ const synthDeepgram = async(logger, {credentials, stats, model, text, renderForC
|
||||
};
|
||||
|
||||
const synthCartesia = async(logger, {
|
||||
credentials, options, stats, voice, language, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, voice, language, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
const {api_key, model_id, embedding, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
@@ -1276,7 +1276,7 @@ const synthCartesia = async(logger, {
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=cartesia';
|
||||
params += `,voice=${voice}`;
|
||||
@@ -1339,7 +1339,7 @@ const synthCartesia = async(logger, {
|
||||
};
|
||||
|
||||
const synthResemble = async(logger, {
|
||||
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming
|
||||
}) => {
|
||||
const {api_key, resemble_tts_uri, resemble_tts_use_tls} = credentials;
|
||||
const {project_uuid, use_hd} = options || {};
|
||||
@@ -1348,7 +1348,7 @@ const synthResemble = async(logger, {
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${playbackIdCounter++}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=resemble';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
|
||||
Reference in New Issue
Block a user