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 |
+91
-59
@@ -53,9 +53,6 @@ const EXPIRES = JAMBONES_TTS_CACHE_DURATION_MINS;
|
|||||||
const OpenAI = require('openai');
|
const OpenAI = require('openai');
|
||||||
const getAwsAuthToken = require('./get-aws-sts-token');
|
const getAwsAuthToken = require('./get-aws-sts-token');
|
||||||
|
|
||||||
/* counter for playback id */
|
|
||||||
let playbackIdCounter = 0;
|
|
||||||
|
|
||||||
const trimTrailingSilence = (buffer) => {
|
const trimTrailingSilence = (buffer) => {
|
||||||
assert.ok(buffer instanceof Buffer, 'trimTrailingSilence - argument is not a Buffer');
|
assert.ok(buffer instanceof Buffer, 'trimTrailingSilence - argument is not a Buffer');
|
||||||
|
|
||||||
@@ -207,74 +204,81 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
|||||||
const startAt = process.hrtime();
|
const startAt = process.hrtime();
|
||||||
switch (vendor) {
|
switch (vendor) {
|
||||||
case 'google':
|
case 'google':
|
||||||
audioData = await synthGoogle(logger, {credentials, stats, language, voice, gender, text});
|
audioData = await synthGoogle(logger, {credentials, stats, language, voice, gender, key, text});
|
||||||
break;
|
break;
|
||||||
case 'aws':
|
case 'aws':
|
||||||
case 'polly':
|
case 'polly':
|
||||||
vendorLabel = 'aws';
|
vendorLabel = 'aws';
|
||||||
audioData = await synthPolly(createHash, retrieveHash, logger,
|
audioData = await synthPolly(createHash, retrieveHash, logger,
|
||||||
{credentials, stats, language, voice, text, engine, renderForCaching, disableTtsStreaming});
|
{credentials, stats, language, voice, key, text, engine, renderForCaching, disableTtsStreaming,
|
||||||
|
disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'azure':
|
case 'azure':
|
||||||
case 'microsoft':
|
case 'microsoft':
|
||||||
vendorLabel = '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});
|
renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'nuance':
|
case 'nuance':
|
||||||
model = model || 'enhanced';
|
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;
|
break;
|
||||||
case 'nvidia':
|
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});
|
renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'ibm':
|
case 'ibm':
|
||||||
audioData = await synthIbm(logger, {credentials, stats, voice, text});
|
audioData = await synthIbm(logger, {credentials, stats, voice, key, text});
|
||||||
break;
|
break;
|
||||||
case 'wellsaid':
|
case 'wellsaid':
|
||||||
audioData = await synthWellSaid(logger, {credentials, stats, language, voice, text});
|
audioData = await synthWellSaid(logger, {credentials, stats, language, voice, key, text});
|
||||||
break;
|
break;
|
||||||
case 'elevenlabs':
|
case 'elevenlabs':
|
||||||
audioData = await synthElevenlabs(logger, {
|
audioData = await synthElevenlabs(logger, {
|
||||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||||
|
disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'playht':
|
case 'playht':
|
||||||
audioData = await synthPlayHT(client, logger, {
|
audioData = await synthPlayHT(client, logger, {
|
||||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||||
|
disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'cartesia':
|
case 'cartesia':
|
||||||
audioData = await synthCartesia(logger, {
|
audioData = await synthCartesia(logger, {
|
||||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||||
|
disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'inworld':
|
case 'inworld':
|
||||||
audioData = await synthInworld(logger, {
|
audioData = await synthInworld(logger, {
|
||||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||||
|
disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'rimelabs':
|
case 'rimelabs':
|
||||||
audioData = await synthRimelabs(logger, {
|
audioData = await synthRimelabs(logger, {
|
||||||
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming});
|
credentials, options, stats, language, voice, key, text, renderForCaching, disableTtsStreaming,
|
||||||
|
disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'whisper':
|
case 'whisper':
|
||||||
audioData = await synthWhisper(logger, {
|
audioData = await synthWhisper(logger, {
|
||||||
credentials, stats, voice, text, instructions, renderForCaching, disableTtsStreaming});
|
credentials, stats, voice, key, text, instructions, renderForCaching, disableTtsStreaming,
|
||||||
|
disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'verbio':
|
case 'verbio':
|
||||||
audioData = await synthVerbio(client, logger, {
|
audioData = await synthVerbio(client, logger, {
|
||||||
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
credentials, stats, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||||
if (audioData?.filePath) return audioData;
|
if (audioData?.filePath) return audioData;
|
||||||
break;
|
break;
|
||||||
case 'deepgram':
|
case 'deepgram':
|
||||||
audioData = await synthDeepgram(logger, {credentials, stats, model, text,
|
audioData = await synthDeepgram(logger, {credentials, stats, model, key, text,
|
||||||
renderForCaching, disableTtsStreaming});
|
renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case 'resemble':
|
case 'resemble':
|
||||||
audioData = await synthResemble(logger, {
|
audioData = await synthResemble(logger, {
|
||||||
credentials, stats, voice, text, options, renderForCaching, disableTtsStreaming});
|
credentials, stats, voice, key, text, options, renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||||
break;
|
break;
|
||||||
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
||||||
audioData = await synthCustomVendor(logger,
|
audioData = await synthCustomVendor(logger,
|
||||||
{credentials, stats, language, voice, text});
|
{credentials, stats, language, voice, key, text, renderForCaching, disableTtsStreaming, disableTtsCache});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assert(`synthAudio: unsupported speech vendor ${vendor}`);
|
assert(`synthAudio: unsupported speech vendor ${vendor}`);
|
||||||
@@ -309,13 +313,14 @@ async function synthAudio(client, createHash, retrieveHash, logger, stats, { acc
|
|||||||
}
|
}
|
||||||
|
|
||||||
const synthPolly = async(createHash, retrieveHash, logger,
|
const synthPolly = async(createHash, retrieveHash, logger,
|
||||||
{credentials, stats, language, voice, engine, text, renderForCaching, disableTtsStreaming}) => {
|
{credentials, stats, language, voice, engine, key, text, renderForCaching, disableTtsStreaming, disableTtsCache}) => {
|
||||||
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
|
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `language=${language}`;
|
params += `language=${language}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,playback_id=${key}`;
|
||||||
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
params += ',vendor=aws';
|
params += ',vendor=aws';
|
||||||
if (accessKeyId && secretAccessKey) {
|
if (accessKeyId && secretAccessKey) {
|
||||||
if (accessKeyId) params += `,accessKeyId=${accessKeyId}`;
|
if (accessKeyId) params += `,accessKeyId=${accessKeyId}`;
|
||||||
@@ -562,9 +567,11 @@ const synthMicrosoft = async(logger, {
|
|||||||
stats,
|
stats,
|
||||||
language,
|
language,
|
||||||
voice,
|
voice,
|
||||||
|
key,
|
||||||
text,
|
text,
|
||||||
renderForCaching,
|
renderForCaching,
|
||||||
disableTtsStreaming
|
disableTtsStreaming,
|
||||||
|
disableTtsCache
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint, custom_tts_endpoint_url} = credentials;
|
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint, custom_tts_endpoint_url} = credentials;
|
||||||
@@ -593,10 +600,11 @@ const synthMicrosoft = async(logger, {
|
|||||||
!renderForCaching && !disableTtsStreaming) {
|
!renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${apiKey}`;
|
params += `api_key=${apiKey}`;
|
||||||
|
params += `,playback_id=${key}`;
|
||||||
params += `,language=${language}`;
|
params += `,language=${language}`;
|
||||||
params += ',vendor=microsoft';
|
params += ',vendor=microsoft';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
if (region) params += `,region=${region}`;
|
if (region) params += `,region=${region}`;
|
||||||
if (custom_tts_endpoint) params += `,endpointId=${custom_tts_endpoint}`;
|
if (custom_tts_endpoint) params += `,endpointId=${custom_tts_endpoint}`;
|
||||||
if (custom_tts_endpoint_url) params += `,endpoint=${custom_tts_endpoint_url}`;
|
if (custom_tts_endpoint_url) params += `,endpoint=${custom_tts_endpoint_url}`;
|
||||||
@@ -769,15 +777,16 @@ const synthNuance = async(client, logger, {credentials, stats, voice, model, tex
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthNvidia = async(client, logger, {
|
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;
|
const {riva_server_uri} = credentials;
|
||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '';
|
let params = '';
|
||||||
params += `{riva_server_uri=${riva_server_uri}`;
|
params += `{riva_server_uri=${riva_server_uri}`;
|
||||||
|
params += `,playback_id=${key}`;
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += `,language=${language}`;
|
params += `,language=${language}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
params += '}';
|
params += '}';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -817,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;
|
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 {
|
try {
|
||||||
const post = bent('POST', {
|
const post = bent('POST', {
|
||||||
'Authorization': `Bearer ${auth_token}`,
|
'Authorization': `Bearer ${auth_token}`,
|
||||||
@@ -848,7 +875,7 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthElevenlabs = async(logger, {
|
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 {api_key, model_id, options: credOpts} = credentials;
|
||||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||||
@@ -857,12 +884,14 @@ const synthElevenlabs = async(logger, {
|
|||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += ',vendor=elevenlabs';
|
params += ',vendor=elevenlabs';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += `,model_id=${model_id}`;
|
params += `,model_id=${model_id}`;
|
||||||
params += `,optimize_streaming_latency=${opts.optimize_streaming_latency || 2}`;
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
params += ',write_cache_file=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?.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?.stability) params += `,stability=${opts.voice_settings.stability}`;
|
||||||
if (opts.voice_settings?.style) params += `,style=${opts.voice_settings.style}`;
|
if (opts.voice_settings?.style) params += `,style=${opts.voice_settings.style}`;
|
||||||
@@ -912,7 +941,7 @@ const synthElevenlabs = async(logger, {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthPlayHT = async(client, 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 {api_key, user_id, voice_engine, playht_tts_uri, options: credOpts} = credentials;
|
||||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||||
@@ -948,13 +977,13 @@ const synthPlayHT = async(client, logger, {
|
|||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += `,user_id=${user_id}`;
|
params += `,user_id=${user_id}`;
|
||||||
params += ',vendor=playht';
|
params += ',vendor=playht';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += `,voice_engine=${voice_engine}`;
|
params += `,voice_engine=${voice_engine}`;
|
||||||
params += `,synthesize_url=${synthesizeUrl}`;
|
params += `,synthesize_url=${synthesizeUrl}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
params += `,language=${language}`;
|
params += `,language=${language}`;
|
||||||
if (opts.quality) params += `,quality=${opts.quality}`;
|
if (opts.quality) params += `,quality=${opts.quality}`;
|
||||||
if (opts.speed) params += `,speed=${opts.speed}`;
|
if (opts.speed) params += `,speed=${opts.speed}`;
|
||||||
@@ -1007,7 +1036,7 @@ const synthPlayHT = async(client, logger, {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthInworld = async(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 {api_key, model_id, options: credOpts} = credentials;
|
||||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||||
@@ -1016,11 +1045,11 @@ const synthInworld = async(logger, {
|
|||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += `,model_id=${model_id}`;
|
params += `,model_id=${model_id}`;
|
||||||
params += ',vendor=inworld';
|
params += ',vendor=inworld';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
if (opts.temperature) params += `,temperature=${opts.temperature}`;
|
if (opts.temperature) params += `,temperature=${opts.temperature}`;
|
||||||
if (opts.audioConfig?.pitch) params += `,pitch=${opts.pitch}`;
|
if (opts.audioConfig?.pitch) params += `,pitch=${opts.pitch}`;
|
||||||
if (opts.audioConfig?.speakingRate) params += `,speakingRate=${opts.speakingRate}`;
|
if (opts.audioConfig?.speakingRate) params += `,speakingRate=${opts.speakingRate}`;
|
||||||
@@ -1072,7 +1101,7 @@ const synthInworld = async(logger, {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthRimelabs = 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 {api_key, model_id, options: credOpts} = credentials;
|
||||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||||
@@ -1081,12 +1110,12 @@ const synthRimelabs = async(logger, {
|
|||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += `,model_id=${model_id}`;
|
params += `,model_id=${model_id}`;
|
||||||
params += ',vendor=rimelabs';
|
params += ',vendor=rimelabs';
|
||||||
params += `,language=${language}`;
|
params += `,language=${language}`;
|
||||||
params += `,voice=${voice}`;
|
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.speedAlpha) params += `,speed_alpha=${opts.speedAlpha}`;
|
||||||
if (opts.reduceLatency) params += `,reduce_latency=${opts.reduceLatency}`;
|
if (opts.reduceLatency) params += `,reduce_latency=${opts.reduceLatency}`;
|
||||||
// Arcana model parameters
|
// Arcana model parameters
|
||||||
@@ -1129,7 +1158,9 @@ const synthRimelabs = async(logger, {
|
|||||||
throw err;
|
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
|
//https://doc.speechcenter.verbio.com/#tag/Text-To-Speech-REST-API
|
||||||
if (text.length > 2000) {
|
if (text.length > 2000) {
|
||||||
throw new Error('Verbio cannot synthesize for the text length larger than 2000 characters');
|
throw new Error('Verbio cannot synthesize for the text length larger than 2000 characters');
|
||||||
@@ -1138,10 +1169,10 @@ const synthVerbio = async(client, logger, {credentials, stats, voice, text, rend
|
|||||||
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `access_token=${token.access_token}`;
|
params += `access_token=${token.access_token}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += ',vendor=verbio';
|
params += ',vendor=verbio';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
params += '}';
|
params += '}';
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -1175,18 +1206,18 @@ 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}) => {
|
renderForCaching, disableTtsStreaming, disableTtsCache}) => {
|
||||||
const {api_key, model_id, baseURL, timeout, speed} = credentials;
|
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 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) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += `,model_id=${model_id}`;
|
params += `,model_id=${model_id}`;
|
||||||
params += ',vendor=whisper';
|
params += ',vendor=whisper';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
if (speed) params += `,speed=${speed}`;
|
if (speed) params += `,speed=${speed}`;
|
||||||
// comma is used to separated parameters in freeswitch tts module
|
// comma is used to separated parameters in freeswitch tts module
|
||||||
if (instructions) params += `,instructions=${instructions.replace(/\n/g, ' ').replace(/,/g, ';')}`;
|
if (instructions) params += `,instructions=${instructions.replace(/\n/g, ' ').replace(/,/g, ';')}`;
|
||||||
@@ -1224,15 +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;
|
const {api_key, deepgram_tts_uri} = credentials;
|
||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += ',vendor=deepgram';
|
params += ',vendor=deepgram';
|
||||||
params += `,voice=${model}`;
|
params += `,voice=${model}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
if (deepgram_tts_uri) params += `,endpoint=${deepgram_tts_uri}`;
|
if (deepgram_tts_uri) params += `,endpoint=${deepgram_tts_uri}`;
|
||||||
params += '}';
|
params += '}';
|
||||||
|
|
||||||
@@ -1265,7 +1297,7 @@ const synthDeepgram = async(logger, {credentials, stats, model, text, renderForC
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthCartesia = async(logger, {
|
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 {api_key, model_id, embedding, options: credOpts} = credentials;
|
||||||
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
const opts = !!options && Object.keys(options).length !== 0 ? options : JSON.parse(credOpts || '{}');
|
||||||
@@ -1273,11 +1305,11 @@ const synthCartesia = async(logger, {
|
|||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += `,model_id=${model_id}`;
|
params += `,model_id=${model_id}`;
|
||||||
params += ',vendor=cartesia';
|
params += ',vendor=cartesia';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
params += `,language=${language}`;
|
params += `,language=${language}`;
|
||||||
params += `,voice_mode=${embedding ? 'embedding' : 'id'}`;
|
params += `,voice_mode=${embedding ? 'embedding' : 'id'}`;
|
||||||
if (embedding) params += `,embedding=${embedding}`;
|
if (embedding) params += `,embedding=${embedding}`;
|
||||||
@@ -1336,7 +1368,7 @@ const synthCartesia = async(logger, {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthResemble = 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 {api_key, resemble_tts_uri, resemble_tts_use_tls} = credentials;
|
||||||
const {project_uuid, use_hd} = options || {};
|
const {project_uuid, use_hd} = options || {};
|
||||||
@@ -1345,10 +1377,10 @@ const synthResemble = async(logger, {
|
|||||||
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
let params = '{';
|
let params = '{';
|
||||||
params += `api_key=${api_key}`;
|
params += `api_key=${api_key}`;
|
||||||
params += `,playback_id=${playbackIdCounter++}`;
|
params += `,playback_id=${key}`;
|
||||||
params += ',vendor=resemble';
|
params += ',vendor=resemble';
|
||||||
params += `,voice=${voice}`;
|
params += `,voice=${voice}`;
|
||||||
params += ',write_cache_file=1';
|
params += `,write_cache_file=${disableTtsCache ? 0 : 1}`;
|
||||||
if (project_uuid) params += `,project_uuid=${project_uuid}`;
|
if (project_uuid) params += `,project_uuid=${project_uuid}`;
|
||||||
if (use_hd) params += `,use_hd=${use_hd}`;
|
if (use_hd) params += `,use_hd=${use_hd}`;
|
||||||
if (resemble_tts_uri) params += `,endpoint=${resemble_tts_uri}`;
|
if (resemble_tts_uri) params += `,endpoint=${resemble_tts_uri}`;
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.2.20",
|
"version": "0.2.24",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.2.20",
|
"version": "0.2.24",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"23": "^0.0.0",
|
"23": "^0.0.0",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.2.20",
|
"version": "0.2.24",
|
||||||
"description": "TTS-related speech utilities for jambonz",
|
"description": "TTS-related speech utilities for jambonz",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": "Dave Horton",
|
"author": "Dave Horton",
|
||||||
|
|||||||
@@ -554,6 +554,7 @@ test('Custom Vendor speech synth tests', async(t) => {
|
|||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'English-US.Female-1',
|
voice: 'English-US.Female-1',
|
||||||
text: 'This is a test. This is only a test',
|
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.servedFromCache, `successfully synthesized custom vendor audio to ${opts.filePath}`);
|
||||||
t.ok(opts.filePath.endsWith('wav'), 'audio is cached as wav file');
|
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',
|
language: 'en-US',
|
||||||
voice: 'English-US.Female-1',
|
voice: 'English-US.Female-1',
|
||||||
text: 'This is a test. This is only a test',
|
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.servedFromCache, `successfully get custom vendor cached audio to ${opts.filePath}`);
|
||||||
t.ok(opts.filePath.endsWith('wav'), 'audio is cached as wav file');
|
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',
|
language: 'en-US',
|
||||||
voice: 'English-US.Female-1',
|
voice: 'English-US.Female-1',
|
||||||
text: '<speak>This is a test. This is only a test</speak>',
|
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}`);
|
t.ok(!opts.servedFromCache, `successfully synthesized Custom Vendor audio to ${opts.filePath}`);
|
||||||
obj = await getJSON(`http://127.0.0.1:3100/lastRequest/somethingnew2`);
|
obj = await getJSON(`http://127.0.0.1:3100/lastRequest/somethingnew2`);
|
||||||
|
|||||||
Reference in New Issue
Block a user