mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-03 23:33:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d8195be9a | ||
|
|
eb4e1a773f | ||
|
|
6fecb8755d | ||
|
|
fdb56cbc77 | ||
|
|
5328a60de8 | ||
|
|
ea1ab301d5 | ||
|
|
0a4994c5a3 | ||
|
|
cb71460189 | ||
|
|
f08efa49b1 | ||
|
|
80eda37ef6 | ||
|
|
7768e58b19 | ||
|
|
6efc99ad83 | ||
|
|
127d01a8c1 | ||
|
|
1900b26d8b | ||
|
|
aa25a6f6d9 | ||
|
|
8dfe17b600 | ||
|
|
5463e9f56e | ||
|
|
2eb36af650 | ||
|
|
b186cbc4f2 | ||
|
|
b1b9c182a9 | ||
|
|
15c77626fc | ||
|
|
76126ec0b3 | ||
|
|
55431ee511 | ||
|
|
1c76f74b4a | ||
|
|
62ad8abb8e | ||
|
|
92734aaedb | ||
|
|
fe4ccfe7d7 |
+144
-68
@@ -53,7 +53,6 @@ const EXPIRES = JAMBONES_TTS_CACHE_DURATION_MINS;
|
||||
const OpenAI = require('openai');
|
||||
const getAwsAuthToken = require('./get-aws-sts-token');
|
||||
|
||||
|
||||
const trimTrailingSilence = (buffer) => {
|
||||
assert.ok(buffer instanceof Buffer, 'trimTrailingSilence - argument is not a Buffer');
|
||||
|
||||
@@ -205,74 +204,81 @@ 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});
|
||||
{credentials, stats, language, voice, key, text, engine, renderForCaching, disableTtsStreaming,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'azure':
|
||||
case 'microsoft':
|
||||
vendorLabel = 'microsoft';
|
||||
audioData = await synthMicrosoft(logger, {credentials, stats, language, voice, text, deploymentId,
|
||||
renderForCaching, disableTtsStreaming});
|
||||
audioData = await synthMicrosoft(logger, {credentials, stats, language, voice, key, text, deploymentId,
|
||||
renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||
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,
|
||||
renderForCaching, disableTtsStreaming});
|
||||
audioData = await synthNvidia(client, logger, {credentials, stats, language, voice, model, key, text,
|
||||
renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||
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,
|
||||
disableTtsCache});
|
||||
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,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'cartesia':
|
||||
audioData = await synthCartesia(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'inworld':
|
||||
audioData = await synthInworld(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'rimelabs':
|
||||
audioData = await synthRimelabs(logger, {
|
||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'whisper':
|
||||
audioData = await synthWhisper(logger, {
|
||||
credentials, stats, voice, text, instructions, renderForCaching, disableTtsStreaming});
|
||||
credentials, stats, voice, key, text, instructions, renderForCaching, disableTtsStreaming,
|
||||
disableTtsCache});
|
||||
break;
|
||||
case 'verbio':
|
||||
audioData = await synthVerbio(client, logger, {
|
||||
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
||||
credentials, stats, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||
if (audioData?.filePath) return audioData;
|
||||
break;
|
||||
case 'deepgram':
|
||||
audioData = await synthDeepgram(logger, {credentials, stats, model, text,
|
||||
renderForCaching, disableTtsStreaming});
|
||||
audioData = await synthDeepgram(logger, {credentials, stats, model, key, text,
|
||||
renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||
break;
|
||||
case 'resemble':
|
||||
audioData = await synthResemble(logger, {
|
||||
credentials, stats, voice, text, options, renderForCaching, disableTtsStreaming});
|
||||
credentials, stats, voice, key, text, options, renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||
break;
|
||||
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
||||
audioData = await synthCustomVendor(logger,
|
||||
{credentials, stats, language, voice, text});
|
||||
{credentials, stats, language, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||
break;
|
||||
default:
|
||||
assert(`synthAudio: unsupported speech vendor ${vendor}`);
|
||||
@@ -307,9 +313,43 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
||||
}
|
||||
|
||||
const synthPolly = async(createHash, retrieveHash, logger,
|
||||
{credentials, stats, language, voice, engine, text}) => {
|
||||
{credentials, stats, language, voice, engine, key, text, renderForCaching, disableTtsStreaming, disableTtsCache}) => {
|
||||
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
|
||||
let params = '{';
|
||||
params += `language=${language}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
params += ',vendor=aws';
|
||||
if (accessKeyId && secretAccessKey) {
|
||||
if (accessKeyId) params += `,accessKeyId=${accessKeyId}`;
|
||||
if (secretAccessKey) params += `,secretAccessKey=${secretAccessKey}`;
|
||||
} else if (roleArn) {
|
||||
const cred = await getAwsAuthToken(
|
||||
logger, createHash, retrieveHash,
|
||||
{
|
||||
region,
|
||||
roleArn
|
||||
});
|
||||
|
||||
if (cred) {
|
||||
params += `,accessKeyId=${cred.accessKeyId}`;
|
||||
params += `,secretAccessKey=${cred.secretAccessKey}`;
|
||||
params += `,sessionToken=${cred.sessionToken}`;
|
||||
}
|
||||
}
|
||||
if (region) params += `,region=${region}`;
|
||||
if (engine) params += `,engine=${engine}`;
|
||||
params += '}';
|
||||
|
||||
return {
|
||||
filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`,
|
||||
servedFromCache: false,
|
||||
rtt: 0
|
||||
};
|
||||
}
|
||||
try {
|
||||
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
||||
let polly;
|
||||
if (accessKeyId && secretAccessKey) {
|
||||
polly = new PollyClient({
|
||||
@@ -527,9 +567,11 @@ const synthMicrosoft = async(logger, {
|
||||
stats,
|
||||
language,
|
||||
voice,
|
||||
key,
|
||||
text,
|
||||
renderForCaching,
|
||||
disableTtsStreaming
|
||||
disableTtsStreaming,
|
||||
disableTtsCache
|
||||
}) => {
|
||||
try {
|
||||
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint, custom_tts_endpoint_url} = credentials;
|
||||
@@ -556,12 +598,13 @@ const synthMicrosoft = async(logger, {
|
||||
}
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !JAMBONES_DISABLE_AZURE_TTS_STREAMING &&
|
||||
!renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${apiKey}`;
|
||||
let params = '{';
|
||||
params += `api_key=${apiKey}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,language=${language}`;
|
||||
params += ',vendor=microsoft';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
if (region) params += `,region=${region}`;
|
||||
if (custom_tts_endpoint) params += `,endpointId=${custom_tts_endpoint}`;
|
||||
if (custom_tts_endpoint_url) params += `,endpoint=${custom_tts_endpoint_url}`;
|
||||
@@ -734,15 +777,16 @@ 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, disableTtsCache
|
||||
}) => {
|
||||
const {riva_server_uri} = credentials;
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{riva_server_uri=${riva_server_uri}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,voice=${voice}`;
|
||||
params += `,language=${language}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
params += '}';
|
||||
|
||||
return {
|
||||
@@ -782,9 +826,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, disableTtsCache}) => {
|
||||
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=${disableTtsCache ? 0 : 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}`,
|
||||
@@ -813,20 +875,23 @@ 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, disableTtsCache
|
||||
}) => {
|
||||
const {api_key, model_id, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
|
||||
/* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=elevenlabs';
|
||||
params += `,voice=${voice}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += `,optimize_streaming_latency=${opts.optimize_streaming_latency || 2}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
if (opts.optimize_streaming_latency !== null && opts.optimize_streaming_latency !== undefined) {
|
||||
params += `,optimize_streaming_latency=${opts.optimize_streaming_latency}`;
|
||||
}
|
||||
if (opts.voice_settings?.similarity_boost) params += `,similarity_boost=${opts.voice_settings.similarity_boost}`;
|
||||
if (opts.voice_settings?.stability) params += `,stability=${opts.voice_settings.stability}`;
|
||||
if (opts.voice_settings?.style) params += `,style=${opts.voice_settings.style}`;
|
||||
@@ -876,7 +941,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, disableTtsCache
|
||||
}) => {
|
||||
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 || '{}');
|
||||
@@ -910,14 +975,15 @@ const synthPlayHT = async(client, logger, {
|
||||
|
||||
/* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,user_id=${user_id}`;
|
||||
params += ',vendor=playht';
|
||||
params += `,voice=${voice}`;
|
||||
params += `,voice_engine=${voice_engine}`;
|
||||
params += `,synthesize_url=${synthesizeUrl}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
params += `,language=${language}`;
|
||||
if (opts.quality) params += `,quality=${opts.quality}`;
|
||||
if (opts.speed) params += `,speed=${opts.speed}`;
|
||||
@@ -970,19 +1036,20 @@ const synthPlayHT = async(client, logger, {
|
||||
};
|
||||
|
||||
const synthInworld = async(logger, {
|
||||
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache
|
||||
}) => {
|
||||
const {api_key, model_id, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
|
||||
/* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=inworld';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
if (opts.temperature) params += `,temperature=${opts.temperature}`;
|
||||
if (opts.audioConfig?.pitch) params += `,pitch=${opts.pitch}`;
|
||||
if (opts.audioConfig?.speakingRate) params += `,speakingRate=${opts.speakingRate}`;
|
||||
@@ -1034,20 +1101,21 @@ 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, disableTtsCache
|
||||
}) => {
|
||||
const {api_key, model_id, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
|
||||
/* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=rimelabs';
|
||||
params += `,language=${language}`;
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
if (opts.speedAlpha) params += `,speed_alpha=${opts.speedAlpha}`;
|
||||
if (opts.reduceLatency) params += `,reduce_latency=${opts.reduceLatency}`;
|
||||
// Arcana model parameters
|
||||
@@ -1090,18 +1158,21 @@ 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, disableTtsCache
|
||||
}) => {
|
||||
//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');
|
||||
}
|
||||
const token = await getVerbioAccessToken(client, logger, credentials);
|
||||
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{access_token=${token.access_token}`;
|
||||
let params = '{';
|
||||
params += `access_token=${token.access_token}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=verbio';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
params += '}';
|
||||
|
||||
return {
|
||||
@@ -1135,17 +1206,18 @@ const synthVerbio = async(client, logger, {credentials, stats, voice, text, rend
|
||||
}
|
||||
};
|
||||
|
||||
const synthWhisper = async(logger, {credentials, stats, voice, text, instructions,
|
||||
renderForCaching, disableTtsStreaming}) => {
|
||||
const synthWhisper = async(logger, {credentials, stats, voice, key, text, instructions,
|
||||
renderForCaching, disableTtsStreaming, disableTtsCache}) => {
|
||||
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}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=whisper';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
if (speed) params += `,speed=${speed}`;
|
||||
// comma is used to separated parameters in freeswitch tts module
|
||||
if (instructions) params += `,instructions=${instructions.replace(/\n/g, ' ').replace(/,/g, ';')}`;
|
||||
@@ -1183,14 +1255,16 @@ 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, disableTtsCache}) => {
|
||||
const {api_key, deepgram_tts_uri} = credentials;
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=deepgram';
|
||||
params += `,voice=${model}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
if (deepgram_tts_uri) params += `,endpoint=${deepgram_tts_uri}`;
|
||||
params += '}';
|
||||
|
||||
@@ -1223,18 +1297,19 @@ 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, disableTtsCache
|
||||
}) => {
|
||||
const {api_key, model_id, embedding, options: credOpts} = credentials;
|
||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += `,model_id=${model_id}`;
|
||||
params += ',vendor=cartesia';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
params += `,language=${language}`;
|
||||
params += `,voice_mode=${embedding ? 'embedding' : 'id'}`;
|
||||
if (embedding) params += `,embedding=${embedding}`;
|
||||
@@ -1293,18 +1368,19 @@ const synthCartesia = async(logger, {
|
||||
};
|
||||
|
||||
const synthResemble = async(logger, {
|
||||
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||
credentials, options, stats, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache
|
||||
}) => {
|
||||
const {api_key, resemble_tts_uri, resemble_tts_use_tls} = credentials;
|
||||
const {project_uuid, use_hd} = options || {};
|
||||
|
||||
/* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
|
||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||
let params = '';
|
||||
params += `{api_key=${api_key}`;
|
||||
let params = '{';
|
||||
params += `api_key=${api_key}`;
|
||||
params += `,playback_id=${key}`;
|
||||
params += ',vendor=resemble';
|
||||
params += `,voice=${voice}`;
|
||||
params += ',write_cache_file=1';
|
||||
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||
if (project_uuid) params += `,project_uuid=${project_uuid}`;
|
||||
if (use_hd) params += `,use_hd=${use_hd}`;
|
||||
if (resemble_tts_uri) params += `,endpoint=${resemble_tts_uri}`;
|
||||
|
||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "@jambonz/speech-utils",
|
||||
"version": "0.2.17",
|
||||
"version": "0.2.24",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@jambonz/speech-utils",
|
||||
"version": "0.2.17",
|
||||
"version": "0.2.24",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"23": "^0.0.0",
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@jambonz/speech-utils",
|
||||
"version": "0.2.17",
|
||||
"version": "0.2.24",
|
||||
"description": "TTS-related speech utilities for jambonz",
|
||||
"main": "index.js",
|
||||
"author": "Dave Horton",
|
||||
|
||||
@@ -185,6 +185,7 @@ test('AWS speech synth tests', async(t) => {
|
||||
language: 'en-US',
|
||||
voice: 'Joey',
|
||||
text: 'This is a test. This is only a test',
|
||||
renderForCaching: true,
|
||||
});
|
||||
t.ok(!opts.servedFromCache, `successfully synthesized aws audio to ${opts.filePath}`);
|
||||
|
||||
@@ -198,6 +199,7 @@ test('AWS speech synth tests', async(t) => {
|
||||
language: 'en-US',
|
||||
voice: 'Joey',
|
||||
text: 'This is a test. This is only a test',
|
||||
renderForCaching: true,
|
||||
});
|
||||
t.ok(opts.servedFromCache, `successfully retrieved aws audio from cache ${opts.filePath}`);
|
||||
} catch (err) {
|
||||
@@ -552,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');
|
||||
@@ -573,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');
|
||||
@@ -587,6 +591,7 @@ test('Custom Vendor speech synth tests', async(t) => {
|
||||
language: 'en-US',
|
||||
voice: 'English-US.Female-1',
|
||||
text: '<speak>This is a test. This is only a test</speak>',
|
||||
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`);
|
||||
|
||||
Reference in New Issue
Block a user