mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-03 23:33:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e099bbb58f | ||
|
|
e60a2d2ba3 | ||
|
|
2212be341b | ||
|
|
5d2d921f31 | ||
|
|
acb2d0c7ce | ||
|
|
90d6048f52 | ||
|
|
e5985620c0 | ||
|
|
eb57f4d290 | ||
|
|
f0a1ab139c | ||
|
|
79289a7249 | ||
|
|
5998eebdca | ||
|
|
e6a7017b55 | ||
|
|
c8571af129 | ||
|
|
6144a9c164 | ||
|
|
68a7f2b0d4 | ||
|
|
0d1cd37097 | ||
|
|
3de8e5ff57 | ||
|
|
b4aad7991b | ||
|
|
8a5c5c1966 | ||
|
|
08a56d1a40 | ||
|
|
ba61f20334 | ||
|
|
10316d786e | ||
|
|
38cdc106cc | ||
|
|
410b99ef24 | ||
|
|
51db63f992 | ||
|
|
c86dceadde |
@@ -8,8 +8,8 @@ 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
|
||||||
@@ -32,5 +32,7 @@ jobs:
|
|||||||
ELEVENLABS_API_KEY: ${{ secrets.ELEVENLABS_API_KEY }}
|
ELEVENLABS_API_KEY: ${{ secrets.ELEVENLABS_API_KEY }}
|
||||||
ELEVENLABS_VOICE_ID: ${{ secrets.ELEVENLABS_VOICE_ID }}
|
ELEVENLABS_VOICE_ID: ${{ secrets.ELEVENLABS_VOICE_ID }}
|
||||||
ELEVENLABS_MODEL_ID: ${{ secrets.ELEVENLABS_MODEL_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_IP: 127.0.0.1
|
||||||
JAMBONES_HTTP_PROXY_PORT: 3128
|
JAMBONES_HTTP_PROXY_PORT: 3128
|
||||||
|
|||||||
@@ -13,10 +13,11 @@ module.exports = (opts, logger) => {
|
|||||||
getTtsSize: require('./lib/get-tts-size').bind(null, client, logger),
|
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),
|
||||||
addFileToCache: require('./lib/add-file-to-cache').bind(null, client, logger),
|
addFileToCache: require('./lib/add-file-to-cache').bind(null, client, logger),
|
||||||
synthAudio: require('./lib/synth-audio').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),
|
||||||
getAwsAuthToken: require('./lib/get-aws-sts-token').bind(null, logger, createHash, retrieveHash),
|
getAwsAuthToken: require('./lib/get-aws-sts-token').bind(null, logger, createHash, retrieveHash),
|
||||||
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, logger),
|
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, createHash, retrieveHash, logger),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
module.exports = {
|
||||||
|
HTTP_TIMEOUT: 5000
|
||||||
|
};
|
||||||
+24
-15
@@ -1,32 +1,41 @@
|
|||||||
const { STSClient, GetSessionTokenCommand } = require('@aws-sdk/client-sts');
|
const { STSClient, GetSessionTokenCommand, AssumeRoleCommand } = require('@aws-sdk/client-sts');
|
||||||
const {makeAwsKey, noopLogger} = require('./utils');
|
const {makeAwsKey, noopLogger} = require('./utils');
|
||||||
const debug = require('debug')('jambonz:speech-utils');
|
const debug = require('debug')('jambonz:speech-utils');
|
||||||
const EXPIRY = 3600;
|
const EXPIRY = 3600;
|
||||||
|
|
||||||
async function getAwsAuthToken(
|
async function getAwsAuthToken(
|
||||||
logger,
|
logger, createHash, retrieveHash,
|
||||||
createHash, retrieveHash,
|
awsAccessKeyId, awsSecretAccessKey, awsRegion, roleArn = null) {
|
||||||
awsAccessKeyId, awsSecretAccessKey, awsRegion) {
|
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
try {
|
try {
|
||||||
const key = makeAwsKey(awsAccessKeyId);
|
const key = makeAwsKey(roleArn || awsAccessKeyId);
|
||||||
const obj = await retrieveHash(key);
|
const obj = await retrieveHash(key);
|
||||||
if (obj) return {...obj, servedFromCache: true};
|
if (obj) return {...obj, servedFromCache: true};
|
||||||
|
|
||||||
/* access token not found in cache, so generate it using STS */
|
let data;
|
||||||
const stsClient = new STSClient({
|
if (roleArn) {
|
||||||
region: awsRegion,
|
const stsClient = new STSClient({ region: awsRegion});
|
||||||
credentials: {
|
const roleToAssume = { RoleArn: roleArn, RoleSessionName: 'Jambonz_Speech', DurationSeconds: EXPIRY};
|
||||||
accessKeyId: awsAccessKeyId,
|
const command = new AssumeRoleCommand(roleToAssume);
|
||||||
secretAccessKey: awsSecretAccessKey,
|
|
||||||
}
|
data = await stsClient.send(command);
|
||||||
});
|
} else {
|
||||||
const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
|
/* access token not found in cache, so generate it using STS */
|
||||||
const data = await stsClient.send(command);
|
const stsClient = new STSClient({
|
||||||
|
region: awsRegion,
|
||||||
|
credentials: {
|
||||||
|
accessKeyId: awsAccessKeyId,
|
||||||
|
secretAccessKey: awsSecretAccessKey,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
|
||||||
|
data = await stsClient.send(command);
|
||||||
|
}
|
||||||
|
|
||||||
const credentials = {
|
const credentials = {
|
||||||
accessKeyId: data.Credentials.AccessKeyId,
|
accessKeyId: data.Credentials.AccessKeyId,
|
||||||
secretAccessKey: data.Credentials.SecretAccessKey,
|
secretAccessKey: data.Credentials.SecretAccessKey,
|
||||||
|
sessionToken: data.Credentials.SessionToken,
|
||||||
securityToken: data.Credentials.SessionToken
|
securityToken: data.Credentials.SessionToken
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ 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('./constants');
|
||||||
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;
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ 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('./constants');
|
||||||
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;
|
||||||
|
|||||||
+49
-12
@@ -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('./constants');
|
||||||
|
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,16 +92,26 @@ 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
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} 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 command = new DescribeVoicesCommand({});
|
||||||
const response = await client.send(command);
|
const response = await client.send(command);
|
||||||
return response;
|
return response;
|
||||||
@@ -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('./constants');
|
||||||
|
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;
|
||||||
+141
-19
@@ -22,6 +22,7 @@ const {
|
|||||||
noopLogger
|
noopLogger
|
||||||
} = require('./utils');
|
} = 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,
|
||||||
@@ -39,6 +40,7 @@ const debug = require('debug')('jambonz:realtimedb-helpers');
|
|||||||
const EXPIRES = (process.env.JAMBONES_TTS_CACHE_DURATION_MINS || 4 * 60) * 60; // cache tts for 4 hours
|
const EXPIRES = (process.env.JAMBONES_TTS_CACHE_DURATION_MINS || 4 * 60) * 60; // cache tts for 4 hours
|
||||||
const TMP_FOLDER = '/tmp';
|
const TMP_FOLDER = '/tmp';
|
||||||
const OpenAI = require('openai');
|
const OpenAI = require('openai');
|
||||||
|
const getAwsAuthToken = require('./get-aws-sts-token');
|
||||||
|
|
||||||
|
|
||||||
const trimTrailingSilence = (buffer) => {
|
const trimTrailingSilence = (buffer) => {
|
||||||
@@ -75,7 +77,7 @@ const trimTrailingSilence = (buffer) => {
|
|||||||
* @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,
|
vendor, language, voice, gender, text, engine, salt, model, credentials, deploymentId,
|
||||||
disableTtsCache, renderForCaching, disableTtsStreaming, options
|
disableTtsCache, renderForCaching, disableTtsStreaming, options
|
||||||
}) {
|
}) {
|
||||||
@@ -84,10 +86,10 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
let rtt;
|
let rtt;
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
|
|
||||||
assert.ok(['google', 'aws', 'polly', 'microsoft',
|
assert.ok(['google', 'aws', 'polly', 'microsoft', 'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs',
|
||||||
'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs', 'whisper', 'deepgram', 'playht'].includes(vendor) ||
|
'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');
|
||||||
}
|
}
|
||||||
@@ -123,17 +125,25 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
assert.ok(voice, 'synthAudio requires voice when elevenlabs is used');
|
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.api_key, 'synthAudio requires api_key when elevenlabs is used');
|
||||||
assert.ok(credentials.model_id, 'synthAudio requires model_id when elevenlabs is used');
|
assert.ok(credentials.model_id, 'synthAudio requires model_id when elevenlabs is used');
|
||||||
} else if ('playht' === vendor) {
|
} else if ('playht' === vendor) {
|
||||||
assert.ok(voice, 'synthAudio requires voice when playht is used');
|
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.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.user_id, 'synthAudio requires user_id when playht is used');
|
||||||
assert.ok(credentials.voice_engine, 'synthAudio requires voice_engine 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) {
|
} else if ('whisper' === vendor) {
|
||||||
assert.ok(voice, 'synthAudio requires voice when whisper is used');
|
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.model_id, 'synthAudio requires model when whisper is used');
|
||||||
assert.ok(credentials.api_key, 'synthAudio requires api_key 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,
|
||||||
@@ -144,14 +154,14 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
text
|
text
|
||||||
});
|
});
|
||||||
let filePath;
|
let filePath;
|
||||||
if (['nuance', 'nvidia'].includes(vendor) ||
|
if (['nuance', 'nvidia', 'verbio'].includes(vendor) ||
|
||||||
(
|
(
|
||||||
(process.env.JAMBONES_TTS_TRIM_SILENCE || !process.env.JAMBONES_DISABLE_TTS_STREAMING) &&
|
(process.env.JAMBONES_TTS_TRIM_SILENCE || !process.env.JAMBONES_DISABLE_TTS_STREAMING) &&
|
||||||
['microsoft', 'azure'].includes(vendor)
|
['microsoft', 'azure'].includes(vendor)
|
||||||
) ||
|
) ||
|
||||||
(
|
(
|
||||||
!process.env.JAMBONES_DISABLE_TTS_STREAMING &&
|
!process.env.JAMBONES_DISABLE_TTS_STREAMING &&
|
||||||
['elevenlabs', 'deepgram'].includes(vendor)
|
['elevenlabs', 'deepgram', 'rimelabs'].includes(vendor)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`;
|
filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`;
|
||||||
@@ -183,7 +193,8 @@ 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':
|
||||||
@@ -217,11 +228,22 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
});
|
});
|
||||||
if (audioBuffer?.filePath) return audioBuffer;
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
break;
|
break;
|
||||||
|
case 'rimelabs':
|
||||||
|
audioBuffer = await synthRimelabs(logger, {
|
||||||
|
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming, filePath
|
||||||
|
});
|
||||||
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
|
break;
|
||||||
case 'whisper':
|
case 'whisper':
|
||||||
audioBuffer = await synthWhisper(logger, {
|
audioBuffer = await synthWhisper(logger, {
|
||||||
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
||||||
if (audioBuffer?.filePath) return audioBuffer;
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
break;
|
break;
|
||||||
|
case 'verbio':
|
||||||
|
audioBuffer = await synthVerbio(client, logger, {
|
||||||
|
credentials, stats, voice, text, renderForCaching, disableTtsStreaming});
|
||||||
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
|
break;
|
||||||
case 'deepgram':
|
case 'deepgram':
|
||||||
audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text,
|
audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text,
|
||||||
renderForCaching, disableTtsStreaming});
|
renderForCaching, disableTtsStreaming});
|
||||||
@@ -253,16 +275,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',
|
||||||
@@ -356,7 +390,7 @@ async function _synthOnPremMicrosoft(logger, {
|
|||||||
text,
|
text,
|
||||||
filePath
|
filePath
|
||||||
}) {
|
}) {
|
||||||
const {use_custom_tts, custom_tts_endpoint_url} = credentials;
|
const {use_custom_tts, custom_tts_endpoint_url, api_key} = credentials;
|
||||||
let content = text;
|
let content = text;
|
||||||
|
|
||||||
if (use_custom_tts && !content.startsWith('<speak')) {
|
if (use_custom_tts && !content.startsWith('<speak')) {
|
||||||
@@ -380,7 +414,8 @@ async function _synthOnPremMicrosoft(logger, {
|
|||||||
const post = bent('POST', 'buffer', {
|
const post = bent('POST', 'buffer', {
|
||||||
'X-Microsoft-OutputFormat': trimSilence ? 'raw-8khz-16bit-mono-pcm' : 'audio-16khz-32kbitrate-mono-mp3',
|
'X-Microsoft-OutputFormat': trimSilence ? 'raw-8khz-16bit-mono-pcm' : 'audio-16khz-32kbitrate-mono-mp3',
|
||||||
'Content-Type': 'application/ssml+xml',
|
'Content-Type': 'application/ssml+xml',
|
||||||
'User-Agent': 'Jambonz'
|
'User-Agent': 'Jambonz',
|
||||||
|
...(api_key && {'Ocp-Apim-Subscription-Key': api_key})
|
||||||
});
|
});
|
||||||
const mp3 = await post(custom_tts_endpoint_url, content);
|
const mp3 = await post(custom_tts_endpoint_url, content);
|
||||||
return mp3;
|
return mp3;
|
||||||
@@ -428,6 +463,7 @@ const synthMicrosoft = async(logger, {
|
|||||||
params += ',write_cache_file=1';
|
params += ',write_cache_file=1';
|
||||||
if (region) params += `,region=${region}`;
|
if (region) params += `,region=${region}`;
|
||||||
if (custom_tts_endpoint) params += `,endpointId=${custom_tts_endpoint}`;
|
if (custom_tts_endpoint) params += `,endpointId=${custom_tts_endpoint}`;
|
||||||
|
if (custom_tts_endpoint_url) params += `,endpoint=${custom_tts_endpoint_url}`;
|
||||||
if (process.env.JAMBONES_HTTP_PROXY_IP) params += `,http_proxy_ip=${process.env.JAMBONES_HTTP_PROXY_IP}`;
|
if (process.env.JAMBONES_HTTP_PROXY_IP) params += `,http_proxy_ip=${process.env.JAMBONES_HTTP_PROXY_IP}`;
|
||||||
if (process.env.JAMBONES_HTTP_PROXY_PORT) params += `,http_proxy_port=${process.env.JAMBONES_HTTP_PROXY_PORT}`;
|
if (process.env.JAMBONES_HTTP_PROXY_PORT) params += `,http_proxy_port=${process.env.JAMBONES_HTTP_PROXY_PORT}`;
|
||||||
params += '}';
|
params += '}';
|
||||||
@@ -748,6 +784,92 @@ const synthPlayHT = async(logger, {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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 (!process.env.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 synthWhisper = async(logger, {credentials, stats, voice, text, renderForCaching, disableTtsStreaming}) => {
|
||||||
const {api_key, model_id, baseURL, timeout, speed} = credentials;
|
const {api_key, model_id, baseURL, timeout, speed} = credentials;
|
||||||
/* if the env is set to stream then bag out, unless we are specifically rendering to generate a cache file */
|
/* if the env is set to stream then bag out, unless we are specifically rendering to generate a cache file */
|
||||||
|
|||||||
+8
-1
@@ -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 { HTTP_TIMEOUT } = require('./constants');
|
||||||
|
|
||||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||||
/**
|
/**
|
||||||
@@ -49,6 +49,12 @@ function makeAwsKey(awsAccessKeyId) {
|
|||||||
return `aws:${hash.digest('hex')}`;
|
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}`);
|
||||||
@@ -117,6 +123,7 @@ module.exports = {
|
|||||||
makeNuanceKey,
|
makeNuanceKey,
|
||||||
makeIbmKey,
|
makeIbmKey,
|
||||||
makeAwsKey,
|
makeAwsKey,
|
||||||
|
makeVerbioKey,
|
||||||
getNuanceAccessToken,
|
getNuanceAccessToken,
|
||||||
createNuanceClient,
|
createNuanceClient,
|
||||||
createKryptonClient,
|
createKryptonClient,
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.0.50",
|
"version": "0.1.1",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.0.50",
|
"version": "0.1.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-polly": "^3.496.0",
|
"@aws-sdk/client-polly": "^3.496.0",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.0.50",
|
"version": "0.1.1",
|
||||||
"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",
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
+97
-2
@@ -162,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);
|
||||||
@@ -581,14 +608,48 @@ test('PlayHT speech synth tests', async(t) => {
|
|||||||
text,
|
text,
|
||||||
renderForCaching: true
|
renderForCaching: true
|
||||||
});
|
});
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized eleven audio to ${opts.filePath}`);
|
t.ok(!opts.servedFromCache, `successfully playht eleven audio to ${opts.filePath}`);
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(JSON.stringify(err));
|
console.error(JSON.stringify(err));
|
||||||
t.end(err);
|
t.end(err);
|
||||||
}
|
}
|
||||||
client.quit();
|
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) => {
|
test('whisper speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
@@ -609,6 +670,40 @@ test('whisper speech synth tests', async(t) => {
|
|||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'alloy',
|
voice: 'alloy',
|
||||||
text,
|
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}`);
|
t.ok(!opts.servedFromCache, `successfully synthesized whisper audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user