mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-03 23:33:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -14,6 +14,9 @@ jobs:
|
|||||||
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 }}
|
||||||
@@ -29,3 +32,5 @@ 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 }}
|
||||||
|
JAMBONES_HTTP_PROXY_IP: 127.0.0.1
|
||||||
|
JAMBONES_HTTP_PROXY_PORT: 3128
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
# speech-utils
|
# speech-utils 
|
||||||
TTS-related speech utilities for jambonz.
|
TTS-related speech utilities for jambonz.
|
||||||
|
|
||||||
|
|||||||
@@ -2,18 +2,17 @@ const {noopLogger} = require('./lib/utils');
|
|||||||
|
|
||||||
module.exports = (opts, logger) => {
|
module.exports = (opts, logger) => {
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
let client = opts.redis_client;
|
|
||||||
const {
|
const {
|
||||||
client: redisClient,
|
client,
|
||||||
createHash,
|
createHash,
|
||||||
retrieveHash
|
retrieveHash
|
||||||
} = require('@jambonz/realtimedb-helpers')(opts, logger);
|
} = require('@jambonz/realtimedb-helpers')(opts, logger);
|
||||||
client = opts.redis_client || redisClient;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
client,
|
client,
|
||||||
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),
|
||||||
synthAudio: require('./lib/synth-audio').bind(null, client, logger),
|
synthAudio: require('./lib/synth-audio').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),
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
const fs = require('fs/promises');
|
||||||
|
const {noopLogger, makeSynthKey} = require('./utils');
|
||||||
|
const EXPIRES = (process.env.JAMBONES_TTS_CACHE_DURATION_MINS || 4 * 60) * 60; // cache tts for 4 hours
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -14,19 +14,20 @@ async function getAwsAuthToken(
|
|||||||
if (obj) return {...obj, servedFromCache: true};
|
if (obj) return {...obj, servedFromCache: true};
|
||||||
|
|
||||||
/* access token not found in cache, so generate it using STS */
|
/* access token not found in cache, so generate it using STS */
|
||||||
const stsClient = new STSClient({ region: awsRegion });
|
const stsClient = new STSClient({
|
||||||
const params = {
|
region: awsRegion,
|
||||||
accessKeyId: awsAccessKeyId,
|
credentials: {
|
||||||
secretAccessKey: awsSecretAccessKey,
|
accessKeyId: awsAccessKeyId,
|
||||||
DurationSeconds: EXPIRY
|
secretAccessKey: awsSecretAccessKey,
|
||||||
};
|
}
|
||||||
const command = new GetSessionTokenCommand(params);
|
});
|
||||||
|
const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
|
||||||
const data = await stsClient.send(command);
|
const 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
|
||||||
};
|
};
|
||||||
|
|
||||||
/* expire 10 minutes before the hour, so we don't lose the use of it during a call */
|
/* expire 10 minutes before the hour, so we don't lose the use of it during a call */
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ const getAwsVoices = async(_client, logger, credentials) => {
|
|||||||
secretAccessKey
|
secretAccessKey
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const command = new DescribeVoicesCommand({LanguageCode: 'en-US'});
|
const command = new DescribeVoicesCommand({});
|
||||||
const response = await client.send(command);
|
const response = await client.send(command);
|
||||||
return response;
|
return response;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
+219
-30
@@ -76,7 +76,8 @@ const trimTrailingSilence = (buffer) => {
|
|||||||
* 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, 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;
|
||||||
@@ -84,7 +85,7 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
|
|
||||||
assert.ok(['google', 'aws', 'polly', 'microsoft',
|
assert.ok(['google', 'aws', 'polly', 'microsoft',
|
||||||
'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs', 'whisper'].includes(vendor) ||
|
'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs', 'whisper', 'deepgram', 'playht'].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, not ${vendor}`);
|
||||||
if ('google' === vendor) {
|
if ('google' === vendor) {
|
||||||
@@ -122,6 +123,11 @@ 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) {
|
||||||
|
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 ('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');
|
||||||
@@ -140,8 +146,12 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
let filePath;
|
let filePath;
|
||||||
if (['nuance', 'nvidia'].includes(vendor) ||
|
if (['nuance', 'nvidia'].includes(vendor) ||
|
||||||
(
|
(
|
||||||
process.env.JAMBONES_TTS_TRIM_SILENCE &&
|
(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 &&
|
||||||
|
['elevenlabs', 'deepgram'].includes(vendor)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`;
|
filePath = `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt || ''}`)}.r8`;
|
||||||
@@ -178,7 +188,9 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
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});
|
||||||
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
break;
|
break;
|
||||||
case 'nuance':
|
case 'nuance':
|
||||||
model = model || 'enhanced';
|
model = model || 'enhanced';
|
||||||
@@ -194,10 +206,26 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|||||||
audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
|
audioBuffer = await synthWellSaid(logger, {credentials, stats, language, voice, text, filePath});
|
||||||
break;
|
break;
|
||||||
case 'elevenlabs':
|
case 'elevenlabs':
|
||||||
audioBuffer = await synthElevenlabs(logger, {credentials, stats, language, voice, text, filePath});
|
audioBuffer = await synthElevenlabs(logger, {
|
||||||
|
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming, filePath
|
||||||
|
});
|
||||||
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
|
break;
|
||||||
|
case 'playht':
|
||||||
|
audioBuffer = await synthPlayHT(logger, {
|
||||||
|
credentials, options, stats, language, voice, text, renderForCaching, disableTtsStreaming, filePath
|
||||||
|
});
|
||||||
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
break;
|
break;
|
||||||
case 'whisper':
|
case 'whisper':
|
||||||
audioBuffer = await synthWhisper(logger, {credentials, stats, voice, text});
|
audioBuffer = await synthWhisper(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});
|
||||||
|
if (audioBuffer?.filePath) return audioBuffer;
|
||||||
break;
|
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,
|
||||||
@@ -368,10 +396,47 @@ const synthMicrosoft = async(logger, {
|
|||||||
language,
|
language,
|
||||||
voice,
|
voice,
|
||||||
text,
|
text,
|
||||||
filePath
|
filePath,
|
||||||
|
renderForCaching,
|
||||||
|
disableTtsStreaming
|
||||||
}) => {
|
}) => {
|
||||||
try {
|
try {
|
||||||
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint, custom_tts_endpoint_url} = credentials;
|
const {api_key: apiKey, region, use_custom_tts, custom_tts_endpoint, custom_tts_endpoint_url} = credentials;
|
||||||
|
// let clean up the text
|
||||||
|
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');
|
||||||
|
}
|
||||||
|
if (!process.env.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 (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}`;
|
||||||
|
params += '}';
|
||||||
|
return {
|
||||||
|
filePath: `say:${params}${content.replace(/\n/g, ' ')}`,
|
||||||
|
servedFromCache: false,
|
||||||
|
rtt: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
if (use_custom_tts && custom_tts_endpoint_url) {
|
if (use_custom_tts && custom_tts_endpoint_url) {
|
||||||
return await _synthOnPremMicrosoft(logger, {
|
return await _synthOnPremMicrosoft(logger, {
|
||||||
credentials,
|
credentials,
|
||||||
@@ -383,32 +448,22 @@ const synthMicrosoft = async(logger, {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const trimSilence = filePath.endsWith('.r8');
|
const trimSilence = filePath.endsWith('.r8');
|
||||||
let content = text;
|
|
||||||
const speechConfig = SpeechConfig.fromSubscription(apiKey, region);
|
const speechConfig = SpeechConfig.fromSubscription(apiKey, region);
|
||||||
speechConfig.speechSynthesisLanguage = language;
|
speechConfig.speechSynthesisLanguage = language;
|
||||||
speechConfig.speechSynthesisVoiceName = voice;
|
speechConfig.speechSynthesisVoiceName = voice;
|
||||||
if (use_custom_tts && custom_tts_endpoint) {
|
if (use_custom_tts && custom_tts_endpoint) {
|
||||||
speechConfig.endpointId = custom_tts_endpoint;
|
speechConfig.endpointId = custom_tts_endpoint;
|
||||||
}
|
}
|
||||||
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>`;
|
|
||||||
}
|
|
||||||
speechConfig.speechSynthesisOutputFormat = trimSilence ?
|
speechConfig.speechSynthesisOutputFormat = trimSilence ?
|
||||||
SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm :
|
SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm :
|
||||||
SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3;
|
SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3;
|
||||||
const synthesizer = new SpeechSynthesizer(speechConfig);
|
|
||||||
|
|
||||||
if (content.startsWith('<speak>')) {
|
if (process.env.JAMBONES_HTTP_PROXY_IP && process.env.JAMBONES_HTTP_PROXY_PORT) {
|
||||||
/* microsoft enforces some properties and uses voice xml element so if the user did not supply do it for them */
|
logger.debug(
|
||||||
const words = content.slice(7, -8).trim().replace(/(\r\n|\n|\r)/gm, ' ');
|
`synthMicrosoft: using proxy ${process.env.JAMBONES_HTTP_PROXY_IP}:${process.env.JAMBONES_HTTP_PROXY_PORT}`);
|
||||||
// eslint-disable-next-line max-len
|
speechConfig.setProxy(process.env.JAMBONES_HTTP_PROXY_IP, process.env.JAMBONES_HTTP_PROXY_PORT);
|
||||||
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');
|
|
||||||
}
|
}
|
||||||
|
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') ?
|
||||||
@@ -585,21 +640,50 @@ const synthCustomVendor = async(logger, {credentials, stats, language, voice, te
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const synthElevenlabs = async(logger, {credentials, stats, language, voice, text}) => {
|
const synthElevenlabs = async(logger, {
|
||||||
const {api_key, model_id} = credentials;
|
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 += ',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 {
|
try {
|
||||||
const post = bent('https://api.elevenlabs.io', 'POST', 'buffer', {
|
const post = bent('https://api.elevenlabs.io', 'POST', 'buffer', {
|
||||||
'xi-api-key': api_key,
|
'xi-api-key': api_key,
|
||||||
'Accept': 'audio/mpeg',
|
'Accept': 'audio/mpeg',
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
});
|
});
|
||||||
const mp3 = await post(`/v1/text-to-speech/${voice}`, {
|
const mp3 = await post(`/v1/text-to-speech/${voice}${optimize_streaming_latency}`, {
|
||||||
text,
|
text,
|
||||||
model_id,
|
model_id,
|
||||||
voice_settings: {
|
voice_settings: {
|
||||||
stability: 0.5,
|
stability: 0.5,
|
||||||
similarity_boost: 0.5
|
similarity_boost: 0.5
|
||||||
}
|
},
|
||||||
|
...opts
|
||||||
});
|
});
|
||||||
return mp3;
|
return mp3;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -609,8 +693,80 @@ const synthElevenlabs = async(logger, {credentials, stats, language, voice, text
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const synthWhisper = async(logger, {credentials, stats, voice, text}) => {
|
const synthPlayHT = async(logger, {
|
||||||
const {api_key, model_id, baseURL, timeout} = credentials;
|
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 (!process.env.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 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 (!process.env.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 {
|
try {
|
||||||
const openai = new OpenAI.OpenAI({
|
const openai = new OpenAI.OpenAI({
|
||||||
apiKey: api_key,
|
apiKey: api_key,
|
||||||
@@ -630,8 +786,41 @@ const synthWhisper = async(logger, {credentials, stats, voice, text}) => {
|
|||||||
stats.increment('tts.count', ['vendor:openai', 'accepted:no']);
|
stats.increment('tts.count', ['vendor:openai', 'accepted:no']);
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
;
|
|
||||||
|
const synthDeepgram = async(logger, {credentials, stats, model, text, renderForCaching, disableTtsStreaming}) => {
|
||||||
|
const {api_key} = credentials;
|
||||||
|
if (!process.env.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':
|
||||||
|
|||||||
Generated
+1682
-2147
File diff suppressed because it is too large
Load Diff
+13
-13
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "0.0.27",
|
"version": "0.0.50",
|
||||||
"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",
|
||||||
@@ -24,26 +24,26 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/jambonz/speech-utils#readme",
|
"homepage": "https://github.com/jambonz/speech-utils#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-polly": "^3.359.0",
|
"@aws-sdk/client-polly": "^3.496.0",
|
||||||
"@aws-sdk/client-sts": "^3.458.0",
|
"@aws-sdk/client-sts": "^3.496.0",
|
||||||
"@google-cloud/text-to-speech": "^4.2.1",
|
"@google-cloud/text-to-speech": "^5.0.2",
|
||||||
"@grpc/grpc-js": "^1.8.13",
|
"@grpc/grpc-js": "^1.9.14",
|
||||||
"@jambonz/realtimedb-helpers": "^0.8.7",
|
"@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.0",
|
"form-urlencoded": "^6.1.4",
|
||||||
"google-protobuf": "^3.21.2",
|
"google-protobuf": "^3.21.2",
|
||||||
"ibm-watson": "^8.0.0",
|
"ibm-watson": "^8.0.0",
|
||||||
"microsoft-cognitiveservices-speech-sdk": "1.32.0",
|
"microsoft-cognitiveservices-speech-sdk": "1.36.0",
|
||||||
"openai": "^4.16.2",
|
"openai": "^4.25.0",
|
||||||
"undici": "^5.21.0"
|
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -21,12 +21,12 @@ test('AWS - create and cache auth token', async(t) => {
|
|||||||
try {
|
try {
|
||||||
let obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
|
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');
|
//console.log({obj}, 'received auth token from AWS');
|
||||||
t.ok(obj.sessionToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
|
t.ok(obj.securityToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
|
||||||
|
|
||||||
await sleep(250);
|
await sleep(250);
|
||||||
obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
|
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');
|
//console.log({obj}, 'received auth token from AWS - second request');
|
||||||
t.ok(obj.sessionToken && obj.servedFromCache, 'successfully received access token from cache');
|
t.ok(obj.securityToken && obj.servedFromCache, 'successfully received access token from cache');
|
||||||
|
|
||||||
await client.flushall();
|
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
|
||||||
+147
-3
@@ -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');
|
||||||
@@ -58,6 +58,14 @@ test('Google speech synth tests', async(t) => {
|
|||||||
});
|
});
|
||||||
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: {
|
||||||
@@ -180,9 +188,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',
|
||||||
@@ -193,6 +204,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) {
|
||||||
@@ -202,6 +214,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);
|
||||||
@@ -223,6 +287,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}`);
|
||||||
|
|
||||||
@@ -237,6 +302,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) {
|
||||||
@@ -459,7 +525,16 @@ test('Elevenlabs speech synth tests', async(t) => {
|
|||||||
vendor: 'elevenlabs',
|
vendor: 'elevenlabs',
|
||||||
credentials: {
|
credentials: {
|
||||||
api_key: process.env.ELEVENLABS_API_KEY,
|
api_key: process.env.ELEVENLABS_API_KEY,
|
||||||
model_id: process.env.ELEVENLABS_MODEL_ID
|
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',
|
language: 'en-US',
|
||||||
voice: process.env.ELEVENLABS_VOICE_ID,
|
voice: process.env.ELEVENLABS_VOICE_ID,
|
||||||
@@ -474,6 +549,47 @@ test('Elevenlabs speech synth tests', async(t) => {
|
|||||||
client.quit();
|
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 synthesized eleven 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('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -503,6 +619,34 @@ test('whisper speech synth tests', async(t) => {
|
|||||||
client.quit();
|
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, getTtsSize, client} = fn(opts, logger);
|
const {purgeTtsCache, getTtsSize, client} = fn(opts, logger);
|
||||||
|
|||||||
Reference in New Issue
Block a user