mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-05 01:22:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
da3aa5aadb | ||
|
|
2fe89f132c | ||
|
|
4bca840ba2 | ||
|
|
f858ccb781 | ||
|
|
436b15d648 | ||
|
|
c3b7ea4cd1 |
@@ -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
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+2
-2
@@ -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
@@ -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",
|
||||||
|
|||||||
Reference in New Issue
Block a user