mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-04 17:14:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
90152b36ef | ||
|
|
92484b7441 | ||
|
|
398904785b | ||
|
|
531fa21f88 | ||
|
|
904495d819 | ||
|
|
f13fc84853 | ||
|
|
e099bbb58f | ||
|
|
e60a2d2ba3 | ||
|
|
39d54050cc | ||
|
|
7618d334db | ||
|
|
71f20178d3 | ||
|
|
cb6ab2479f | ||
|
|
2212be341b | ||
|
|
5d2d921f31 | ||
|
|
acb2d0c7ce | ||
|
|
90d6048f52 | ||
|
|
e5985620c0 | ||
|
|
eb57f4d290 | ||
|
|
f0a1ab139c | ||
|
|
79289a7249 | ||
|
|
5998eebdca | ||
|
|
e6a7017b55 | ||
|
|
c8571af129 | ||
|
|
6144a9c164 | ||
|
|
68a7f2b0d4 | ||
|
|
0d1cd37097 | ||
|
|
3de8e5ff57 | ||
|
|
b4aad7991b | ||
|
|
8a5c5c1966 | ||
|
|
08a56d1a40 | ||
|
|
ba61f20334 | ||
|
|
10316d786e | ||
|
|
38cdc106cc | ||
|
|
410b99ef24 | ||
|
|
51db63f992 | ||
|
|
c86dceadde | ||
|
|
f56f98f40f | ||
|
|
12a36593aa | ||
|
|
8382491477 | ||
|
|
545d559e27 | ||
|
|
cc8963802f | ||
|
|
282d87f922 | ||
|
|
6a288c1db0 | ||
|
|
8650328e64 | ||
|
|
85fa6da5b5 | ||
|
|
e54e913fdd | ||
|
|
b088c0d7d9 | ||
|
|
f154a40692 | ||
|
|
0471b94ebe | ||
|
|
8279891dff | ||
|
|
f546ca998d | ||
|
|
bf229d0ab0 | ||
|
|
f08fedb8ca | ||
|
|
f3cc38089c | ||
|
|
fbed59e5de | ||
|
|
4f1685a365 | ||
|
|
2701af102a | ||
|
|
7f939b96d2 | ||
|
|
4d58ca6daf | ||
|
|
16dd7a2805 | ||
|
|
8f3e930004 | ||
|
|
3f4c444d82 | ||
|
|
fd7d8b8bcd | ||
|
|
46f833c7fa | ||
|
|
4eabfbe4b7 | ||
|
|
f3ab2baa6a | ||
|
|
fb412e2ddf | ||
|
|
f06f96a6f0 | ||
|
|
2988e800b1 | ||
|
|
dbfabeaddf | ||
|
|
c3188e40bb | ||
|
|
d0dfd07204 | ||
|
|
04a2466f54 | ||
|
|
0f9a9edc4d | ||
|
|
31a54f595b | ||
|
|
3560a6d4d9 | ||
|
|
be8053db4f | ||
|
|
4ffae38a3f | ||
|
|
9e74760c39 | ||
|
|
ced1a0ef0d | ||
|
|
1609d0b205 | ||
|
|
ef8ada2793 | ||
|
|
444ad2522f | ||
|
|
1caea60803 | ||
|
|
97c3588cfd | ||
|
|
da3aa5aadb | ||
|
|
2fe89f132c | ||
|
|
4bca840ba2 | ||
|
|
f858ccb781 | ||
|
|
3cf9894b44 | ||
|
|
436b15d648 | ||
|
|
c3b7ea4cd1 | ||
|
|
4b5430d61d | ||
|
|
9fc8fe8341 | ||
|
|
b31e40b8a5 | ||
|
|
62e1c69f69 | ||
|
|
bc68b672ac | ||
|
|
da1e279128 | ||
|
|
60bcfe07d7 | ||
|
|
d343c81088 | ||
|
|
706f6d5808 | ||
|
|
1b1a0f19d0 | ||
|
|
119ac50f7f | ||
|
|
cb479f04d5 | ||
|
|
7e21e0b666 | ||
|
|
dabdb5b584 | ||
|
|
f36ba027d0 | ||
|
|
08aae32975 | ||
|
|
4cfc730d92 | ||
|
|
4ef8538bcd | ||
|
|
16a746398f | ||
|
|
4a75f353ee | ||
|
|
bbff7963fd | ||
|
|
7b1d226403 | ||
|
|
95c29ce105 | ||
|
|
a46ae01d9c | ||
|
|
562dd0ac79 | ||
|
|
a0612bd1f9 | ||
|
|
2dcbf2b0f1 | ||
|
|
048b7e871e | ||
|
|
4cae96eacb | ||
|
|
1e57d00b55 | ||
|
|
4ead5ee417 | ||
|
|
a517f37473 | ||
|
|
3ac5a98e3a | ||
|
|
689fab6857 | ||
|
|
be3c484527 | ||
|
|
9827f7405d | ||
|
|
906a6b52b8 | ||
|
|
1f0b9ff539 | ||
|
|
b6f8368357 | ||
|
|
6bc487b3d1 | ||
|
|
9699abe0a3 | ||
|
|
5e1e7b17c6 | ||
|
|
1f52cd4f08 | ||
|
|
7df4e2f4c7 | ||
|
|
e99f7c5087 | ||
|
|
c7d981c23a | ||
|
|
95c54b9b12 | ||
|
|
48192aeba1 | ||
|
|
8f931cd8a5 | ||
|
|
144baafe94 | ||
|
|
ed3e513419 | ||
|
|
8d93fdc42a | ||
|
|
ea523a7a1d | ||
|
|
750ed97312 | ||
|
|
73baa81177 | ||
|
|
f86234a769 | ||
|
|
d564f24e6c | ||
|
|
464d8462d9 | ||
|
|
6853f0e342 | ||
|
|
507045dcba | ||
|
|
08758bbbff | ||
|
|
a3aa1169b8 | ||
|
|
7cae19a4e5 | ||
|
|
8c4d5a7cee | ||
|
|
eb2c39072b | ||
|
|
e5932ffc18 | ||
|
|
0a98c6a376 | ||
|
|
ea153e9833 | ||
|
|
b5daeff047 | ||
|
|
da02926c9a | ||
|
|
da3cdbb7aa | ||
|
|
625f147137 | ||
|
|
2e5687978e | ||
|
|
897481d34c | ||
|
|
bd5282e681 | ||
|
|
95a1384f02 | ||
|
|
35deeecf70 | ||
|
|
9d2ac3273f | ||
|
|
b1049aad7f | ||
|
|
40f51e7509 | ||
|
|
a0e2fe167c | ||
|
|
1fa853faa3 | ||
|
|
95e8d942b8 | ||
|
|
7a91876cd7 | ||
|
|
d07344ba3b | ||
|
|
44d8af2a96 | ||
|
|
b530db9a62 | ||
|
|
4c166c8eb4 | ||
|
|
8246dbea21 | ||
|
|
0084f6a468 | ||
|
|
98f679f43a | ||
|
|
7e7841b5ff | ||
|
|
75ce537db1 | ||
|
|
830be783b8 | ||
|
|
38c3219425 | ||
|
|
e37b96a9c2 | ||
|
|
c184fbae26 | ||
|
|
66d33ebd60 | ||
|
|
98e1bf62f9 | ||
|
|
63edbc2883 | ||
|
|
fb75de6af5 | ||
|
|
617f7af4af | ||
|
|
6c5c8e734f | ||
|
|
4349cd7e40 | ||
|
|
b6058ca242 | ||
|
|
68cbd63bbd | ||
|
|
521560e276 | ||
|
|
d606141f57 | ||
|
|
0d58954537 | ||
|
|
7c0eafded3 | ||
|
|
ab7d145288 | ||
|
|
11746d3f22 | ||
|
|
3fcfbd10a1 | ||
|
|
df8acbed0e | ||
|
|
4296ed7256 | ||
|
|
f4b271c7b3 | ||
|
|
d5c71de27d |
@@ -8,12 +8,15 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: lts/*
|
node-version: lts/*
|
||||||
- run: npm install
|
- run: npm install
|
||||||
- run: npm run jslint
|
- run: npm run jslint
|
||||||
|
- run: sudo apt update && sudo apt install -y squid
|
||||||
|
- run: sudo cp test/squid.conf /etc/squid/squid.conf
|
||||||
|
- run: sudo systemctl start squid
|
||||||
- run: npm test
|
- run: npm test
|
||||||
env:
|
env:
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||||
@@ -24,4 +27,12 @@ jobs:
|
|||||||
IBM_TTS_API_KEY: ${{ secrets.IBM_TTS_API_KEY }}
|
IBM_TTS_API_KEY: ${{ secrets.IBM_TTS_API_KEY }}
|
||||||
IBM_TTS_REGION: ${{ secrets.IBM_TTS_REGION }}
|
IBM_TTS_REGION: ${{ secrets.IBM_TTS_REGION }}
|
||||||
MICROSOFT_API_KEY: ${{ secrets.MICROSOFT_API_KEY }}
|
MICROSOFT_API_KEY: ${{ secrets.MICROSOFT_API_KEY }}
|
||||||
MICROSOFT_REGION: ${{ secrets.MICROSOFT_REGION }}
|
MICROSOFT_REGION: ${{ secrets.MICROSOFT_REGION }}
|
||||||
|
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||||
|
ELEVENLABS_API_KEY: ${{ secrets.ELEVENLABS_API_KEY }}
|
||||||
|
ELEVENLABS_VOICE_ID: ${{ secrets.ELEVENLABS_VOICE_ID }}
|
||||||
|
ELEVENLABS_MODEL_ID: ${{ secrets.ELEVENLABS_MODEL_ID }}
|
||||||
|
PLAYHT_USER_ID: ${{ secrets.PLAYHT_USER_ID }}
|
||||||
|
PLAYHT_API_KEY: ${{ secrets.PLAYHT_API_KEY }}
|
||||||
|
JAMBONES_HTTP_PROXY_IP: 127.0.0.1
|
||||||
|
JAMBONES_HTTP_PROXY_PORT: 3128
|
||||||
|
|||||||
@@ -39,3 +39,5 @@ node_modules
|
|||||||
examples/*
|
examples/*
|
||||||
|
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
.env
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
# speech-utils
|
# speech-utils 
|
||||||
TTS-related speech utilities for jambonz
|
TTS-related speech utilities for jambonz.
|
||||||
|
|
||||||
|
|||||||
+3
-1
@@ -8,6 +8,8 @@
|
|||||||
},
|
},
|
||||||
"redis-auth": {
|
"redis-auth": {
|
||||||
"host": "127.0.0.1",
|
"host": "127.0.0.1",
|
||||||
"port": 3380
|
"port": 3380,
|
||||||
|
"username": "daveh",
|
||||||
|
"password": "foobarbazzle"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,23 @@
|
|||||||
const {noopLogger} = require('./lib/utils');
|
const {noopLogger} = require('./lib/utils');
|
||||||
const promisify = require('@jambonz/promisify-redis');
|
|
||||||
const redis = promisify(require('redis'));
|
|
||||||
|
|
||||||
module.exports = (opts, logger) => {
|
module.exports = (opts, logger) => {
|
||||||
const {host = '127.0.0.1', port = 6379, tls = false} = opts;
|
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
|
const {
|
||||||
const url = process.env.JAMBONES_REDIS_USERNAME && process.env.JAMBONES_REDIS_PASSWORD ?
|
client,
|
||||||
`${process.env.JAMBONES_REDIS_USERNAME}:${process.env.JAMBONES_REDIS_PASSWORD}@${host}:${port}` :
|
createHash,
|
||||||
`${host}:${port}`;
|
retrieveHash
|
||||||
const client = redis.createClient(tls ? `rediss://${url}` : `redis://${url}`);
|
} = require('@jambonz/realtimedb-helpers')(opts, logger);
|
||||||
['ready', 'connect', 'reconnecting', 'error', 'end', 'warning']
|
|
||||||
.forEach((event) => {
|
|
||||||
client.on(event, (...args) => {
|
|
||||||
if ('error' === event) {
|
|
||||||
if (process.env.NODE_ENV === 'test' && args[0]?.code === 'ECONNREFUSED') return;
|
|
||||||
logger.error({...args}, '@jambonz/realtimedb-helpers - redis error');
|
|
||||||
}
|
|
||||||
else logger.debug({args}, `redis event ${event}`);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
client,
|
client,
|
||||||
|
getTtsSize: require('./lib/get-tts-size').bind(null, client, logger),
|
||||||
purgeTtsCache: require('./lib/purge-tts-cache').bind(null, client, logger),
|
purgeTtsCache: require('./lib/purge-tts-cache').bind(null, client, logger),
|
||||||
synthAudio: require('./lib/synth-audio').bind(null, client, logger),
|
addFileToCache: require('./lib/add-file-to-cache').bind(null, client, logger),
|
||||||
|
synthAudio: require('./lib/synth-audio').bind(null, client, createHash, retrieveHash, logger),
|
||||||
|
getVerbioAccessToken: require('./lib/get-verbio-token').bind(null, client, logger),
|
||||||
getNuanceAccessToken: require('./lib/get-nuance-access-token').bind(null, client, logger),
|
getNuanceAccessToken: require('./lib/get-nuance-access-token').bind(null, client, logger),
|
||||||
getIbmAccessToken: require('./lib/get-ibm-access-token').bind(null, client, logger),
|
getIbmAccessToken: require('./lib/get-ibm-access-token').bind(null, client, logger),
|
||||||
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, logger),
|
getAwsAuthToken: require('./lib/get-aws-sts-token').bind(null, logger, createHash, retrieveHash),
|
||||||
|
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, createHash, retrieveHash, logger),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
const fs = require('fs/promises');
|
||||||
|
const {noopLogger, makeSynthKey} = require('./utils');
|
||||||
|
const {JAMBONES_TTS_CACHE_DURATION_MINS} = require('./config');
|
||||||
|
const EXPIRES = JAMBONES_TTS_CACHE_DURATION_MINS;
|
||||||
|
|
||||||
|
async function addFileToCache(client, logger, path,
|
||||||
|
{account_sid, vendor, language, voice, deploymentId, engine, text}) {
|
||||||
|
let key;
|
||||||
|
logger = logger || noopLogger;
|
||||||
|
|
||||||
|
try {
|
||||||
|
key = makeSynthKey({
|
||||||
|
account_sid,
|
||||||
|
vendor,
|
||||||
|
language: language || '',
|
||||||
|
voice: voice || deploymentId,
|
||||||
|
engine,
|
||||||
|
text,
|
||||||
|
});
|
||||||
|
const audioBuffer = await fs.readFile(path);
|
||||||
|
await client.setex(key, EXPIRES, audioBuffer.toString('base64'));
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err, 'addFileToCache: Error');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug(`addFileToCache: added ${path} to cache with key ${key}`);
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = addFileToCache;
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
const JAMBONES_TTS_TRIM_SILENCE = process.env.JAMBONES_TTS_TRIM_SILENCE;
|
||||||
|
const JAMBONES_DISABLE_TTS_STREAMING = process.env.JAMBONES_DISABLE_TTS_STREAMING;
|
||||||
|
|
||||||
|
const JAMBONES_HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP;
|
||||||
|
const JAMBONES_HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT;
|
||||||
|
const JAMBONES_TTS_CACHE_DURATION_MINS =
|
||||||
|
(parseInt(process.env.JAMBONES_TTS_CACHE_DURATION_MINS) || 4 * 60) * 60; // cache tts for 4 hours
|
||||||
|
|
||||||
|
const TMP_FOLDER = '/tmp';
|
||||||
|
|
||||||
|
const HTTP_TIMEOUT = 5000;
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
JAMBONES_TTS_TRIM_SILENCE,
|
||||||
|
JAMBONES_DISABLE_TTS_STREAMING,
|
||||||
|
JAMBONES_HTTP_PROXY_IP,
|
||||||
|
JAMBONES_HTTP_PROXY_PORT,
|
||||||
|
JAMBONES_TTS_CACHE_DURATION_MINS,
|
||||||
|
TMP_FOLDER,
|
||||||
|
HTTP_TIMEOUT
|
||||||
|
};
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
const { STSClient, GetSessionTokenCommand, AssumeRoleCommand } = require('@aws-sdk/client-sts');
|
||||||
|
const {makeAwsKey, noopLogger} = require('./utils');
|
||||||
|
const debug = require('debug')('jambonz:speech-utils');
|
||||||
|
const EXPIRY = 3600;
|
||||||
|
|
||||||
|
async function getAwsAuthToken(
|
||||||
|
logger, createHash, retrieveHash,
|
||||||
|
awsAccessKeyId, awsSecretAccessKey, awsRegion, roleArn = null) {
|
||||||
|
logger = logger || noopLogger;
|
||||||
|
try {
|
||||||
|
const key = makeAwsKey(roleArn || awsAccessKeyId);
|
||||||
|
const obj = await retrieveHash(key);
|
||||||
|
if (obj) return {...obj, servedFromCache: true};
|
||||||
|
|
||||||
|
let data;
|
||||||
|
if (roleArn) {
|
||||||
|
const stsClient = new STSClient({ region: awsRegion});
|
||||||
|
const roleToAssume = { RoleArn: roleArn, RoleSessionName: 'Jambonz_Speech', DurationSeconds: EXPIRY};
|
||||||
|
const command = new AssumeRoleCommand(roleToAssume);
|
||||||
|
|
||||||
|
data = await stsClient.send(command);
|
||||||
|
} else {
|
||||||
|
/* access token not found in cache, so generate it using STS */
|
||||||
|
const stsClient = new STSClient({
|
||||||
|
region: awsRegion,
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: awsAccessKeyId,
|
||||||
|
secretAccessKey: awsSecretAccessKey,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
|
||||||
|
data = await stsClient.send(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
const credentials = {
|
||||||
|
accessKeyId: data.Credentials.AccessKeyId,
|
||||||
|
secretAccessKey: data.Credentials.SecretAccessKey,
|
||||||
|
sessionToken: data.Credentials.SessionToken,
|
||||||
|
securityToken: data.Credentials.SessionToken
|
||||||
|
};
|
||||||
|
|
||||||
|
/* expire 10 minutes before the hour, so we don't lose the use of it during a call */
|
||||||
|
createHash(key, credentials, EXPIRY - 600)
|
||||||
|
.catch((err) => logger.error(err, `Error saving hash for key ${key}`));
|
||||||
|
|
||||||
|
return {...credentials, servedFromCache: false};
|
||||||
|
} catch (err) {
|
||||||
|
debug(err, 'getAwsAuthToken: Error retrieving AWS auth token');
|
||||||
|
logger.error(err, 'getAwsAuthToken: Error retrieving AWS auth token');
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getAwsAuthToken;
|
||||||
@@ -2,14 +2,14 @@ const formurlencoded = require('form-urlencoded');
|
|||||||
const {Pool} = require('undici');
|
const {Pool} = require('undici');
|
||||||
const pool = new Pool('https://iam.cloud.ibm.com');
|
const pool = new Pool('https://iam.cloud.ibm.com');
|
||||||
const {makeIbmKey, noopLogger} = require('./utils');
|
const {makeIbmKey, noopLogger} = require('./utils');
|
||||||
|
const { HTTP_TIMEOUT } = require('./config');
|
||||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||||
const HTTP_TIMEOUT = 5000;
|
|
||||||
|
|
||||||
async function getIbmAccessToken(client, logger, apiKey) {
|
async function getIbmAccessToken(client, logger, apiKey) {
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
try {
|
try {
|
||||||
const key = makeIbmKey(apiKey);
|
const key = makeIbmKey(apiKey);
|
||||||
const access_token = await client.getAsync(key);
|
const access_token = await client.get(key);
|
||||||
if (access_token) return {access_token, servedFromCache: true};
|
if (access_token) return {access_token, servedFromCache: true};
|
||||||
|
|
||||||
/* access token not found in cache, so fetch it from Ibm */
|
/* access token not found in cache, so fetch it from Ibm */
|
||||||
|
|||||||
@@ -2,14 +2,14 @@ const formurlencoded = require('form-urlencoded');
|
|||||||
const {Pool} = require('undici');
|
const {Pool} = require('undici');
|
||||||
const pool = new Pool('https://auth.crt.nuance.com');
|
const pool = new Pool('https://auth.crt.nuance.com');
|
||||||
const {makeNuanceKey, makeBasicAuthHeader, noopLogger} = require('./utils');
|
const {makeNuanceKey, makeBasicAuthHeader, noopLogger} = require('./utils');
|
||||||
|
const { HTTP_TIMEOUT } = require('./config');
|
||||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||||
const HTTP_TIMEOUT = 5000;
|
|
||||||
|
|
||||||
async function getNuanceAccessToken(client, logger, clientId, secret, scope) {
|
async function getNuanceAccessToken(client, logger, clientId, secret, scope) {
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
try {
|
try {
|
||||||
const key = makeNuanceKey(clientId, secret, scope);
|
const key = makeNuanceKey(clientId, secret, scope);
|
||||||
const access_token = await client.getAsync(key);
|
const access_token = await client.get(key);
|
||||||
if (access_token) return {access_token, servedFromCache: true};
|
if (access_token) return {access_token, servedFromCache: true};
|
||||||
|
|
||||||
/* access token not found in cache, so fetch it from Nuance */
|
/* access token not found in cache, so fetch it from Nuance */
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
async function getTtsSize(client, logger, pattern = null) {
|
||||||
|
let keys;
|
||||||
|
if (pattern) {
|
||||||
|
keys = await client.keys(pattern);
|
||||||
|
} else {
|
||||||
|
keys = await client.keys('tts:*');
|
||||||
|
}
|
||||||
|
return keys.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getTtsSize;
|
||||||
+50
-13
@@ -1,11 +1,16 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const {noopLogger, createNuanceClient, createKryptonClient} = require('./utils');
|
const {noopLogger, createNuanceClient, createKryptonClient} = require('./utils');
|
||||||
const getNuanceAccessToken = require('./get-nuance-access-token');
|
const getNuanceAccessToken = require('./get-nuance-access-token');
|
||||||
|
const getVerbioAccessToken = require('./get-verbio-token');
|
||||||
const {GetVoicesRequest, Voice} = require('../stubs/nuance/synthesizer_pb');
|
const {GetVoicesRequest, Voice} = require('../stubs/nuance/synthesizer_pb');
|
||||||
const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
|
const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
|
||||||
const { IamAuthenticator } = require('ibm-watson/auth');
|
const { IamAuthenticator } = require('ibm-watson/auth');
|
||||||
const ttsGoogle = require('@google-cloud/text-to-speech');
|
const ttsGoogle = require('@google-cloud/text-to-speech');
|
||||||
const { PollyClient, DescribeVoicesCommand } = require('@aws-sdk/client-polly');
|
const { PollyClient, DescribeVoicesCommand } = require('@aws-sdk/client-polly');
|
||||||
|
const getAwsAuthToken = require('./get-aws-sts-token');
|
||||||
|
const {Pool} = require('undici');
|
||||||
|
const { HTTP_TIMEOUT } = require('./config');
|
||||||
|
const verbioVoicePool = new Pool('https://us.rest.speechcenter.verbio.com');
|
||||||
|
|
||||||
const getIbmVoices = async(client, logger, credentials) => {
|
const getIbmVoices = async(client, logger, credentials) => {
|
||||||
const {tts_region, tts_api_key} = credentials;
|
const {tts_region, tts_api_key} = credentials;
|
||||||
@@ -87,17 +92,27 @@ const getGoogleVoices = async(_client, logger, credentials) => {
|
|||||||
return await client.listVoices();
|
return await client.listVoices();
|
||||||
};
|
};
|
||||||
|
|
||||||
const getAwsVoices = async(_client, logger, credentials) => {
|
const getAwsVoices = async(_client, createHash, retrieveHash, logger, credentials) => {
|
||||||
try {
|
try {
|
||||||
const {region, accessKeyId, secretAccessKey} = credentials;
|
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
||||||
const client = new PollyClient({
|
let client = null;
|
||||||
region,
|
if (accessKeyId && secretAccessKey) {
|
||||||
credentials: {
|
client = new PollyClient({
|
||||||
accessKeyId,
|
region,
|
||||||
secretAccessKey
|
credentials: {
|
||||||
}
|
accessKeyId,
|
||||||
});
|
secretAccessKey
|
||||||
const command = new DescribeVoicesCommand({LanguageCode: 'en-US'});
|
}
|
||||||
|
});
|
||||||
|
} else if (roleArn) {
|
||||||
|
client = new PollyClient({
|
||||||
|
region,
|
||||||
|
credentials: await getAwsAuthToken(logger, createHash, retrieveHash, null, null, region, roleArn),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
client = new PollyClient({region});
|
||||||
|
}
|
||||||
|
const command = new DescribeVoicesCommand({});
|
||||||
const response = await client.send(command);
|
const response = await client.send(command);
|
||||||
return response;
|
return response;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -106,6 +121,26 @@ const getAwsVoices = async(_client, logger, credentials) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getVerbioVoices = async(client, logger, credentials) => {
|
||||||
|
try {
|
||||||
|
const access_token = await getVerbioAccessToken(client, logger, credentials);
|
||||||
|
const { body} = await verbioVoicePool.request({
|
||||||
|
path: '/api/v1/voices',
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'Authorization': `Bearer ${access_token.access_token}`,
|
||||||
|
'User-Agent': 'jambonz'
|
||||||
|
},
|
||||||
|
timeout: HTTP_TIMEOUT,
|
||||||
|
followRedirects: false
|
||||||
|
});
|
||||||
|
return await body.json();
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'getVerbioVoices - failed to list voices for Verbio');
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synthesize speech to an mp3 file, and also cache the generated speech
|
* Synthesize speech to an mp3 file, and also cache the generated speech
|
||||||
* in redis (base64 format) for 24 hours so as to avoid unnecessarily paying
|
* in redis (base64 format) for 24 hours so as to avoid unnecessarily paying
|
||||||
@@ -122,10 +157,10 @@ const getAwsVoices = async(_client, logger, credentials) => {
|
|||||||
* @returns object containing filepath to an mp3 file in the /tmp folder containing
|
* @returns object containing filepath to an mp3 file in the /tmp folder containing
|
||||||
* the synthesized audio, and a variable indicating whether it was served from cache
|
* the synthesized audio, and a variable indicating whether it was served from cache
|
||||||
*/
|
*/
|
||||||
async function getTtsVoices(client, logger, {vendor, credentials}) {
|
async function getTtsVoices(client, createHash, retrieveHash, logger, {vendor, credentials}) {
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
|
|
||||||
assert.ok(['nuance', 'ibm', 'google', 'aws', 'polly'].includes(vendor),
|
assert.ok(['nuance', 'ibm', 'google', 'aws', 'polly', 'verbio'].includes(vendor),
|
||||||
`getTtsVoices not supported for vendor ${vendor}`);
|
`getTtsVoices not supported for vendor ${vendor}`);
|
||||||
|
|
||||||
switch (vendor) {
|
switch (vendor) {
|
||||||
@@ -137,7 +172,9 @@ async function getTtsVoices(client, logger, {vendor, credentials}) {
|
|||||||
return getGoogleVoices(client, logger, credentials);
|
return getGoogleVoices(client, logger, credentials);
|
||||||
case 'aws':
|
case 'aws':
|
||||||
case 'polly':
|
case 'polly':
|
||||||
return getAwsVoices(client, logger, credentials);
|
return getAwsVoices(client, createHash, retrieveHash, logger, credentials);
|
||||||
|
case 'verbio':
|
||||||
|
return getVerbioVoices(client, logger, credentials);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,51 @@
|
|||||||
|
const {Pool} = require('undici');
|
||||||
|
const { noopLogger, makeVerbioKey } = require('./utils');
|
||||||
|
const { HTTP_TIMEOUT } = require('./config');
|
||||||
|
const pool = new Pool('https://auth.speechcenter.verbio.com:444');
|
||||||
|
const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||||
|
|
||||||
|
async function getVerbioAccessToken(client, logger, credentials) {
|
||||||
|
logger = logger || noopLogger;
|
||||||
|
const { client_id, client_secret } = credentials;
|
||||||
|
try {
|
||||||
|
const key = makeVerbioKey(client_id);
|
||||||
|
const access_token = await client.get(key);
|
||||||
|
if (access_token) {
|
||||||
|
return {access_token, servedFromCache: true};
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
client_id,
|
||||||
|
client_secret
|
||||||
|
};
|
||||||
|
|
||||||
|
const {statusCode, headers, body} = await pool.request({
|
||||||
|
path: '/api/v1/token',
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
'User-Agent': 'jambonz'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(payload),
|
||||||
|
timeout: HTTP_TIMEOUT,
|
||||||
|
followRedirects: false
|
||||||
|
});
|
||||||
|
|
||||||
|
if (200 !== statusCode) {
|
||||||
|
logger.debug({statusCode, headers, body: await body.text()}, 'error fetching access token from Verbio');
|
||||||
|
const err = new Error();
|
||||||
|
err.statusCode = statusCode;
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
const json = await body.json();
|
||||||
|
const expiry = Math.floor(json.expiration_time - Date.now() / 1000 - 30);
|
||||||
|
await client.set(key, json.access_token, 'EX', expiry);
|
||||||
|
return {...json, servedFromCache: false};
|
||||||
|
} catch (err) {
|
||||||
|
debug(err, `getVerbioAccessToken: Error retrieving Verbio access token for client_id ${client_id}`);
|
||||||
|
logger.error(err, `getVerbioAccessToken: Error retrieving Verbio access token for client_id ${client_id}`);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = getVerbioAccessToken;
|
||||||
@@ -19,12 +19,12 @@ async function purgeTtsCache(client, logger, {all, account_sid, vendor,
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (all) {
|
if (all) {
|
||||||
const keys = await client.keysAsync('tts:*');
|
const keys = await client.keys('tts:*');
|
||||||
purgedCount = await client.delAsync(keys);
|
purgedCount = await client.del(keys);
|
||||||
|
|
||||||
} else if (account_sid && !vendor && !language && !voice && !engine && !text) {
|
} else if (account_sid && !vendor && !language && !voice && !engine && !text) {
|
||||||
const keys = await client.keysAsync(`tts:${account_sid}:*`);
|
const keys = await client.keys(`tts:${account_sid}:*`);
|
||||||
purgedCount = await client.delAsync(keys);
|
purgedCount = await client.del(keys);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const key = makeSynthKey({
|
const key = makeSynthKey({
|
||||||
@@ -35,7 +35,7 @@ async function purgeTtsCache(client, logger, {all, account_sid, vendor,
|
|||||||
engine,
|
engine,
|
||||||
text,
|
text,
|
||||||
});
|
});
|
||||||
purgedCount = await client.delAsync(key);
|
purgedCount = await client.del(key);
|
||||||
if (purgedCount === 0) error = 'Specified item not found';
|
if (purgedCount === 0) error = 'Specified item not found';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+506
-59
@@ -2,22 +2,28 @@ const assert = require('assert');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const bent = require('bent');
|
const bent = require('bent');
|
||||||
const ttsGoogle = require('@google-cloud/text-to-speech');
|
const ttsGoogle = require('@google-cloud/text-to-speech');
|
||||||
//const Polly = require('aws-sdk/clients/polly');
|
|
||||||
const { PollyClient, SynthesizeSpeechCommand } = require('@aws-sdk/client-polly');
|
const { PollyClient, SynthesizeSpeechCommand } = require('@aws-sdk/client-polly');
|
||||||
|
|
||||||
const sdk = require('microsoft-cognitiveservices-speech-sdk');
|
const sdk = require('microsoft-cognitiveservices-speech-sdk');
|
||||||
const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
|
const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
|
||||||
const { IamAuthenticator } = require('ibm-watson/auth');
|
const { IamAuthenticator } = require('ibm-watson/auth');
|
||||||
const {
|
const {
|
||||||
AudioConfig,
|
|
||||||
ResultReason,
|
ResultReason,
|
||||||
SpeechConfig,
|
SpeechConfig,
|
||||||
SpeechSynthesizer,
|
SpeechSynthesizer,
|
||||||
CancellationDetails,
|
CancellationDetails,
|
||||||
SpeechSynthesisOutputFormat
|
SpeechSynthesisOutputFormat
|
||||||
} = sdk;
|
} = sdk;
|
||||||
const {makeSynthKey, createNuanceClient, createKryptonClient, createRivaClient, noopLogger} = require('./utils');
|
const {
|
||||||
|
makeSynthKey,
|
||||||
|
createNuanceClient,
|
||||||
|
createKryptonClient,
|
||||||
|
createRivaClient,
|
||||||
|
noopLogger,
|
||||||
|
makeFilePath
|
||||||
|
} = require('./utils');
|
||||||
const getNuanceAccessToken = require('./get-nuance-access-token');
|
const getNuanceAccessToken = require('./get-nuance-access-token');
|
||||||
|
const getVerbioAccessToken = require('./get-verbio-token');
|
||||||
const {
|
const {
|
||||||
SynthesisRequest,
|
SynthesisRequest,
|
||||||
Voice,
|
Voice,
|
||||||
@@ -32,8 +38,33 @@ const {
|
|||||||
const {SynthesizeSpeechRequest} = require('../stubs/riva/proto/riva_tts_pb');
|
const {SynthesizeSpeechRequest} = require('../stubs/riva/proto/riva_tts_pb');
|
||||||
const {AudioEncoding} = require('../stubs/riva/proto/riva_audio_pb');
|
const {AudioEncoding} = require('../stubs/riva/proto/riva_audio_pb');
|
||||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||||
const EXPIRES = (process.env.JAMBONES_TTS_CACHE_DURATION_MINS || 24 * 60) * 60; // cache tts for 24 hours
|
const {
|
||||||
const TMP_FOLDER = '/tmp';
|
JAMBONES_DISABLE_TTS_STREAMING,
|
||||||
|
JAMBONES_HTTP_PROXY_IP,
|
||||||
|
JAMBONES_HTTP_PROXY_PORT,
|
||||||
|
JAMBONES_TTS_CACHE_DURATION_MINS,
|
||||||
|
} = require('./config');
|
||||||
|
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');
|
||||||
|
|
||||||
|
let offset = buffer.length;
|
||||||
|
while (offset > 0) {
|
||||||
|
// Get 16-bit value from the buffer (read in reverse)
|
||||||
|
const value = buffer.readUInt16BE(offset - 2);
|
||||||
|
if (value !== 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
offset -= 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim the silence from the end
|
||||||
|
return offset === buffer.length ? buffer : buffer.subarray(0, offset);
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Synthesize speech to an mp3 file, and also cache the generated speech
|
* Synthesize speech to an mp3 file, and also cache the generated speech
|
||||||
@@ -52,17 +83,19 @@ const TMP_FOLDER = '/tmp';
|
|||||||
* @returns object containing filepath to an mp3 file in the /tmp folder containing
|
* @returns object containing filepath to an mp3 file in the /tmp folder containing
|
||||||
* the synthesized audio, and a variable indicating whether it was served from cache
|
* the synthesized audio, and a variable indicating whether it was served from cache
|
||||||
*/
|
*/
|
||||||
async function synthAudio(client, logger, stats, { account_sid,
|
async function synthAudio(client, createHash, retrieveHash, logger, stats, { account_sid,
|
||||||
vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId, disableTtsCache
|
vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId,
|
||||||
|
disableTtsCache, renderForCaching, disableTtsStreaming, options
|
||||||
}) {
|
}) {
|
||||||
let audioBuffer;
|
let audioBuffer;
|
||||||
let servedFromCache = false;
|
let servedFromCache = false;
|
||||||
let rtt;
|
let rtt;
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
|
|
||||||
assert.ok(['google', 'aws', 'polly', 'microsoft', 'wellsaid', 'nuance', 'nvidia', 'ibm'].includes(vendor) ||
|
assert.ok(['google', 'aws', 'polly', 'microsoft', 'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs',
|
||||||
|
'whisper', 'deepgram', 'playht', 'rimelabs', 'verbio'].includes(vendor) ||
|
||||||
vendor.startsWith('custom'),
|
vendor.startsWith('custom'),
|
||||||
`synthAudio supported vendors are google, aws, microsoft, nuance, nvidia and wellsaid, not ${vendor}`);
|
`synthAudio supported vendors are google, aws, microsoft, nuance, nvidia and wellsaid ..etc, not ${vendor}`);
|
||||||
if ('google' === vendor) {
|
if ('google' === vendor) {
|
||||||
assert.ok(language, 'synthAudio requires language when google is used');
|
assert.ok(language, 'synthAudio requires language when google is used');
|
||||||
}
|
}
|
||||||
@@ -83,7 +116,7 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
else if ('nvidia' === vendor) {
|
else if ('nvidia' === vendor) {
|
||||||
assert.ok(voice, 'synthAudio requires voice when nvidia is used');
|
assert.ok(voice, 'synthAudio requires voice when nvidia is used');
|
||||||
assert.ok(language, 'synthAudio requires language when nvidia is used');
|
assert.ok(language, 'synthAudio requires language when nvidia is used');
|
||||||
assert.ok(credentials.riva_uri, 'synthAudio requires riva_uri in credentials when nuance is used');
|
assert.ok(credentials.riva_server_uri, 'synthAudio requires riva_server_uri in credentials when nvidia is used');
|
||||||
}
|
}
|
||||||
else if ('ibm' === vendor) {
|
else if ('ibm' === vendor) {
|
||||||
assert.ok(voice, 'synthAudio requires voice when ibm is used');
|
assert.ok(voice, 'synthAudio requires voice when ibm is used');
|
||||||
@@ -94,8 +127,29 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
language = 'en-US'; // WellSaid only supports English atm
|
language = 'en-US'; // WellSaid only supports English atm
|
||||||
assert.ok(voice, 'synthAudio requires voice when wellsaid is used');
|
assert.ok(voice, 'synthAudio requires voice when wellsaid is used');
|
||||||
assert.ok(!text.startsWith('<speak'), 'wellsaid does not support SSML tags');
|
assert.ok(!text.startsWith('<speak'), 'wellsaid does not support SSML tags');
|
||||||
|
} else if ('elevenlabs' === vendor) {
|
||||||
|
assert.ok(voice, 'synthAudio requires voice when elevenlabs is used');
|
||||||
|
assert.ok(credentials.api_key, 'synthAudio requires api_key when elevenlabs is used');
|
||||||
|
assert.ok(credentials.model_id, 'synthAudio requires model_id when elevenlabs is used');
|
||||||
|
} else if ('playht' === vendor) {
|
||||||
|
assert.ok(voice, 'synthAudio requires voice when playht is used');
|
||||||
|
assert.ok(credentials.api_key, 'synthAudio requires api_key when playht is used');
|
||||||
|
assert.ok(credentials.user_id, 'synthAudio requires user_id when playht is used');
|
||||||
|
assert.ok(credentials.voice_engine, 'synthAudio requires voice_engine when playht is used');
|
||||||
|
} else if ('rimelabs' === vendor) {
|
||||||
|
assert.ok(voice, 'synthAudio requires voice when rimelabs is used');
|
||||||
|
assert.ok(credentials.api_key, 'synthAudio requires api_key when rimelabs is used');
|
||||||
|
assert.ok(credentials.model_id, 'synthAudio requires model_id when rimelabs is used');
|
||||||
|
} else if ('whisper' === vendor) {
|
||||||
|
assert.ok(voice, 'synthAudio requires voice when whisper is used');
|
||||||
|
assert.ok(credentials.model_id, 'synthAudio requires model when whisper is used');
|
||||||
|
assert.ok(credentials.api_key, 'synthAudio requires api_key when whisper is used');
|
||||||
} else if (vendor.startsWith('custom')) {
|
} else if (vendor.startsWith('custom')) {
|
||||||
assert.ok(credentials.custom_tts_url, `synthAudio requires custom_tts_url in credentials when ${vendor} is used`);
|
assert.ok(credentials.custom_tts_url, `synthAudio requires custom_tts_url in credentials when ${vendor} is used`);
|
||||||
|
} else if ('verbio' === vendor) {
|
||||||
|
assert.ok(voice, 'synthAudio requires voice when verbio is used');
|
||||||
|
assert.ok(credentials.client_id, 'synthAudio requires client_id when verbio is used');
|
||||||
|
assert.ok(credentials.client_secret, 'synthAudio requires client_secret when verbio is used');
|
||||||
}
|
}
|
||||||
const key = makeSynthKey({
|
const key = makeSynthKey({
|
||||||
account_sid,
|
account_sid,
|
||||||
@@ -106,14 +160,11 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
text
|
text
|
||||||
});
|
});
|
||||||
let filePath;
|
let filePath;
|
||||||
if (['nuance', 'nvidia'].includes(vendor)) {
|
filePath = makeFilePath(vendor, key, salt);
|
||||||
filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`;
|
|
||||||
}
|
|
||||||
else filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.mp3`;
|
|
||||||
debug(`synth key is ${key}`);
|
debug(`synth key is ${key}`);
|
||||||
let cached;
|
let cached;
|
||||||
if (!disableTtsCache) {
|
if (!disableTtsCache) {
|
||||||
cached = await client.getAsync(key);
|
cached = await client.get(key);
|
||||||
}
|
}
|
||||||
if (cached) {
|
if (cached) {
|
||||||
// found in cache - extend the expiry and use it
|
// found in cache - extend the expiry and use it
|
||||||
@@ -121,7 +172,7 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
servedFromCache = true;
|
servedFromCache = true;
|
||||||
stats.increment('tts.cache.requests', ['found:yes']);
|
stats.increment('tts.cache.requests', ['found:yes']);
|
||||||
audioBuffer = Buffer.from(cached, 'base64');
|
audioBuffer = Buffer.from(cached, 'base64');
|
||||||
client.expireAsync(key, EXPIRES).catch((err) => logger.info(err, 'Error setting expires'));
|
client.expire(key, EXPIRES).catch((err) => logger.info(err, 'Error setting expires'));
|
||||||
}
|
}
|
||||||
if (!cached) {
|
if (!cached) {
|
||||||
// not found in cache - go get it from speech vendor and add to cache
|
// not found in cache - go get it from speech vendor and add to cache
|
||||||
@@ -136,12 +187,14 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
case 'aws':
|
case 'aws':
|
||||||
case 'polly':
|
case 'polly':
|
||||||
vendorLabel = 'aws';
|
vendorLabel = 'aws';
|
||||||
audioBuffer = await synthPolly(logger, {credentials, stats, language, voice, text, engine});
|
audioBuffer = await synthPolly(createHash, retrieveHash, logger,
|
||||||
|
{credentials, stats, language, voice, text, engine});
|
||||||
break;
|
break;
|
||||||
case 'azure':
|
case 'azure':
|
||||||
case 'microsoft':
|
case 'microsoft':
|
||||||
vendorLabel = 'microsoft';
|
vendorLabel = 'microsoft';
|
||||||
audioBuffer = await synthMicrosoft(logger, {credentials, stats, language, voice, text, deploymentId, filePath});
|
audioBuffer = await synthMicrosoft(logger, {credentials, stats, language, voice, text, deploymentId,
|
||||||
|
filePath, renderForCaching, disableTtsStreaming});
|
||||||
break;
|
break;
|
||||||
case 'nuance':
|
case 'nuance':
|
||||||
model = model || 'enhanced';
|
model = model || 'enhanced';
|
||||||
@@ -156,6 +209,34 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
case 'wellsaid':
|
case 'wellsaid':
|
||||||
audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
|
audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
|
||||||
break;
|
break;
|
||||||
|
case 'elevenlabs':
|
||||||
|
audioBuffer = await synthElevenlabs(logger, {
|
||||||
|
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming, filePath
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'playht':
|
||||||
|
audioBuffer = await synthPlayHT(logger, {
|
||||||
|
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming, filePath
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'rimelabs':
|
||||||
|
audioBuffer = await synthRimelabs(logger, {
|
||||||
|
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming, filePath
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
case 'whisper':
|
||||||
|
audioBuffer = await synthWhisper(logger, {
|
||||||
|
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
||||||
|
break;
|
||||||
|
case 'verbio':
|
||||||
|
audioBuffer = await synthVerbio(client, logger, {
|
||||||
|
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
||||||
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
|
break;
|
||||||
|
case 'deepgram':
|
||||||
|
audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text,
|
||||||
|
renderForCaching, disableTtsStreaming});
|
||||||
|
break;
|
||||||
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
||||||
({ audioBuffer, filePath } = await synthCustomVendor(logger,
|
({ audioBuffer, filePath } = await synthCustomVendor(logger,
|
||||||
{credentials, stats, language, voice, text, filePath}));
|
{credentials, stats, language, voice, text, filePath}));
|
||||||
@@ -163,6 +244,7 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
default:
|
default:
|
||||||
assert(`synthAudio: unsupported speech vendor ${vendor}`);
|
assert(`synthAudio: unsupported speech vendor ${vendor}`);
|
||||||
}
|
}
|
||||||
|
if ('filePath' in audioBuffer) return audioBuffer;
|
||||||
const diff = process.hrtime(startAt);
|
const diff = process.hrtime(startAt);
|
||||||
const time = diff[0] * 1e3 + diff[1] * 1e-6;
|
const time = diff[0] * 1e3 + diff[1] * 1e-6;
|
||||||
rtt = time.toFixed(0);
|
rtt = time.toFixed(0);
|
||||||
@@ -170,10 +252,8 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
debug(`tts rtt time for ${text.length} chars on ${vendorLabel}: ${rtt}`);
|
debug(`tts rtt time for ${text.length} chars on ${vendorLabel}: ${rtt}`);
|
||||||
logger.info(`tts rtt time for ${text.length} chars on ${vendorLabel}: ${rtt}`);
|
logger.info(`tts rtt time for ${text.length} chars on ${vendorLabel}: ${rtt}`);
|
||||||
|
|
||||||
client.setexAsync(key, EXPIRES, audioBuffer.toString('base64'))
|
client.setex(key, EXPIRES, audioBuffer.toString('base64'))
|
||||||
.catch((err) => logger.error(err, `error calling setex on key ${key}`));
|
.catch((err) => logger.error(err, `error calling setex on key ${key}`));
|
||||||
|
|
||||||
if (['microsoft'].includes(vendor)) return {filePath, servedFromCache, rtt};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
@@ -184,16 +264,28 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const synthPolly = async(logger, {credentials, stats, language, voice, engine, text}) => {
|
const synthPolly = async(createHash, retrieveHash, logger,
|
||||||
|
{credentials, stats, language, voice, engine, text}) => {
|
||||||
try {
|
try {
|
||||||
const {region, accessKeyId, secretAccessKey} = credentials;
|
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
||||||
const polly = new PollyClient({
|
let polly;
|
||||||
region,
|
if (accessKeyId && secretAccessKey) {
|
||||||
credentials: {
|
polly = new PollyClient({
|
||||||
accessKeyId,
|
region,
|
||||||
secretAccessKey
|
credentials: {
|
||||||
}
|
accessKeyId,
|
||||||
});
|
secretAccessKey
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (roleArn) {
|
||||||
|
polly = new PollyClient({
|
||||||
|
region,
|
||||||
|
credentials: await getAwsAuthToken(logger, createHash, retrieveHash, null, null, region, roleArn),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// AWS RoleArn assigned to Instance profile
|
||||||
|
polly = new PollyClient({region});
|
||||||
|
}
|
||||||
const opts = {
|
const opts = {
|
||||||
Engine: engine,
|
Engine: engine,
|
||||||
OutputFormat: 'mp3',
|
OutputFormat: 'mp3',
|
||||||
@@ -228,7 +320,8 @@ const synthGoogle = async(logger, {credentials, stats, language, voice, gender,
|
|||||||
const client = new ttsGoogle.TextToSpeechClient(credentials);
|
const client = new ttsGoogle.TextToSpeechClient(credentials);
|
||||||
const opts = {
|
const opts = {
|
||||||
voice: {
|
voice: {
|
||||||
name: voice,
|
...(typeof voice === 'string' && {name: voice}),
|
||||||
|
...(typeof voice === 'object' && {customVoice: voice}),
|
||||||
languageCode: language,
|
languageCode: language,
|
||||||
ssmlGender: gender || 'SSML_VOICE_GENDER_UNSPECIFIED'
|
ssmlGender: gender || 'SSML_VOICE_GENDER_UNSPECIFIED'
|
||||||
},
|
},
|
||||||
@@ -278,32 +371,70 @@ const synthIbm = async(logger, {credentials, stats, voice, text}) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const synthMicrosoft = async(logger, {
|
async function _synthOnPremMicrosoft(logger, {
|
||||||
credentials,
|
credentials,
|
||||||
stats,
|
stats,
|
||||||
language,
|
language,
|
||||||
voice,
|
voice,
|
||||||
text,
|
text,
|
||||||
filePath
|
filePath
|
||||||
|
}) {
|
||||||
|
const {use_custom_tts, custom_tts_endpoint_url, api_key} = credentials;
|
||||||
|
let content = text;
|
||||||
|
|
||||||
|
if (use_custom_tts && !content.startsWith('<speak')) {
|
||||||
|
/**
|
||||||
|
* Note: it seems that to use custom voice ssml is required with the voice attribute
|
||||||
|
* Otherwise sending plain text we get "Voice does not match"
|
||||||
|
*/
|
||||||
|
content = `<speak>${text}</speak>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content.startsWith('<speak>')) {
|
||||||
|
/* microsoft enforces some properties and uses voice xml element so if the user did not supply do it for them */
|
||||||
|
const words = content.slice(7, -8).trim().replace(/(\r\n|\n|\r)/gm, ' ');
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${language}"><voice name="${voice}">${words}</voice></speak>`;
|
||||||
|
logger.info({content}, 'synthMicrosoft');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const trimSilence = filePath.endsWith('.r8');
|
||||||
|
const post = bent('POST', 'buffer', {
|
||||||
|
'X-Microsoft-OutputFormat': trimSilence ? 'raw-8khz-16bit-mono-pcm' : 'audio-16khz-32kbitrate-mono-mp3',
|
||||||
|
'Content-Type': 'application/ssml+xml',
|
||||||
|
'User-Agent': 'Jambonz',
|
||||||
|
...(api_key && {'Ocp-Apim-Subscription-Key': api_key})
|
||||||
|
});
|
||||||
|
const mp3 = await post(custom_tts_endpoint_url, content);
|
||||||
|
return mp3;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, '_synthMicrosoftByHttp returned error');
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const synthMicrosoft = async(logger, {
|
||||||
|
credentials,
|
||||||
|
stats,
|
||||||
|
language,
|
||||||
|
voice,
|
||||||
|
text,
|
||||||
|
filePath,
|
||||||
|
renderForCaching,
|
||||||
|
disableTtsStreaming
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint} = credentials;
|
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint, custom_tts_endpoint_url} = credentials;
|
||||||
|
// let clean up the text
|
||||||
let content = text;
|
let content = text;
|
||||||
const speechConfig = SpeechConfig.fromSubscription(apiKey, region);
|
if (use_custom_tts && !content.startsWith('<speak')) {
|
||||||
speechConfig.speechSynthesisLanguage = language;
|
|
||||||
speechConfig.speechSynthesisVoiceName = voice;
|
|
||||||
if (use_custom_tts && custom_tts_endpoint) {
|
|
||||||
speechConfig.endpointId = custom_tts_endpoint;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note: it seems that to use custom voice ssml is required with the voice attribute
|
* Note: it seems that to use custom voice ssml is required with the voice attribute
|
||||||
* Otherwise sending plain text we get "Voice does not match"
|
* Otherwise sending plain text we get "Voice does not match"
|
||||||
*/
|
*/
|
||||||
if (!content.startsWith('<speak')) content = `<speak>${text}</speak>`;
|
content = `<speak>${text}</speak>`;
|
||||||
}
|
}
|
||||||
speechConfig.speechSynthesisOutputFormat = SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3;
|
|
||||||
const config = AudioConfig.fromAudioFileOutput(filePath);
|
|
||||||
const synthesizer = new SpeechSynthesizer(speechConfig, config);
|
|
||||||
|
|
||||||
if (content.startsWith('<speak>')) {
|
if (content.startsWith('<speak>')) {
|
||||||
/* microsoft enforces some properties and uses voice xml element so if the user did not supply do it for them */
|
/* microsoft enforces some properties and uses voice xml element so if the user did not supply do it for them */
|
||||||
@@ -312,6 +443,52 @@ const synthMicrosoft = async(logger, {
|
|||||||
content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${language}"><voice name="${voice}">${words}</voice></speak>`;
|
content = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="${language}"><voice name="${voice}">${words}</voice></speak>`;
|
||||||
logger.info({content}, 'synthMicrosoft');
|
logger.info({content}, 'synthMicrosoft');
|
||||||
}
|
}
|
||||||
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
|
let params = '';
|
||||||
|
params += `{api_key=${apiKey}`;
|
||||||
|
params += `,language=${language}`;
|
||||||
|
params += ',vendor=microsoft';
|
||||||
|
params += `,voice=${voice}`;
|
||||||
|
params += ',write_cache_file=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}`;
|
||||||
|
if (JAMBONES_HTTP_PROXY_IP) params += `,http_proxy_ip=${JAMBONES_HTTP_PROXY_IP}`;
|
||||||
|
if (JAMBONES_HTTP_PROXY_PORT) params += `,http_proxy_port=${JAMBONES_HTTP_PROXY_PORT}`;
|
||||||
|
params += '}';
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${content.replace(/\n/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (use_custom_tts && custom_tts_endpoint_url) {
|
||||||
|
return await _synthOnPremMicrosoft(logger, {
|
||||||
|
credentials,
|
||||||
|
stats,
|
||||||
|
language,
|
||||||
|
voice,
|
||||||
|
text,
|
||||||
|
filePath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const trimSilence = filePath.endsWith('.r8');
|
||||||
|
const speechConfig = SpeechConfig.fromSubscription(apiKey, region);
|
||||||
|
speechConfig.speechSynthesisLanguage = language;
|
||||||
|
speechConfig.speechSynthesisVoiceName = voice;
|
||||||
|
if (use_custom_tts && custom_tts_endpoint) {
|
||||||
|
speechConfig.endpointId = custom_tts_endpoint;
|
||||||
|
}
|
||||||
|
speechConfig.speechSynthesisOutputFormat = trimSilence ?
|
||||||
|
SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm :
|
||||||
|
SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3;
|
||||||
|
|
||||||
|
if (JAMBONES_HTTP_PROXY_IP && JAMBONES_HTTP_PROXY_PORT) {
|
||||||
|
logger.debug(
|
||||||
|
`synthMicrosoft: using proxy ${JAMBONES_HTTP_PROXY_IP}:${JAMBONES_HTTP_PROXY_PORT}`);
|
||||||
|
speechConfig.setProxy(JAMBONES_HTTP_PROXY_IP, JAMBONES_HTTP_PROXY_PORT);
|
||||||
|
}
|
||||||
|
const synthesizer = new SpeechSynthesizer(speechConfig);
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const speakAsync = content.startsWith('<speak') ?
|
const speakAsync = content.startsWith('<speak') ?
|
||||||
@@ -328,12 +505,11 @@ const synthMicrosoft = async(logger, {
|
|||||||
reject(cancellation.errorDetails);
|
reject(cancellation.errorDetails);
|
||||||
break;
|
break;
|
||||||
case ResultReason.SynthesizingAudioCompleted:
|
case ResultReason.SynthesizingAudioCompleted:
|
||||||
stats.increment('tts.count', ['vendor:microsoft', 'accepted:yes']);
|
let buffer = Buffer.from(result.audioData);
|
||||||
|
if (trimSilence) buffer = trimTrailingSilence(buffer);
|
||||||
|
resolve(buffer);
|
||||||
synthesizer.close();
|
synthesizer.close();
|
||||||
fs.readFile(filePath, (err, data) => {
|
stats.increment('tts.count', ['vendor:microsoft', 'accepted:yes']);
|
||||||
if (err) return reject(err);
|
|
||||||
resolve(data);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.info({result}, 'synthAudio: (Microsoft) unexpected result');
|
logger.info({result}, 'synthAudio: (Microsoft) unexpected result');
|
||||||
@@ -433,21 +609,25 @@ const synthNuance = async(client, logger, {credentials, stats, voice, model, tex
|
|||||||
};
|
};
|
||||||
|
|
||||||
const synthNvidia = async(client, logger, {credentials, stats, language, voice, model, text}) => {
|
const synthNvidia = async(client, logger, {credentials, stats, language, voice, model, text}) => {
|
||||||
const {riva_uri} = credentials;
|
const {riva_server_uri} = credentials;
|
||||||
const rivaClient = await createRivaClient(riva_uri);
|
let rivaClient, request;
|
||||||
|
try {
|
||||||
const request = new SynthesizeSpeechRequest();
|
rivaClient = await createRivaClient(riva_server_uri);
|
||||||
request.setVoiceName(voice);
|
request = new SynthesizeSpeechRequest();
|
||||||
request.setLanguageCode(language);
|
request.setVoiceName(voice);
|
||||||
request.setSampleRateHz(8000);
|
request.setLanguageCode(language);
|
||||||
request.setEncoding(AudioEncoding.LINEAR_PCM);
|
request.setSampleRateHz(8000);
|
||||||
request.setText(text);
|
request.setEncoding(AudioEncoding.LINEAR_PCM);
|
||||||
|
request.setText(text);
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'error creating riva client');
|
||||||
|
return Promise.reject(err);
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log(`language ${language} voice ${voice} model ${model} text ${text}`);
|
|
||||||
rivaClient.synthesize(request, (err, response) => {
|
rivaClient.synthesize(request, (err, response) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error(err);
|
logger.info({err, voice, language}, 'error synthesizing speech using Nvidia');
|
||||||
return reject(err);
|
return reject(err);
|
||||||
}
|
}
|
||||||
resolve(Buffer.from(response.getAudio()));
|
resolve(Buffer.from(response.getAudio()));
|
||||||
@@ -485,6 +665,273 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const synthElevenlabs = async(logger, {
|
||||||
|
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||||
|
}) => {
|
||||||
|
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}`;
|
||||||
|
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';
|
||||||
|
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}`;
|
||||||
|
if (opts.voice_settings?.use_speaker_boost === false) params += ',use_speaker_boost=false';
|
||||||
|
params += '}';
|
||||||
|
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const optimize_streaming_latency = opts.optimize_streaming_latency ?
|
||||||
|
`?optimize_streaming_latency=${opts.optimize_streaming_latency}` : '';
|
||||||
|
try {
|
||||||
|
const post = bent('https://api.elevenlabs.io', 'POST', 'buffer', {
|
||||||
|
'xi-api-key': api_key,
|
||||||
|
'Accept': 'audio/mpeg',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
const mp3 = await post(`/v1/text-to-speech/${voice}${optimize_streaming_latency}`, {
|
||||||
|
text,
|
||||||
|
model_id,
|
||||||
|
voice_settings: {
|
||||||
|
stability: 0.5,
|
||||||
|
similarity_boost: 0.5
|
||||||
|
},
|
||||||
|
...opts
|
||||||
|
});
|
||||||
|
return mp3;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'synth Elevenlabs returned error');
|
||||||
|
stats.increment('tts.count', ['vendor:elevenlabs', 'accepted:no']);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const synthPlayHT = async(logger, {
|
||||||
|
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||||
|
}) => {
|
||||||
|
const {api_key, user_id, voice_engine, 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}`;
|
||||||
|
params += `,user_id=${user_id}`;
|
||||||
|
params += ',vendor=playht';
|
||||||
|
params += `,voice=${voice}`;
|
||||||
|
params += `,voice_engine=${voice_engine}`;
|
||||||
|
params += ',write_cache_file=1';
|
||||||
|
if (opts.quality) params += `,quality=${opts.quality}`;
|
||||||
|
if (opts.speed) params += `,speed=${opts.speed}`;
|
||||||
|
if (opts.seed) params += `,style=${opts.seed}`;
|
||||||
|
if (opts.temperature) params += `,temperature=${opts.temperature}`;
|
||||||
|
if (opts.emotion) params += `,emotion=${opts.emotion}`;
|
||||||
|
if (opts.voice_guidance) params += `,voice_guidance=${opts.voice_guidance}`;
|
||||||
|
if (opts.style_guidance) params += `,style_guidance=${opts.style_guidance}`;
|
||||||
|
if (opts.text_guidance) params += `,text_guidance=${opts.text_guidance}`;
|
||||||
|
params += '}';
|
||||||
|
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const post = bent('https://api.play.ht', 'POST', 'buffer', {
|
||||||
|
'AUTHORIZATION': api_key,
|
||||||
|
'X-USER-ID': user_id,
|
||||||
|
'Accept': 'audio/mpeg',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
const mp3 = await post('/api/v2/tts/stream', {
|
||||||
|
text,
|
||||||
|
voice,
|
||||||
|
voice_engine,
|
||||||
|
output_format: 'mp3',
|
||||||
|
sample_rate: 8000,
|
||||||
|
...opts
|
||||||
|
});
|
||||||
|
return mp3;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'synth PlayHT returned error');
|
||||||
|
stats.increment('tts.count', ['vendor:playht', 'accepted:no']);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const synthRimelabs = async(logger, {
|
||||||
|
credentials, options, stats, voice, text, renderForCaching, disableTtsStreaming
|
||||||
|
}) => {
|
||||||
|
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}`;
|
||||||
|
params += `,model_id=${model_id}`;
|
||||||
|
params += ',vendor=rimelabs';
|
||||||
|
params += `,voice=${voice}`;
|
||||||
|
params += ',write_cache_file=1';
|
||||||
|
if (opts.speedAlpha) params += `,speed_alpha=${opts.speedAlpha}`;
|
||||||
|
if (opts.reduceLatency) params += `,reduce_latency=${opts.reduceLatency}`;
|
||||||
|
params += '}';
|
||||||
|
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${text.replace(/\n/g, ' ').replace(/\r/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const post = bent('https://users.rime.ai', 'POST', 'buffer', {
|
||||||
|
'Authorization': `Bearer ${api_key}`,
|
||||||
|
'Accept': 'audio/mp3',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
const mp3 = await post('/v1/rime-tts', {
|
||||||
|
speaker: voice,
|
||||||
|
text,
|
||||||
|
modelId: model_id,
|
||||||
|
samplingRate: 8000,
|
||||||
|
...opts
|
||||||
|
});
|
||||||
|
return mp3;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'synth rimelabs returned error');
|
||||||
|
stats.increment('tts.count', ['vendor:rimelabs', 'accepted:no']);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const synthVerbio = async(client, logger, {credentials, stats, voice, 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');
|
||||||
|
}
|
||||||
|
const token = await getVerbioAccessToken(client, logger, credentials);
|
||||||
|
if (!process.env.JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
|
let params = '';
|
||||||
|
params += `{access_token=${token.access_token}`;
|
||||||
|
params += ',vendor=verbio';
|
||||||
|
params += `,voice=${voice}`;
|
||||||
|
params += ',write_cache_file=1';
|
||||||
|
params += '}';
|
||||||
|
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${text.replace(/\n/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const post = bent('https://us.rest.speechcenter.verbio.com', 'POST', 'buffer', {
|
||||||
|
'Authorization': `Bearer ${token.access_token}`,
|
||||||
|
'User-Agent': 'jambonz',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
const r8 = await post('/api/v1/synthesize', {
|
||||||
|
voice_id: voice,
|
||||||
|
output_sample_rate: '8k',
|
||||||
|
output_encoding: 'pcm16',
|
||||||
|
text
|
||||||
|
});
|
||||||
|
return r8;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'synth Verbio returned error');
|
||||||
|
stats.increment('tts.count', ['vendor:verbio', 'accepted:no']);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const synthWhisper = async(logger, {credentials, stats, voice, text, 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 += `,model_id=${model_id}`;
|
||||||
|
params += ',vendor=whisper';
|
||||||
|
params += `,voice=${voice}`;
|
||||||
|
params += ',write_cache_file=1';
|
||||||
|
if (speed) params += `,speed=${speed}`;
|
||||||
|
params += '}';
|
||||||
|
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${text.replace(/\n/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const openai = new OpenAI.OpenAI({
|
||||||
|
apiKey: api_key,
|
||||||
|
timeout: timeout || 5000,
|
||||||
|
...(baseURL && {baseURL})
|
||||||
|
});
|
||||||
|
|
||||||
|
const mp3 = await openai.audio.speech.create({
|
||||||
|
model: model_id,
|
||||||
|
voice,
|
||||||
|
input: text,
|
||||||
|
response_format: 'mp3'
|
||||||
|
});
|
||||||
|
return Buffer.from(await mp3.arrayBuffer());
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'synth whisper returned error');
|
||||||
|
stats.increment('tts.count', ['vendor:openai', 'accepted:no']);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const synthDeepgram = async(logger, {credentials, stats, model, text, renderForCaching, disableTtsStreaming}) => {
|
||||||
|
const {api_key} = credentials;
|
||||||
|
if (!JAMBONES_DISABLE_TTS_STREAMING && !renderForCaching && !disableTtsStreaming) {
|
||||||
|
let params = '';
|
||||||
|
params += `{api_key=${api_key}`;
|
||||||
|
params += ',vendor=deepgram';
|
||||||
|
params += `,voice=${model}`;
|
||||||
|
params += ',write_cache_file=1';
|
||||||
|
params += '}';
|
||||||
|
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${text.replace(/\n/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const post = bent('https://api.deepgram.com', 'POST', 'buffer', {
|
||||||
|
'Authorization': `Token ${api_key}`,
|
||||||
|
'Accept': 'audio/mpeg',
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
});
|
||||||
|
const mp3 = await post(`/v1/speak?model=${model}`, {
|
||||||
|
text
|
||||||
|
});
|
||||||
|
return mp3;
|
||||||
|
} catch (err) {
|
||||||
|
logger.info({err}, 'synth Deepgram returned error');
|
||||||
|
stats.increment('tts.count', ['vendor:deepgram', 'accepted:no']);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const getFileExtFromMime = (mime) => {
|
const getFileExtFromMime = (mime) => {
|
||||||
switch (mime) {
|
switch (mime) {
|
||||||
case 'audio/wav':
|
case 'audio/wav':
|
||||||
|
|||||||
+55
-4
@@ -3,10 +3,10 @@ const {SynthesizerClient} = require('../stubs/nuance/synthesizer_grpc_pb');
|
|||||||
const {RivaSpeechSynthesisClient} = require('../stubs/riva/proto/riva_tts_grpc_pb');
|
const {RivaSpeechSynthesisClient} = require('../stubs/riva/proto/riva_tts_grpc_pb');
|
||||||
const {Pool} = require('undici');
|
const {Pool} = require('undici');
|
||||||
const pool = new Pool('https://auth.crt.nuance.com');
|
const pool = new Pool('https://auth.crt.nuance.com');
|
||||||
const HTTP_TIMEOUT = 5000;
|
|
||||||
const NUANCE_AUTH_ENDPOINT = 'tts.api.nuance.com:443';
|
const NUANCE_AUTH_ENDPOINT = 'tts.api.nuance.com:443';
|
||||||
const grpc = require('@grpc/grpc-js');
|
const grpc = require('@grpc/grpc-js');
|
||||||
const formurlencoded = require('form-urlencoded');
|
const formurlencoded = require('form-urlencoded');
|
||||||
|
const { JAMBONES_DISABLE_TTS_STREAMING, JAMBONES_TTS_TRIM_SILENCE, TMP_FOLDER, HTTP_TIMEOUT } = require('./config');
|
||||||
|
|
||||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||||
/**
|
/**
|
||||||
@@ -19,7 +19,44 @@ const debug = require('debug')('jambonz:realtimedb-helpers');
|
|||||||
function makeSynthKey({account_sid = '', vendor, language, voice, engine = '', text}) {
|
function makeSynthKey({account_sid = '', vendor, language, voice, engine = '', text}) {
|
||||||
const hash = crypto.createHash('sha1');
|
const hash = crypto.createHash('sha1');
|
||||||
hash.update(`${language}:${vendor}:${voice}:${engine}:${text}`);
|
hash.update(`${language}:${vendor}:${voice}:${engine}:${text}`);
|
||||||
return `tts${account_sid ? (':' + account_sid) : ''}:${hash.digest('hex')}`;
|
const hexHashKey = hash.digest('hex');
|
||||||
|
const accountKey = account_sid ? `:${account_sid}` : '';
|
||||||
|
const namespace = vendor.startsWith('custom') ? vendor : getFileExtension(vendor);
|
||||||
|
const key = `tts${accountKey}:${namespace}:${hexHashKey}`;
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeFilePath(vendor, key, salt = '') {
|
||||||
|
const extension = getFileExtension(vendor);
|
||||||
|
return `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt}`)}.${extension}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getFileExtension(vendor) {
|
||||||
|
const mp3Extension = 'mp3';
|
||||||
|
const r8Extension = 'r8';
|
||||||
|
|
||||||
|
switch (vendor) {
|
||||||
|
case 'azure':
|
||||||
|
case 'microsoft':
|
||||||
|
if (!JAMBONES_DISABLE_TTS_STREAMING || JAMBONES_TTS_TRIM_SILENCE) {
|
||||||
|
return r8Extension;
|
||||||
|
} else {
|
||||||
|
return mp3Extension;
|
||||||
|
}
|
||||||
|
case 'deepgram':
|
||||||
|
case 'elevenlabs':
|
||||||
|
case 'rimlabs':
|
||||||
|
if (!JAMBONES_DISABLE_TTS_STREAMING) {
|
||||||
|
return r8Extension;
|
||||||
|
} else {
|
||||||
|
return mp3Extension;
|
||||||
|
}
|
||||||
|
case 'nuance':
|
||||||
|
case 'nvidia':
|
||||||
|
return r8Extension;
|
||||||
|
default:
|
||||||
|
return mp3Extension;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const noopLogger = {
|
const noopLogger = {
|
||||||
@@ -43,6 +80,18 @@ function makeIbmKey(apiKey) {
|
|||||||
return `ibm:${hash.digest('hex')}`;
|
return `ibm:${hash.digest('hex')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeAwsKey(awsAccessKeyId) {
|
||||||
|
const hash = crypto.createHash('sha1');
|
||||||
|
hash.update(awsAccessKeyId);
|
||||||
|
return `aws:${hash.digest('hex')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeVerbioKey(client_id) {
|
||||||
|
const hash = crypto.createHash('sha1');
|
||||||
|
hash.update(client_id);
|
||||||
|
return `verbio:${hash.digest('hex')}`;
|
||||||
|
}
|
||||||
|
|
||||||
function makeNuanceKey(clientId, secret, scope) {
|
function makeNuanceKey(clientId, secret, scope) {
|
||||||
const hash = crypto.createHash('sha1');
|
const hash = crypto.createHash('sha1');
|
||||||
hash.update(`${clientId}:${secret}:${scope}`);
|
hash.update(`${clientId}:${secret}:${scope}`);
|
||||||
@@ -106,16 +155,18 @@ const createRivaClient = async(rivaUri) => {
|
|||||||
return client;
|
return client;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
makeSynthKey,
|
makeSynthKey,
|
||||||
makeNuanceKey,
|
makeNuanceKey,
|
||||||
makeIbmKey,
|
makeIbmKey,
|
||||||
|
makeAwsKey,
|
||||||
|
makeVerbioKey,
|
||||||
getNuanceAccessToken,
|
getNuanceAccessToken,
|
||||||
createNuanceClient,
|
createNuanceClient,
|
||||||
createKryptonClient,
|
createKryptonClient,
|
||||||
createRivaClient,
|
createRivaClient,
|
||||||
makeBasicAuthHeader,
|
makeBasicAuthHeader,
|
||||||
NUANCE_AUTH_ENDPOINT,
|
NUANCE_AUTH_ENDPOINT,
|
||||||
noopLogger
|
noopLogger,
|
||||||
|
makeFilePath
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+4507
-4462
File diff suppressed because it is too large
Load Diff
+17
-15
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.0.8",
|
"version": "0.1.3",
|
||||||
"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",
|
||||||
@@ -9,9 +9,10 @@
|
|||||||
"test": "test"
|
"test": "test"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "NODE_ENV=test JAMBONES_REDIS_USERNAME=daveh JAMBONES_REDIS_PASSWORD=foobarbazzle node test/ ",
|
"test": "NODE_ENV=test node test/ ",
|
||||||
"coverage": "nyc --reporter html --report-dir ./coverage npm run test",
|
"coverage": "nyc --reporter html --report-dir ./coverage npm run test",
|
||||||
"jslint": "eslint index.js lib",
|
"jslint": "eslint index.js lib",
|
||||||
|
"jslint:fix": "eslint --fix '**/*.js'",
|
||||||
"build": "./build_stubs.sh"
|
"build": "./build_stubs.sh"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -24,25 +25,26 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/jambonz/speech-utils#readme",
|
"homepage": "https://github.com/jambonz/speech-utils#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-polly": "^3.276.0",
|
"@aws-sdk/client-polly": "^3.496.0",
|
||||||
"@google-cloud/text-to-speech": "^4.2.0",
|
"@aws-sdk/client-sts": "^3.496.0",
|
||||||
"@grpc/grpc-js": "^1.8.7",
|
"@google-cloud/text-to-speech": "^5.0.2",
|
||||||
"@jambonz/realtimedb-helpers": "^0.6.3",
|
"@grpc/grpc-js": "^1.9.14",
|
||||||
"aws-sdk": "^2.1310.0",
|
"@jambonz/realtimedb-helpers": "^0.8.7",
|
||||||
"bent": "^7.3.12",
|
"bent": "^7.3.12",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
|
"form-urlencoded": "^6.1.4",
|
||||||
"google-protobuf": "^3.21.2",
|
"google-protobuf": "^3.21.2",
|
||||||
"ibm-watson": "^7.1.2",
|
"ibm-watson": "^8.0.0",
|
||||||
"form-urlencoded": "^6.1.0",
|
"microsoft-cognitiveservices-speech-sdk": "1.36.0",
|
||||||
"microsoft-cognitiveservices-speech-sdk": "^1.25.0",
|
"openai": "^4.25.0",
|
||||||
"undici": "^5.19.1"
|
"undici": "^6.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"config": "^3.3.9",
|
"config": "^3.3.10",
|
||||||
"eslint": "^8.33.0",
|
"eslint": "^8.56.0",
|
||||||
"eslint-plugin-promise": "^6.1.1",
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"pino": "^7.2.0",
|
"pino": "^8.17.0",
|
||||||
"tape": "^5.1.1"
|
"tape": "^5.7.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,9 +62,9 @@ function deserialize_nuance_tts_v1_UnarySynthesisResponse(buffer_arg) {
|
|||||||
|
|
||||||
//
|
//
|
||||||
// The Synthesizer service offers these functionalities:
|
// The Synthesizer service offers these functionalities:
|
||||||
// - GetVoices: Queries the list of available voices, with filters to reduce the search space.
|
// - GetVoices: Queries the list of available voices, with filters to reduce the search space.
|
||||||
// - Synthesize: Synthesizes audio from input text and parameters, and returns an audio stream.
|
// - Synthesize: Synthesizes audio from input text and parameters, and returns an audio stream.
|
||||||
// - UnarySynthesize: Synthesizes audio from input text and parameters, and returns a single audio response.
|
// - UnarySynthesize: Synthesizes audio from input text and parameters, and returns a single audio response.
|
||||||
var SynthesizerService = exports.SynthesizerService = {
|
var SynthesizerService = exports.SynthesizerService = {
|
||||||
getVoices: {
|
getVoices: {
|
||||||
path: '/nuance.tts.v1.Synthesizer/GetVoices',
|
path: '/nuance.tts.v1.Synthesizer/GetVoices',
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
// GENERATED CODE -- NO SERVICES IN PROTO
|
// GENERATED CODE -- NO SERVICES IN PROTO
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ function deserialize_nvidia_riva_tts_SynthesizeSpeechResponse(buffer_arg) {
|
|||||||
var RivaSpeechSynthesisService = exports.RivaSpeechSynthesisService = {
|
var RivaSpeechSynthesisService = exports.RivaSpeechSynthesisService = {
|
||||||
// Used to request text-to-speech from the service. Submit a request containing the
|
// Used to request text-to-speech from the service. Submit a request containing the
|
||||||
// desired text and configuration, and receive audio bytes in the requested format.
|
// desired text and configuration, and receive audio bytes in the requested format.
|
||||||
synthesize: {
|
synthesize: {
|
||||||
path: '/nvidia.riva.tts.RivaSpeechSynthesis/Synthesize',
|
path: '/nvidia.riva.tts.RivaSpeechSynthesis/Synthesize',
|
||||||
requestStream: false,
|
requestStream: false,
|
||||||
responseStream: false,
|
responseStream: false,
|
||||||
@@ -69,9 +69,9 @@ synthesize: {
|
|||||||
responseDeserialize: deserialize_nvidia_riva_tts_SynthesizeSpeechResponse,
|
responseDeserialize: deserialize_nvidia_riva_tts_SynthesizeSpeechResponse,
|
||||||
},
|
},
|
||||||
// Used to request text-to-speech returned via stream as it becomes available.
|
// Used to request text-to-speech returned via stream as it becomes available.
|
||||||
// Submit a SynthesizeSpeechRequest with desired text and configuration,
|
// Submit a SynthesizeSpeechRequest with desired text and configuration,
|
||||||
// and receive stream of bytes in the requested format.
|
// and receive stream of bytes in the requested format.
|
||||||
synthesizeOnline: {
|
synthesizeOnline: {
|
||||||
path: '/nvidia.riva.tts.RivaSpeechSynthesis/SynthesizeOnline',
|
path: '/nvidia.riva.tts.RivaSpeechSynthesis/SynthesizeOnline',
|
||||||
requestStream: false,
|
requestStream: false,
|
||||||
responseStream: true,
|
responseStream: true,
|
||||||
@@ -83,7 +83,7 @@ synthesizeOnline: {
|
|||||||
responseDeserialize: deserialize_nvidia_riva_tts_SynthesizeSpeechResponse,
|
responseDeserialize: deserialize_nvidia_riva_tts_SynthesizeSpeechResponse,
|
||||||
},
|
},
|
||||||
// Enables clients to request the configuration of the current Synthesize service, or a specific model within the service.
|
// Enables clients to request the configuration of the current Synthesize service, or a specific model within the service.
|
||||||
getRivaSynthesisConfig: {
|
getRivaSynthesisConfig: {
|
||||||
path: '/nvidia.riva.tts.RivaSpeechSynthesis/GetRivaSynthesisConfig',
|
path: '/nvidia.riva.tts.RivaSpeechSynthesis/GetRivaSynthesisConfig',
|
||||||
requestStream: false,
|
requestStream: false,
|
||||||
responseStream: false,
|
responseStream: false,
|
||||||
|
|||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
const test = require('tape').test ;
|
||||||
|
const config = require('config');
|
||||||
|
const opts = config.get('redis');
|
||||||
|
const logger = require('pino')({level: 'error'});
|
||||||
|
process.on('unhandledRejection', (reason, p) => {
|
||||||
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||||
|
});
|
||||||
|
|
||||||
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
test('AWS - create and cache auth token', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {client, getAwsAuthToken} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY || !process.env.AWS_REGION) {
|
||||||
|
t.pass('skipping AWS auth token tests since no AWS credentials provided');
|
||||||
|
t.end();
|
||||||
|
client.quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
|
||||||
|
//console.log({obj}, 'received auth token from AWS');
|
||||||
|
t.ok(obj.securityToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
|
||||||
|
|
||||||
|
await sleep(250);
|
||||||
|
obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
|
||||||
|
//console.log({obj}, 'received auth token from AWS - second request');
|
||||||
|
t.ok(obj.securityToken && obj.servedFromCache, 'successfully received access token from cache');
|
||||||
|
|
||||||
|
await client.flushall();
|
||||||
|
t.end();
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
+2
-2
@@ -31,7 +31,7 @@ test('IBM - create access key', async(t) => {
|
|||||||
//console.log({obj}, 'received access token from IBM - second request');
|
//console.log({obj}, 'received access token from IBM - second request');
|
||||||
t.ok(obj.access_token && obj.servedFromCache, 'successfully received access token from cache');
|
t.ok(obj.access_token && obj.servedFromCache, 'successfully received access token from cache');
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
t.end();
|
t.end();
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@@ -65,7 +65,7 @@ test('IBM - retrieve tts voices test', async(t) => {
|
|||||||
t.ok(voices.length > 0 && voices[0].language,
|
t.ok(voices.length > 0 && voices[0].language,
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from IBM`);
|
`GetVoices: successfully retrieved ${voices.length} voices from IBM`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
require('./docker_start');
|
require('./docker_start');
|
||||||
require('./synth');
|
require('./synth');
|
||||||
require('./list-voices');
|
require('./list-voices');
|
||||||
|
require('./aws');
|
||||||
|
require('./ibm');
|
||||||
|
require('./nuance');
|
||||||
require('./docker_stop');
|
require('./docker_stop');
|
||||||
|
|||||||
+32
-6
@@ -12,6 +12,32 @@ const stats = {
|
|||||||
histogram: () => {}
|
histogram: () => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
test('Verbio - get Access key and voices', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {client, getTtsVoices, getVerbioAccessToken} = fn(opts, logger);
|
||||||
|
if (!process.env.VERBIO_CLIENT_ID || !process.env.VERBIO_CLIENT_SECRET) {
|
||||||
|
t.pass('skipping Verbio test since no Verbio Keys provided');
|
||||||
|
t.end();
|
||||||
|
client.quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const credentials = {
|
||||||
|
client_id: process.env.VERBIO_CLIENT_ID,
|
||||||
|
client_secret: process.env.VERBIO_CLIENT_SECRET
|
||||||
|
};
|
||||||
|
let obj = await getVerbioAccessToken(credentials);
|
||||||
|
t.ok(obj.access_token , 'successfully received access token not from cache');
|
||||||
|
const voices = await getTtsVoices({vendor: 'verbio', credentials});
|
||||||
|
t.ok(voices && voices.length != 0, 'successfully received verbio voices');
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
test('IBM - create access key', async(t) => {
|
test('IBM - create access key', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {client, getIbmAccessToken} = fn(opts, logger);
|
const {client, getIbmAccessToken} = fn(opts, logger);
|
||||||
@@ -31,7 +57,7 @@ test('IBM - create access key', async(t) => {
|
|||||||
//console.log({obj}, 'received access token from IBM - second request');
|
//console.log({obj}, 'received access token from IBM - second request');
|
||||||
t.ok(obj.access_token && obj.servedFromCache, 'successfully received access token from cache');
|
t.ok(obj.access_token && obj.servedFromCache, 'successfully received access token from cache');
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
t.end();
|
t.end();
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
@@ -65,7 +91,7 @@ test('IBM - retrieve tts voices test', async(t) => {
|
|||||||
t.ok(voices.length > 0 && voices[0].language,
|
t.ok(voices.length > 0 && voices[0].language,
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from IBM`);
|
`GetVoices: successfully retrieved ${voices.length} voices from IBM`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
||||||
@@ -99,7 +125,7 @@ test('Nuance hosted tests', async(t) => {
|
|||||||
t.ok(voices.length > 0 && voices[0].language,
|
t.ok(voices.length > 0 && voices[0].language,
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
||||||
@@ -132,7 +158,7 @@ test('Nuance on-prem tests', async(t) => {
|
|||||||
t.ok(voices.length > 0 && voices[0].language,
|
t.ok(voices.length > 0 && voices[0].language,
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
||||||
@@ -162,7 +188,7 @@ test('Google tests', async(t) => {
|
|||||||
let result = await getTtsVoices(opts);
|
let result = await getTtsVoices(opts);
|
||||||
t.ok(result[0].voices.length > 0, `GetVoices: successfully retrieved ${result[0].voices.length} voices from Google`);
|
t.ok(result[0].voices.length > 0, `GetVoices: successfully retrieved ${result[0].voices.length} voices from Google`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
}
|
}
|
||||||
@@ -193,7 +219,7 @@ test('AWS tests', async(t) => {
|
|||||||
let result = await getTtsVoices(opts);
|
let result = await getTtsVoices(opts);
|
||||||
t.ok(result?.Voices?.length > 0, `GetVoices: successfully retrieved ${result.Voices.length} voices from AWS`);
|
t.ok(result?.Voices?.length > 0, `GetVoices: successfully retrieved ${result.Voices.length} voices from AWS`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -34,7 +34,7 @@ test('Nuance hosted tests', async(t) => {
|
|||||||
t.ok(voices.length > 0 && voices[0].language,
|
t.ok(voices.length > 0 && voices[0].language,
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ test('Nuance on-prem tests', async(t) => {
|
|||||||
t.ok(voices.length > 0 && voices[0].language,
|
t.ok(voices.length > 0 && voices[0].language,
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
||||||
|
|
||||||
await client.flushallAsync();
|
await client.flushall();
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
#
|
||||||
|
# Recommended minimum configuration:
|
||||||
|
#
|
||||||
|
|
||||||
|
# Example rule allowing access from your local networks.
|
||||||
|
# Adapt to list your (internal) IP networks from where browsing
|
||||||
|
# should be allowed
|
||||||
|
acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
|
||||||
|
acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
|
||||||
|
acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
|
||||||
|
acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
|
||||||
|
acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
|
||||||
|
acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
|
||||||
|
acl localnet src fc00::/7 # RFC 4193 local private network range
|
||||||
|
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
|
||||||
|
|
||||||
|
acl SSL_ports port 443
|
||||||
|
acl Safe_ports port 80 # http
|
||||||
|
acl Safe_ports port 21 # ftp
|
||||||
|
acl Safe_ports port 443 # https
|
||||||
|
acl Safe_ports port 70 # gopher
|
||||||
|
acl Safe_ports port 210 # wais
|
||||||
|
acl Safe_ports port 1025-65535 # unregistered ports
|
||||||
|
acl Safe_ports port 280 # http-mgmt
|
||||||
|
acl Safe_ports port 488 # gss-http
|
||||||
|
acl Safe_ports port 591 # filemaker
|
||||||
|
acl Safe_ports port 777 # multiling http
|
||||||
|
|
||||||
|
#
|
||||||
|
# Recommended minimum Access Permission configuration:
|
||||||
|
#
|
||||||
|
# Deny requests to certain unsafe ports
|
||||||
|
http_access deny !Safe_ports
|
||||||
|
|
||||||
|
# Deny CONNECT to other than secure SSL ports
|
||||||
|
http_access allow CONNECT !SSL_ports
|
||||||
|
|
||||||
|
# Only allow cachemgr access from localhost
|
||||||
|
http_access allow localhost manager
|
||||||
|
http_access deny manager
|
||||||
|
|
||||||
|
# This default configuration only allows localhost requests because a more
|
||||||
|
# permissive Squid installation could introduce new attack vectors into the
|
||||||
|
# network by proxying external TCP connections to unprotected services.
|
||||||
|
http_access allow localhost
|
||||||
|
|
||||||
|
# The two deny rules below are unnecessary in this default configuration
|
||||||
|
# because they are followed by a "deny all" rule. However, they may become
|
||||||
|
# critically important when you start allowing external requests below them.
|
||||||
|
|
||||||
|
# Protect web applications running on the same server as Squid. They often
|
||||||
|
# assume that only local users can access them at "localhost" ports.
|
||||||
|
http_access deny to_localhost
|
||||||
|
|
||||||
|
# Protect cloud servers that provide local users with sensitive info about
|
||||||
|
# their server via certain well-known link-local (a.k.a. APIPA) addresses.
|
||||||
|
http_access deny to_linklocal
|
||||||
|
|
||||||
|
#
|
||||||
|
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
|
||||||
|
#
|
||||||
|
|
||||||
|
# For example, to allow access from your local networks, you may uncomment the
|
||||||
|
# following rule (and/or add rules that match your definition of "local"):
|
||||||
|
# http_access allow localnet
|
||||||
|
|
||||||
|
# And finally deny all other access to this proxy
|
||||||
|
http_access deny all
|
||||||
|
|
||||||
|
# Squid normally listens to port 3128
|
||||||
|
http_port 3128
|
||||||
|
|
||||||
|
# Uncomment and adjust the following to add a disk cache directory.
|
||||||
|
#cache_dir ufs /usr/local/var/cache/squid 100 16 256
|
||||||
|
|
||||||
|
# Leave coredumps in the first cache dir
|
||||||
|
coredump_dir /usr/local/var/cache/squid
|
||||||
|
|
||||||
|
#
|
||||||
|
# Add any of your own refresh_pattern entries above these.
|
||||||
|
#
|
||||||
|
refresh_pattern ^ftp: 1440 20% 10080
|
||||||
|
refresh_pattern ^gopher: 1440 0% 1440
|
||||||
|
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
|
||||||
|
refresh_pattern . 0 20% 4320
|
||||||
+363
-18
@@ -20,7 +20,7 @@ const stats = {
|
|||||||
|
|
||||||
test('Google speech synth tests', async(t) => {
|
test('Google speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, addFileToCache, client} = fn(opts, logger);
|
||||||
|
|
||||||
if (!process.env.GCP_FILE && !process.env.GCP_JSON_KEY) {
|
if (!process.env.GCP_FILE && !process.env.GCP_JSON_KEY) {
|
||||||
t.pass('skipping google speech synth tests since neither GCP_FILE nor GCP_JSON_KEY provided');
|
t.pass('skipping google speech synth tests since neither GCP_FILE nor GCP_JSON_KEY provided');
|
||||||
@@ -38,7 +38,7 @@ test('Google speech synth tests', async(t) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
language: 'en-GB',
|
language: 'en-GB',
|
||||||
gender: 'MALE',
|
gender: 'FEMALE',
|
||||||
text: 'This is a test. This is only a test',
|
text: 'This is a test. This is only a test',
|
||||||
salt: 'foo.bar',
|
salt: 'foo.bar',
|
||||||
});
|
});
|
||||||
@@ -53,11 +53,19 @@ test('Google speech synth tests', async(t) => {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
language: 'en-GB',
|
language: 'en-GB',
|
||||||
gender: 'MALE',
|
gender: 'FEMALE',
|
||||||
text: 'This is a test. This is only a test',
|
text: 'This is a test. This is only a test',
|
||||||
});
|
});
|
||||||
t.ok(opts.servedFromCache, `successfully retrieved cached google audio from ${opts.filePath}`);
|
t.ok(opts.servedFromCache, `successfully retrieved cached google audio from ${opts.filePath}`);
|
||||||
|
|
||||||
|
const success = await addFileToCache(opts.filePath, {
|
||||||
|
vendor: 'google',
|
||||||
|
language: 'en-GB',
|
||||||
|
gender: 'FEMALE',
|
||||||
|
text: 'This is a test. This is only a test'
|
||||||
|
});
|
||||||
|
t.ok(success, `successfully added ${opts.filePath} to cache`);
|
||||||
|
|
||||||
opts = await synthAudio(stats, {
|
opts = await synthAudio(stats, {
|
||||||
vendor: 'google',
|
vendor: 'google',
|
||||||
credentials: {
|
credentials: {
|
||||||
@@ -68,7 +76,7 @@ test('Google speech synth tests', async(t) => {
|
|||||||
},
|
},
|
||||||
disableTtsCache: true,
|
disableTtsCache: true,
|
||||||
language: 'en-GB',
|
language: 'en-GB',
|
||||||
gender: 'MALE',
|
gender: 'FEMALE',
|
||||||
text: 'This is a test. This is only a test',
|
text: 'This is a test. This is only a test',
|
||||||
});
|
});
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized google audio regardless of current cache to ${opts.filePath}`);
|
t.ok(!opts.servedFromCache, `successfully synthesized google audio regardless of current cache to ${opts.filePath}`);
|
||||||
@@ -79,6 +87,40 @@ test('Google speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Google speech Custom voice synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.GCP_CUSTOM_VOICE_FILE && !process.env.GCP_CUSTOM_VOICE_JSON_KEY || !process.env.GCP_CUSTOM_VOICE_MODEL) {
|
||||||
|
t.pass('skipping google speech synth tests since neither GCP_CUSTOM_VOICE_FILE nor GCP_CUSTOM_VOICE_JSON_KEY provided, GCP_CUSTOM_VOICE_MODEL is not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const str = process.env.GCP_CUSTOM_VOICE_JSON_KEY || fs.readFileSync(process.env.GCP_CUSTOM_VOICE_FILE);
|
||||||
|
const creds = JSON.parse(str);
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: {
|
||||||
|
credentials: {
|
||||||
|
client_email: creds.client_email,
|
||||||
|
private_key: creds.private_key,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
language: 'en-AU',
|
||||||
|
text: 'This is a test. This is only a test',
|
||||||
|
voice: {
|
||||||
|
reportedUsage:"REALTIME",
|
||||||
|
model: process.env.GCP_CUSTOM_VOICE_MODEL
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized google custom voice audio to ${opts.filePath}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
test('AWS speech synth tests', async(t) => {
|
test('AWS speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -120,6 +162,33 @@ test('AWS speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('AWS speech synth tests by RoleArn', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.AWS_ROLE_ARN || !process.env.AWS_REGION) {
|
||||||
|
t.pass('skipping AWS speech synth tests by RoleArn since AWS_ROLE_ARN or AWS_REGION not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'aws',
|
||||||
|
credentials: {
|
||||||
|
roleArn: process.env.AWS_ROLE_ARN,
|
||||||
|
region: process.env.AWS_REGION,
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'Joey',
|
||||||
|
text: 'This is a test. This is only a test',
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized aws by roleArn audio to ${opts.filePath}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
test('Azure speech synth tests', async(t) => {
|
test('Azure speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -146,9 +215,12 @@ test('Azure speech synth tests', async(t) => {
|
|||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'en-US-ChristopherNeural',
|
voice: 'en-US-ChristopherNeural',
|
||||||
text: longText,
|
text: longText,
|
||||||
|
renderForCaching: true
|
||||||
});
|
});
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized microsoft audio to ${opts.filePath}`);
|
t.ok(!opts.servedFromCache, `successfully synthesized microsoft audio to ${opts.filePath}`);
|
||||||
|
if (process.env.JAMBONES_HTTP_PROXY_IP && process.env.JAMBONES_HTTP_PROXY_PORT) {
|
||||||
|
t.pass('successfully used proxy to reach microsoft tts service');
|
||||||
|
}
|
||||||
|
|
||||||
opts = await synthAudio(stats, {
|
opts = await synthAudio(stats, {
|
||||||
vendor: 'microsoft',
|
vendor: 'microsoft',
|
||||||
@@ -159,6 +231,7 @@ test('Azure speech synth tests', async(t) => {
|
|||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'en-US-ChristopherNeural',
|
voice: 'en-US-ChristopherNeural',
|
||||||
text: longText,
|
text: longText,
|
||||||
|
renderForCaching: true
|
||||||
});
|
});
|
||||||
t.ok(opts.servedFromCache, `successfully retrieved microsoft audio from cache ${opts.filePath}`);
|
t.ok(opts.servedFromCache, `successfully retrieved microsoft audio from cache ${opts.filePath}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -168,6 +241,58 @@ test('Azure speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Azure SSML tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.MICROSOFT_API_KEY || !process.env.MICROSOFT_REGION) {
|
||||||
|
t.pass('skipping Microsoft speech synth tests since MICROSOFT_API_KEY or MICROSOFT_REGION not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const text = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="en-US">
|
||||||
|
<voice name="en-US-JennyMultilingualNeural">
|
||||||
|
<mstts:express-as style="cheerful" styledegree="2">That'd be just amazing!
|
||||||
|
</mstts:express-as>
|
||||||
|
</voice>
|
||||||
|
</speak>`;
|
||||||
|
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'microsoft',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.MICROSOFT_API_KEY,
|
||||||
|
region: process.env.MICROSOFT_REGION,
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-ChristopherNeural',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized microsoft audio to ${opts.filePath}`);
|
||||||
|
if (process.env.JAMBONES_HTTP_PROXY_IP && process.env.JAMBONES_HTTP_PROXY_PORT) {
|
||||||
|
t.pass('successfully used proxy to reach microsoft tts service');
|
||||||
|
}
|
||||||
|
|
||||||
|
opts = await synthAudio(stats, {
|
||||||
|
vendor: 'microsoft',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.MICROSOFT_API_KEY,
|
||||||
|
region: process.env.MICROSOFT_REGION,
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-ChristopherNeural',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(opts.servedFromCache, `successfully retrieved microsoft audio from cache ${opts.filePath}`);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
test('Azure custom voice speech synth tests', async(t) => {
|
test('Azure custom voice speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -189,6 +314,7 @@ test('Azure custom voice speech synth tests', async(t) => {
|
|||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: process.env.MICROSOFT_CUSTOM_VOICE,
|
voice: process.env.MICROSOFT_CUSTOM_VOICE,
|
||||||
text,
|
text,
|
||||||
|
renderForCaching: true
|
||||||
});
|
});
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized microsoft audio to ${opts.filePath}`);
|
t.ok(!opts.servedFromCache, `successfully synthesized microsoft audio to ${opts.filePath}`);
|
||||||
|
|
||||||
@@ -203,6 +329,7 @@ test('Azure custom voice speech synth tests', async(t) => {
|
|||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: process.env.MICROSOFT_CUSTOM_VOICE,
|
voice: process.env.MICROSOFT_CUSTOM_VOICE,
|
||||||
text,
|
text,
|
||||||
|
renderForCaching: true
|
||||||
});
|
});
|
||||||
t.ok(opts.servedFromCache, `successfully retrieved microsoft custom voice audio from cache ${opts.filePath}`);
|
t.ok(opts.servedFromCache, `successfully retrieved microsoft custom voice audio from cache ${opts.filePath}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -300,7 +427,7 @@ test('Nvidia speech synth tests', async(t) => {
|
|||||||
let opts = await synthAudio(stats, {
|
let opts = await synthAudio(stats, {
|
||||||
vendor: 'nvidia',
|
vendor: 'nvidia',
|
||||||
credentials: {
|
credentials: {
|
||||||
riva_uri: process.env.RIVA_URI,
|
riva_server_uri: process.env.RIVA_URI,
|
||||||
},
|
},
|
||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'English-US.Female-1',
|
voice: 'English-US.Female-1',
|
||||||
@@ -311,7 +438,7 @@ test('Nvidia speech synth tests', async(t) => {
|
|||||||
opts = await synthAudio(stats, {
|
opts = await synthAudio(stats, {
|
||||||
vendor: 'nvidia',
|
vendor: 'nvidia',
|
||||||
credentials: {
|
credentials: {
|
||||||
riva_uri: process.env.RIVA_URI,
|
riva_server_uri: process.env.RIVA_URI,
|
||||||
},
|
},
|
||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'English-US.Female-1',
|
voice: 'English-US.Female-1',
|
||||||
@@ -411,20 +538,227 @@ test('Custom Vendor speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('Elevenlabs speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.ELEVENLABS_API_KEY || !process.env.ELEVENLABS_VOICE_ID || !process.env.ELEVENLABS_MODEL_ID) {
|
||||||
|
t.pass('skipping ElevenLabs speech synth tests since ELEVENLABS_API_KEY or ELEVENLABS_VOICE_ID or ELEVENLABS_MODEL_ID not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'elevenlabs',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.ELEVENLABS_API_KEY,
|
||||||
|
model_id: process.env.ELEVENLABS_MODEL_ID,
|
||||||
|
options: JSON.stringify({
|
||||||
|
optimize_streaming_latency: 1,
|
||||||
|
voice_settings: {
|
||||||
|
similarity_boost: 1,
|
||||||
|
stability: 0.8,
|
||||||
|
style: 1,
|
||||||
|
use_speaker_boost: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: process.env.ELEVENLABS_VOICE_ID,
|
||||||
|
text,
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized eleven audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
})
|
||||||
|
|
||||||
|
test('PlayHT speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.PLAYHT_API_KEY || !process.env.PLAYHT_USER_ID) {
|
||||||
|
t.pass('skipping PlayHT speech synth tests since PLAYHT_API_KEY or PLAYHT_USER_ID is/are not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'playht',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.PLAYHT_API_KEY,
|
||||||
|
user_id: process.env.PLAYHT_USER_ID,
|
||||||
|
voice_engine: 'PlayHT2.0-turbo',
|
||||||
|
options: JSON.stringify({
|
||||||
|
quality: "medium",
|
||||||
|
speed: 1,
|
||||||
|
seed: 1,
|
||||||
|
temperature: 1,
|
||||||
|
emotion: "female_happy",
|
||||||
|
voice_guidance: 3,
|
||||||
|
style_guidance: 20,
|
||||||
|
text_guidance: 1,
|
||||||
|
})
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 's3://voice-cloning-zero-shot/d9ff78ba-d016-47f6-b0ef-dd630f59414e/female-cs/manifest.json',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully playht eleven audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('rimelabs speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.RIMELABS_API_KEY) {
|
||||||
|
t.pass('skipping rimelabs speech synth tests since RIMELABS_API_KEY is not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'rimelabs',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.RIMELABS_API_KEY,
|
||||||
|
model_id: 'mist',
|
||||||
|
options: JSON.stringify({
|
||||||
|
speedAlpha: 1.0,
|
||||||
|
reduceLatency: false
|
||||||
|
})
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'amber',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized rimelabs audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('whisper speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.OPENAI_API_KEY) {
|
||||||
|
t.pass('skipping OPENAI speech synth tests since OPENAI_API_KEY not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'whisper',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.OPENAI_API_KEY,
|
||||||
|
model_id: 'tts-1'
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'alloy',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized whisper audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Verbio speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.VERBIO_CLIENT_ID || !process.env.VERBIO_CLIENT_SECRET) {
|
||||||
|
t.pass('skipping Verbio Synthesize test since no Verbio Keys provided');
|
||||||
|
t.end();
|
||||||
|
client.quit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'verbio',
|
||||||
|
credentials: {
|
||||||
|
client_id: process.env.VERBIO_CLIENT_ID,
|
||||||
|
client_secret: process.env.VERBIO_CLIENT_SECRET
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'tommy_en-us',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized whisper audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
})
|
||||||
|
|
||||||
|
test('Deepgram speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.DEEPGRAM_API_KEY) {
|
||||||
|
t.pass('skipping Deepgram speech synth tests since DEEPGRAM_API_KEY');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
let opts = await synthAudio(stats, {
|
||||||
|
vendor: 'deepgram',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.DEEPGRAM_API_KEY
|
||||||
|
},
|
||||||
|
model: 'aura-asteria-en',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized deepgram audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
})
|
||||||
|
|
||||||
test('TTS Cache tests', async(t) => {
|
test('TTS Cache tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {purgeTtsCache, client} = fn(opts, logger);
|
const {purgeTtsCache, getTtsSize, client} = fn(opts, logger);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// save some random tts keys to cache
|
// save some random tts keys to cache
|
||||||
const minRecords = 8;
|
const minRecords = 8;
|
||||||
for (const i in Array(minRecords).fill(0)) {
|
for (const i in Array(minRecords).fill(0)) {
|
||||||
await client.setAsync(makeSynthKey({vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
||||||
}
|
}
|
||||||
|
const count = await getTtsSize();
|
||||||
|
t.ok(count >= minRecords, 'getTtsSize worked.');
|
||||||
|
|
||||||
const {purgedCount} = await purgeTtsCache();
|
const {purgedCount} = await purgeTtsCache();
|
||||||
t.ok(purgedCount >= minRecords, `successfully purged at least ${minRecords} tts records from cache`);
|
t.ok(purgedCount >= minRecords, `successfully purged at least ${minRecords} tts records from cache`);
|
||||||
|
|
||||||
const cached = (await client.keysAsync('tts:*')).length;
|
const cached = (await client.keys('tts:*')).length;
|
||||||
t.equal(cached, 0, `successfully purged all tts records from cache`);
|
t.equal(cached, 0, `successfully purged all tts records from cache`);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -435,11 +769,11 @@ test('TTS Cache tests', async(t) => {
|
|||||||
try {
|
try {
|
||||||
// save some random tts keys to cache
|
// save some random tts keys to cache
|
||||||
for (const i in Array(10).fill(0)) {
|
for (const i in Array(10).fill(0)) {
|
||||||
await client.setAsync(makeSynthKey({vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
await client.set(makeSynthKey({vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
||||||
}
|
}
|
||||||
// save a specific key to tts cache
|
// save a specific key to tts cache
|
||||||
const opts = {vendor: 'aws', language: 'en-US', voice: 'MALE', engine: 'Engine', text: 'Hello World!'};
|
const opts = {vendor: 'aws', language: 'en-US', voice: 'MALE', engine: 'Engine', text: 'Hello World!'};
|
||||||
await client.setAsync(makeSynthKey(opts), opts.text);
|
await client.set(makeSynthKey(opts), opts.text);
|
||||||
|
|
||||||
const {purgedCount} = await purgeTtsCache({all: false, ...opts});
|
const {purgedCount} = await purgeTtsCache({all: false, ...opts});
|
||||||
t.ok(purgedCount === 1, `successfully purged one specific tts record from cache`);
|
t.ok(purgedCount === 1, `successfully purged one specific tts record from cache`);
|
||||||
@@ -455,8 +789,19 @@ test('TTS Cache tests', async(t) => {
|
|||||||
t.ok(error, `error returned when specified key was not found`);
|
t.ok(error, `error returned when specified key was not found`);
|
||||||
|
|
||||||
// make sure other tts keys are still there
|
// make sure other tts keys are still there
|
||||||
const cached = (await client.keysAsync('tts:*')).length;
|
const cached = await client.keys('tts:*')
|
||||||
t.ok(cached >= 1, `successfully kept all non-specified tts records in cache`);
|
t.ok(cached.length >= 1, `successfully kept all non-specified tts records in cache`);
|
||||||
|
|
||||||
|
// retrieve keys from cache and check the key contains the file extension
|
||||||
|
let key = cached[0];
|
||||||
|
t.ok(key.includes('mp3'), `tts cache extension shoult be part of the key and equal mp3`);
|
||||||
|
|
||||||
|
process.env.VG_TRIM_TTS_SILENCE = 'true';
|
||||||
|
await client.set(makeSynthKey({ vendor: 'azure' }), 'value');
|
||||||
|
|
||||||
|
const r8Keys = await client.keys('tts:r8*');
|
||||||
|
key = r8Keys[0];
|
||||||
|
t.ok(key.includes('r8'), `tts cache extension shoult be part of the key and equal r8`);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(JSON.stringify(err));
|
console.error(JSON.stringify(err));
|
||||||
@@ -471,21 +816,21 @@ test('TTS Cache tests', async(t) => {
|
|||||||
const account_sid = "12412512_cabc_5aff"
|
const account_sid = "12412512_cabc_5aff"
|
||||||
const account_sid2 = "22412512_cabc_5aff"
|
const account_sid2 = "22412512_cabc_5aff"
|
||||||
for (const i in Array(minRecords).fill(0)) {
|
for (const i in Array(minRecords).fill(0)) {
|
||||||
await client.setAsync(makeSynthKey({account_sid, vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
await client.set(makeSynthKey({account_sid, vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
||||||
}
|
}
|
||||||
for (const i in Array(minRecords).fill(0)) {
|
for (const i in Array(minRecords).fill(0)) {
|
||||||
await client.setAsync(makeSynthKey({account_sid: account_sid2, vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
await client.set(makeSynthKey({account_sid: account_sid2, vendor: i, language: i, voice: i, engine: i, text: i}), i);
|
||||||
}
|
}
|
||||||
const {purgedCount} = await purgeTtsCache({account_sid});
|
const {purgedCount} = await purgeTtsCache({account_sid});
|
||||||
t.equal(purgedCount, minRecords, `successfully purged at least ${minRecords} tts records from cache for account_sid:${account_sid}`);
|
t.equal(purgedCount, minRecords, `successfully purged at least ${minRecords} tts records from cache for account_sid:${account_sid}`);
|
||||||
|
|
||||||
let cached = (await client.keysAsync('tts:*')).length;
|
let cached = (await client.keys('tts:*')).length;
|
||||||
t.equal(cached, minRecords, `successfully purged all tts records from cache for account_sid:${account_sid}`);
|
t.equal(cached, minRecords, `successfully purged all tts records from cache for account_sid:${account_sid}`);
|
||||||
|
|
||||||
const {purgedCount: purgedCount2} = await purgeTtsCache({account_sid: account_sid2});
|
const {purgedCount: purgedCount2} = await purgeTtsCache({account_sid: account_sid2});
|
||||||
t.equal(purgedCount2, minRecords, `successfully purged at least ${minRecords} tts records from cache for account_sid:${account_sid2}`);
|
t.equal(purgedCount2, minRecords, `successfully purged at least ${minRecords} tts records from cache for account_sid:${account_sid2}`);
|
||||||
|
|
||||||
cached = (await client.keysAsync('tts:*')).length;
|
cached = (await client.keys('tts:*')).length;
|
||||||
t.equal(cached, 0, `successfully purged all tts records from cache`);
|
t.equal(cached, 0, `successfully purged all tts records from cache`);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user