Compare commits

...
6 Commits
4 changed files with 16 additions and 11 deletions
+6 -5
View File
@@ -4,10 +4,11 @@ const EXPIRES = (process.env.JAMBONES_TTS_CACHE_DURATION_MINS || 4 * 60) * 60; /
async function addFileToCache(client, logger, path, async function addFileToCache(client, logger, path,
{account_sid, vendor, language, voice, deploymentId, engine, text}) { {account_sid, vendor, language, voice, deploymentId, engine, text}) {
let key;
logger = logger || noopLogger; logger = logger || noopLogger;
try { try {
const key = makeSynthKey({ key = makeSynthKey({
account_sid, account_sid,
vendor, vendor,
language: language || '', language: language || '',
@@ -15,15 +16,15 @@ async function addFileToCache(client, logger, path,
engine, engine,
text, text,
}); });
const audioBuffer = fs.readFile(path); const audioBuffer = await fs.readFile(path);
await client.setex(key, EXPIRES, audioBuffer.toString('base64')); await client.setex(key, EXPIRES, audioBuffer.toString('base64'));
} catch (err) { } catch (err) {
logger.error(err, 'addFileToCache: Error'); logger.error(err, 'addFileToCache: Error');
return false; return;
} }
logger.debug(`addFileToCache: added ${path} to cache`); logger.debug(`addFileToCache: added ${path} to cache with key ${key}`);
return true; return key;
} }
module.exports = addFileToCache; module.exports = addFileToCache;
+7 -3
View File
@@ -143,6 +143,10 @@ async function synthAudio(client, logger, stats, { account_sid,
( (
process.env.JAMBONES_TTS_TRIM_SILENCE && process.env.JAMBONES_TTS_TRIM_SILENCE &&
['microsoft', 'azure'].includes(vendor) ['microsoft', 'azure'].includes(vendor)
) ||
(
process.env.JAMBONES_ELEVENLABS_STREAMING &&
vendor === 'elevenlabs'
) )
) { ) {
filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`; filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`;
@@ -607,8 +611,8 @@ const synthElevenlabs = async(logger, {credentials, options, stats, language, vo
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 || '{}');
/* if the env is set to stream then bag out, unless we are specifically rendering to generate a cache file */ /* default to using the streaming interface, unless disabled by env var OR we want just a cache file */
if (process.env.JAMBONES_ELEVENLABS_STREAMING && !renderForCaching) { if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching) {
let params = ''; let params = '';
params += `{api_key=${api_key}`; params += `{api_key=${api_key}`;
params += `,model_id=${model_id}`; params += `,model_id=${model_id}`;
@@ -621,7 +625,7 @@ const synthElevenlabs = async(logger, {credentials, options, stats, language, vo
params += '}'; params += '}';
return { return {
filePath: `say:${params}${text.replace(/\n/g, ' ')}`, filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`,
servedFromCache: false, servedFromCache: false,
rtt: 0 rtt: 0
}; };
+2 -2
View File
@@ -1,12 +1,12 @@
{ {
"name": "@jambonz/speech-utils", "name": "@jambonz/speech-utils",
"version": "0.0.37", "version": "0.0.40",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@jambonz/speech-utils", "name": "@jambonz/speech-utils",
"version": "0.0.37", "version": "0.0.40",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@aws-sdk/client-polly": "^3.496.0", "@aws-sdk/client-polly": "^3.496.0",
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@jambonz/speech-utils", "name": "@jambonz/speech-utils",
"version": "0.0.37", "version": "0.0.40",
"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",