mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-03 23:33:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5dc26c916d | ||
|
|
12e3364461 | ||
|
|
6c67f6faa0 | ||
|
|
18917f49ff | ||
|
|
fa705694e1 | ||
|
|
89fe0b87e9 | ||
|
|
b928820906 | ||
|
|
f4c3c7dc8b | ||
|
|
a32f71ac5a | ||
|
|
c8850998b5 | ||
|
|
e8b2009d29 | ||
|
|
27e07bb551 | ||
|
|
33456b93d9 | ||
|
|
70e91b5057 | ||
|
|
c066840f85 | ||
|
|
d89457f67d | ||
|
|
3c15976669 | ||
|
|
70abb04941 | ||
|
|
724af7fcab | ||
|
|
c0a79090c2 | ||
|
|
7a9a3e2468 | ||
|
|
ab2b3f7fb2 | ||
|
|
e848d0276e | ||
|
|
d2447d477d | ||
|
|
ec8bbacc2c | ||
|
|
9694714a7f | ||
|
|
6a6de9b7a1 | ||
|
|
04d1fb548b | ||
|
|
bbf0167b40 | ||
|
|
4cfa286242 | ||
|
|
42ac63adc6 | ||
|
|
12a121672d | ||
|
|
7b94a5a969 | ||
|
|
c47b4883c7 | ||
|
|
7d076bb8b4 | ||
|
|
142323a151 |
@@ -7,11 +7,18 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
id-token: write # required to request the GitHub OIDC token for AWS
|
||||||
|
contents: read
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v4
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
node-version: '20'
|
||||||
|
- uses: aws-actions/configure-aws-credentials@v4
|
||||||
|
with:
|
||||||
|
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
|
||||||
|
aws-region: us-east-1
|
||||||
- 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 apt update && sudo apt install -y squid
|
||||||
@@ -19,10 +26,12 @@ jobs:
|
|||||||
- run: sudo systemctl start squid
|
- run: sudo systemctl start squid
|
||||||
- run: npm test
|
- run: npm test
|
||||||
env:
|
env:
|
||||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
# AWS_* are exported by configure-aws-credentials above as short-lived
|
||||||
AWS_REGION: ${{ secrets.AWS_REGION }}
|
# OIDC credentials; no AWS keys are stored as repository secrets.
|
||||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
|
||||||
GCP_JSON_KEY: ${{ secrets.GCP_JSON_KEY }}
|
GCP_JSON_KEY: ${{ secrets.GCP_JSON_KEY }}
|
||||||
|
# Enables the "AWS speech synth tests by RoleArn" test, which exercises the
|
||||||
|
# AssumeRole credential path used in production.
|
||||||
|
AWS_ROLE_ARN: ${{ secrets.AWS_ROLE_ARN }}
|
||||||
|
|
||||||
MICROSOFT_API_KEY: ${{ secrets.MICROSOFT_API_KEY }}
|
MICROSOFT_API_KEY: ${{ secrets.MICROSOFT_API_KEY }}
|
||||||
MICROSOFT_REGION: ${{ secrets.MICROSOFT_REGION }}
|
MICROSOFT_REGION: ${{ secrets.MICROSOFT_REGION }}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
# CLAUDE.md
|
||||||
|
|
||||||
|
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
`@jambonz/speech-utils` is a Node.js library providing TTS (Text-to-Speech) utilities for the jambonz CPaaS platform. It handles speech synthesis with caching through Redis and supports multiple TTS vendors.
|
||||||
|
|
||||||
|
## Commands
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Run tests (requires Docker for Redis)
|
||||||
|
npm test
|
||||||
|
|
||||||
|
# Run linter
|
||||||
|
npm run jslint
|
||||||
|
|
||||||
|
# Auto-fix lint issues
|
||||||
|
npm run jslint:fix
|
||||||
|
|
||||||
|
# Generate coverage report
|
||||||
|
npm run coverage
|
||||||
|
```
|
||||||
|
|
||||||
|
## Testing
|
||||||
|
|
||||||
|
Tests use `tape` and require Redis. The test harness automatically starts/stops Redis via Docker Compose (`test/docker-compose-testbed.yaml`).
|
||||||
|
|
||||||
|
Most tests are conditional based on environment variables for vendor credentials:
|
||||||
|
- `GCP_FILE` or `GCP_JSON_KEY` - Google TTS
|
||||||
|
- `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AWS_REGION` - AWS Polly
|
||||||
|
- `MICROSOFT_API_KEY`, `MICROSOFT_REGION` - Azure TTS
|
||||||
|
- `ELEVENLABS_API_KEY`, `ELEVENLABS_VOICE_ID`, `ELEVENLABS_MODEL_ID` - ElevenLabs
|
||||||
|
- `OPENAI_API_KEY` - OpenAI Whisper TTS
|
||||||
|
- And others per vendor
|
||||||
|
|
||||||
|
Redis config is in `config/test.json` (port 3379).
|
||||||
|
|
||||||
|
## Architecture
|
||||||
|
|
||||||
|
### Entry Point
|
||||||
|
|
||||||
|
`index.js` exports a factory function that takes Redis options and a logger, returning an object with these methods:
|
||||||
|
- `synthAudio` - Main synthesis function
|
||||||
|
- `getTtsVoices` - List available voices for a vendor
|
||||||
|
- `purgeTtsCache` / `getTtsSize` / `addFileToCache` - Cache management
|
||||||
|
- `getAwsAuthToken` - Token management
|
||||||
|
|
||||||
|
### Core Module: `lib/synth-audio.js`
|
||||||
|
|
||||||
|
The `synthAudio` function handles synthesis for all vendors. Key behaviors:
|
||||||
|
1. **Cache check**: Generates SHA1 hash key from (vendor, language, voice, engine, model, text, instructions)
|
||||||
|
2. **Streaming vs non-streaming**: When `JAMBONES_DISABLE_TTS_STREAMING` is not set and `renderForCaching=false`, returns `say:{params}text` format for FreeSWITCH streaming playback instead of generating files
|
||||||
|
3. **Vendor dispatch**: Switch statement routes to vendor-specific synth functions (`synthGoogle`, `synthPolly`, `synthMicrosoft`, etc.)
|
||||||
|
4. **Caching**: Stores audio as base64 JSON in Redis with configurable TTL (default 4 hours)
|
||||||
|
|
||||||
|
### Supported Vendors
|
||||||
|
|
||||||
|
google, aws/polly, microsoft/azure, nvidia (Riva), wellsaid, elevenlabs, cartesia, inworld, rimelabs, whisper (OpenAI), deepgram, resemble, custom:*
|
||||||
|
|
||||||
|
### gRPC Stubs
|
||||||
|
|
||||||
|
`stubs/riva/` contains generated protobuf/gRPC code for NVIDIA Riva.
|
||||||
|
|
||||||
|
## Environment Variables
|
||||||
|
|
||||||
|
Key configuration via env vars (see `lib/config.js`):
|
||||||
|
- `JAMBONES_DISABLE_TTS_STREAMING` - Force non-streaming mode
|
||||||
|
- `JAMBONES_DISABLE_AZURE_TTS_STREAMING` - Azure-specific streaming disable
|
||||||
|
- `JAMBONES_TTS_CACHE_DURATION_MINS` - Cache TTL in minutes (default: 240)
|
||||||
|
- `JAMBONES_TTS_TRIM_SILENCE` - Trim trailing silence from audio
|
||||||
|
- `JAMBONES_TMP_FOLDER` - Temp folder for audio files (default: /tmp)
|
||||||
|
- `JAMBONES_HTTP_PROXY_IP`, `JAMBONES_HTTP_PROXY_PORT` - HTTP proxy for Azure
|
||||||
|
- `JAMBONES_AZURE_ENABLE_SSML` - Force SSML wrapper for Azure plain text
|
||||||
|
|
||||||
|
## Key Dependencies
|
||||||
|
|
||||||
|
- `@jambonz/realtimedb-helpers` - Redis client and hash utilities
|
||||||
|
- `@google-cloud/text-to-speech` - Google TTS
|
||||||
|
- `@aws-sdk/client-polly` - AWS Polly
|
||||||
|
- `microsoft-cognitiveservices-speech-sdk` - Azure TTS
|
||||||
|
- `@grpc/grpc-js` - gRPC for Riva
|
||||||
|
- `openai` - OpenAI Whisper TTS
|
||||||
|
- `bent` - HTTP client for REST-based vendors
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
mkdir -p stubs/nuance
|
|
||||||
|
|
||||||
for FILE in ./protos/nuance/*; do
|
|
||||||
grpc_tools_node_protoc \
|
|
||||||
--js_out=import_style=commonjs,binary:./stubs/nuance \
|
|
||||||
--grpc_out=grpc_js:./stubs/nuance \
|
|
||||||
--proto_path=./protos/nuance \
|
|
||||||
$FILE
|
|
||||||
done
|
|
||||||
@@ -14,8 +14,6 @@ module.exports = (opts, 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, createHash, retrieveHash, 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),
|
|
||||||
|
|
||||||
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, createHash, retrieveHash, logger),
|
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, createHash, retrieveHash, logger),
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
const formurlencoded = require('form-urlencoded');
|
|
||||||
const {Pool} = require('undici');
|
|
||||||
const pool = new Pool('https://auth.crt.nuance.com');
|
|
||||||
const {makeNuanceKey, makeBasicAuthHeader, noopLogger} = require('./utils');
|
|
||||||
const { HTTP_TIMEOUT } = require('./config');
|
|
||||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
|
||||||
|
|
||||||
async function getNuanceAccessToken(client, logger, clientId, secret, scope) {
|
|
||||||
logger = logger || noopLogger;
|
|
||||||
try {
|
|
||||||
const key = makeNuanceKey(clientId, secret, scope);
|
|
||||||
const access_token = await client.get(key);
|
|
||||||
if (access_token) return {access_token, servedFromCache: true};
|
|
||||||
|
|
||||||
/* access token not found in cache, so fetch it from Nuance */
|
|
||||||
const payload = {
|
|
||||||
grant_type: 'client_credentials',
|
|
||||||
scope
|
|
||||||
};
|
|
||||||
const auth = makeBasicAuthHeader(clientId, secret);
|
|
||||||
const {statusCode, headers, body} = await pool.request({
|
|
||||||
path: '/oauth2/token',
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
...auth,
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
|
||||||
},
|
|
||||||
body: formurlencoded(payload),
|
|
||||||
timeout: HTTP_TIMEOUT,
|
|
||||||
followRedirects: false
|
|
||||||
});
|
|
||||||
|
|
||||||
if (200 !== statusCode) {
|
|
||||||
logger.debug({statusCode, headers, body: body.text()}, 'error fetching access token from Nuance');
|
|
||||||
const err = new Error();
|
|
||||||
err.statusCode = statusCode;
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
const json = await body.json();
|
|
||||||
await client.set(key, json.access_token, 'EX', json.expires_in - 30);
|
|
||||||
return {...json, servedFromCache: false};
|
|
||||||
} catch (err) {
|
|
||||||
debug(err, `getNuanceAccessToken: Error retrieving Nuance access token for client_id ${clientId}`);
|
|
||||||
logger.error(err, `getNuanceAccessToken: Error retrieving Nuance access token for client_id ${clientId}`);
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = getNuanceAccessToken;
|
|
||||||
+2
-92
@@ -1,74 +1,8 @@
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const {noopLogger, createNuanceClient, createKryptonClient} = require('./utils');
|
const {noopLogger} = require('./utils');
|
||||||
const getNuanceAccessToken = require('./get-nuance-access-token');
|
|
||||||
const getVerbioAccessToken = require('./get-verbio-token');
|
|
||||||
const {GetVoicesRequest, Voice} = require('../stubs/nuance/synthesizer_pb');
|
|
||||||
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 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 getNuanceVoices = async(client, logger, credentials) => {
|
|
||||||
const {client_id: clientId, secret: secret, nuance_tts_uri} = credentials;
|
|
||||||
|
|
||||||
return new Promise(async(resolve, reject) => {
|
|
||||||
/* get a nuance access token */
|
|
||||||
let token, nuanceClient;
|
|
||||||
try {
|
|
||||||
if (nuance_tts_uri) {
|
|
||||||
nuanceClient = await createKryptonClient(nuance_tts_uri);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
const access_token = await getNuanceAccessToken(client, logger, clientId, secret, 'tts');
|
|
||||||
token = access_token.access_token;
|
|
||||||
nuanceClient = await createNuanceClient(token);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
logger.error({err}, 'getTtsVoices: error retrieving access token');
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
/* retrieve all voices */
|
|
||||||
const v = new Voice();
|
|
||||||
const request = new GetVoicesRequest();
|
|
||||||
request.setVoice(v);
|
|
||||||
|
|
||||||
nuanceClient.getVoices(request, (err, response) => {
|
|
||||||
if (err) {
|
|
||||||
logger.error({err, clientId, secret, token}, 'getTtsVoices: error retrieving voices');
|
|
||||||
return reject(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* return all the voices that are not restricted and eliminate duplicates */
|
|
||||||
const voices = response.getVoicesList()
|
|
||||||
.map((v) => {
|
|
||||||
return {
|
|
||||||
language: v.getLanguage(),
|
|
||||||
name: v.getName(),
|
|
||||||
model: v.getModel(),
|
|
||||||
gender: v.getGender() === 1 ? 'male' : 'female',
|
|
||||||
restricted: v.getRestricted()
|
|
||||||
};
|
|
||||||
});
|
|
||||||
const v = voices
|
|
||||||
.filter((v) => v.restricted === false)
|
|
||||||
.map((v) => {
|
|
||||||
delete v.restricted;
|
|
||||||
return v;
|
|
||||||
})
|
|
||||||
.sort((a, b) => {
|
|
||||||
if (a.language < b.language) return -1;
|
|
||||||
if (a.language > b.language) return 1;
|
|
||||||
if (a.name < b.name) return -1;
|
|
||||||
return 1;
|
|
||||||
});
|
|
||||||
const arr = [...new Set(v.map((v) => JSON.stringify(v)))]
|
|
||||||
.map((v) => JSON.parse(v));
|
|
||||||
resolve(arr);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const getGoogleVoices = async(_client, logger, credentials) => {
|
const getGoogleVoices = async(_client, logger, credentials) => {
|
||||||
const client = new ttsGoogle.TextToSpeechClient({credentials});
|
const client = new ttsGoogle.TextToSpeechClient({credentials});
|
||||||
@@ -109,26 +43,6 @@ const getAwsVoices = async(_client, createHash, retrieveHash, logger, credential
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
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
|
||||||
@@ -148,19 +62,15 @@ const getVerbioVoices = async(client, logger, credentials) => {
|
|||||||
async function getTtsVoices(client, createHash, retrieveHash, logger, {vendor, credentials}) {
|
async function getTtsVoices(client, createHash, retrieveHash, logger, {vendor, credentials}) {
|
||||||
logger = logger || noopLogger;
|
logger = logger || noopLogger;
|
||||||
|
|
||||||
assert.ok(['nuance', 'google', 'aws', 'polly', 'verbio'].includes(vendor),
|
assert.ok(['google', 'aws', 'polly'].includes(vendor),
|
||||||
`getTtsVoices not supported for vendor ${vendor}`);
|
`getTtsVoices not supported for vendor ${vendor}`);
|
||||||
|
|
||||||
switch (vendor) {
|
switch (vendor) {
|
||||||
case 'nuance':
|
|
||||||
return getNuanceVoices(client, logger, credentials);
|
|
||||||
case 'google':
|
case 'google':
|
||||||
return getGoogleVoices(client, logger, credentials);
|
return getGoogleVoices(client, logger, credentials);
|
||||||
case 'aws':
|
case 'aws':
|
||||||
case 'polly':
|
case 'polly':
|
||||||
return getAwsVoices(client, createHash, retrieveHash, logger, credentials);
|
return getAwsVoices(client, createHash, retrieveHash, logger, credentials);
|
||||||
case 'verbio':
|
|
||||||
return getVerbioVoices(client, logger, credentials);
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
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;
|
|
||||||
+616
-234
File diff suppressed because it is too large
Load Diff
+1
-101
@@ -1,20 +1,7 @@
|
|||||||
const crypto = require('crypto');
|
const crypto = require('crypto');
|
||||||
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 = new Pool('https://auth.crt.nuance.com');
|
|
||||||
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 { TMP_FOLDER } = require('./config');
|
||||||
const { TMP_FOLDER, HTTP_TIMEOUT } = require('./config');
|
|
||||||
|
|
||||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
|
||||||
/**
|
|
||||||
* Future TODO: cache recently used connections to providers
|
|
||||||
* to avoid connection overhead during a call.
|
|
||||||
* Will need to periodically age them out to avoid memory leaks.
|
|
||||||
*/
|
|
||||||
//const nuanceClientMap = new Map();
|
|
||||||
|
|
||||||
function makeSynthKey({
|
function makeSynthKey({
|
||||||
account_sid = '',
|
account_sid = '',
|
||||||
@@ -45,90 +32,12 @@ const noopLogger = {
|
|||||||
error: () => {}
|
error: () => {}
|
||||||
};
|
};
|
||||||
|
|
||||||
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
|
|
||||||
|
|
||||||
function makeBasicAuthHeader(username, password) {
|
|
||||||
if (!username || !password) return {};
|
|
||||||
const creds = `${encodeURIComponent(username)}:${password || ''}`;
|
|
||||||
const header = `Basic ${toBase64(creds)}`;
|
|
||||||
return {Authorization: header};
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeAwsKey(awsAccessKeyId) {
|
function makeAwsKey(awsAccessKeyId) {
|
||||||
const hash = crypto.createHash('sha1');
|
const hash = crypto.createHash('sha1');
|
||||||
hash.update(awsAccessKeyId);
|
hash.update(awsAccessKeyId);
|
||||||
return `aws:${hash.digest('hex')}`;
|
return `aws:${hash.digest('hex')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function makePlayhtKey(apiKey) {
|
|
||||||
const hash = crypto.createHash('sha1');
|
|
||||||
hash.update(apiKey);
|
|
||||||
return `playht:${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) {
|
|
||||||
const hash = crypto.createHash('sha1');
|
|
||||||
hash.update(`${clientId}:${secret}:${scope}`);
|
|
||||||
return `nuance:${hash.digest('hex')}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const getNuanceAccessToken = async(clientId, secret, scope = 'asr tts') => {
|
|
||||||
const payload = {
|
|
||||||
grant_type: 'client_credentials',
|
|
||||||
scope
|
|
||||||
};
|
|
||||||
const auth = makeBasicAuthHeader(clientId, secret);
|
|
||||||
const {statusCode, headers, body} = await pool.request({
|
|
||||||
path: '/oauth2/token',
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
...auth,
|
|
||||||
'Content-Type': 'application/x-www-form-urlencoded'
|
|
||||||
},
|
|
||||||
body: formurlencoded(payload),
|
|
||||||
timeout: HTTP_TIMEOUT,
|
|
||||||
followRedirects: false
|
|
||||||
});
|
|
||||||
|
|
||||||
if (200 !== statusCode) {
|
|
||||||
debug({statusCode, headers, body: body.text()}, 'error fetching access token from Nuance');
|
|
||||||
const err = new Error();
|
|
||||||
err.statusCode = statusCode;
|
|
||||||
throw err;
|
|
||||||
}
|
|
||||||
const json = await body.json();
|
|
||||||
return json.access_token;
|
|
||||||
};
|
|
||||||
|
|
||||||
const createKryptonClient = async(uri) => {
|
|
||||||
const client = new SynthesizerClient(uri, grpc.credentials.createInsecure());
|
|
||||||
return client;
|
|
||||||
};
|
|
||||||
|
|
||||||
const createNuanceClient = async(access_token) => {
|
|
||||||
|
|
||||||
//if (nuanceClientMap.has(access_token)) return nuanceClientMap.get(access_token);
|
|
||||||
|
|
||||||
const generateMetadata = (params, callback) => {
|
|
||||||
var metadata = new grpc.Metadata();
|
|
||||||
metadata.add('authorization', `Bearer ${access_token}`);
|
|
||||||
callback(null, metadata);
|
|
||||||
};
|
|
||||||
|
|
||||||
const sslCreds = grpc.credentials.createSsl();
|
|
||||||
const authCreds = grpc.credentials.createFromMetadataGenerator(generateMetadata);
|
|
||||||
const combined_creds = grpc.credentials.combineChannelCredentials(sslCreds, authCreds);
|
|
||||||
const client = new SynthesizerClient(NUANCE_AUTH_ENDPOINT, combined_creds);
|
|
||||||
|
|
||||||
//if (process.env.NUANCE_CACHE_TTS_CONNECTIONS) nuanceClientMap.set(access_token, client);
|
|
||||||
return client;
|
|
||||||
};
|
|
||||||
|
|
||||||
const createRivaClient = async(rivaUri) => {
|
const createRivaClient = async(rivaUri) => {
|
||||||
const client = new RivaSpeechSynthesisClient(rivaUri, grpc.credentials.createInsecure());
|
const client = new RivaSpeechSynthesisClient(rivaUri, grpc.credentials.createInsecure());
|
||||||
return client;
|
return client;
|
||||||
@@ -136,17 +45,8 @@ const createRivaClient = async(rivaUri) => {
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
makeSynthKey,
|
makeSynthKey,
|
||||||
makeNuanceKey,
|
|
||||||
|
|
||||||
makePlayhtKey,
|
|
||||||
makeAwsKey,
|
makeAwsKey,
|
||||||
makeVerbioKey,
|
|
||||||
getNuanceAccessToken,
|
|
||||||
createNuanceClient,
|
|
||||||
createKryptonClient,
|
|
||||||
createRivaClient,
|
createRivaClient,
|
||||||
makeBasicAuthHeader,
|
|
||||||
NUANCE_AUTH_ENDPOINT,
|
|
||||||
noopLogger,
|
noopLogger,
|
||||||
makeFilePath
|
makeFilePath
|
||||||
};
|
};
|
||||||
|
|||||||
Generated
+115
-85
@@ -1,15 +1,14 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "1.0.4",
|
"version": "1.0.21",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "1.0.4",
|
"version": "1.0.21",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"23": "^0.0.0",
|
|
||||||
"@aws-sdk/client-polly": "^3.496.0",
|
"@aws-sdk/client-polly": "^3.496.0",
|
||||||
"@aws-sdk/client-sts": "^3.496.0",
|
"@aws-sdk/client-sts": "^3.496.0",
|
||||||
"@cartesia/cartesia-js": "^2.2.7",
|
"@cartesia/cartesia-js": "^2.2.7",
|
||||||
@@ -18,11 +17,9 @@
|
|||||||
"@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.4",
|
|
||||||
"google-protobuf": "^3.21.2",
|
"google-protobuf": "^3.21.2",
|
||||||
"microsoft-cognitiveservices-speech-sdk": "1.38.0",
|
"microsoft-cognitiveservices-speech-sdk": "^1.51.0",
|
||||||
"openai": "^4.98.0",
|
"openai": "^4.98.0"
|
||||||
"undici": "^7.5.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"config": "^4.2.0",
|
"config": "^4.2.0",
|
||||||
@@ -761,6 +758,46 @@
|
|||||||
"node": ">=18.0.0"
|
"node": ">=18.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@azure/abort-controller": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.2.0.tgz",
|
||||||
|
"integrity": "sha512-fNAjWnA/nZ2jz31kxR/AqRaUT8ewHBw/WuBIosK0moMy1C9e5ValbDfFdIxJzVOOYaYkV/b2F1S4H/aHiqfVQg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@azure/core-auth": {
|
||||||
|
"version": "1.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@azure/core-auth/-/core-auth-1.11.0.tgz",
|
||||||
|
"integrity": "sha512-IUZydyTUkDnYdstOW9pFOOUQlBjAepK5teihDE3x6yxsPJs/hsAaaYpeGxdxrgtOiJbBKSjKW7MDk7AEhb4LRg==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@azure/abort-controller": "^2.1.2",
|
||||||
|
"@azure/core-util": "^1.13.0",
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@azure/core-util": {
|
||||||
|
"version": "1.14.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@azure/core-util/-/core-util-1.14.0.tgz",
|
||||||
|
"integrity": "sha512-9n2pWK61veAuN0V20t9lOuoV4CFMdyAZ1ygZzvBGk/pBBJRib/PjL9PLXa/aI2CcPpyHfqVsxxqLCYl6uZlfDw==",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@azure/abort-controller": "^2.1.2",
|
||||||
|
"@typespec/ts-http-runtime": "^0.3.0",
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@babel/code-frame": {
|
"node_modules/@babel/code-frame": {
|
||||||
"version": "7.26.2",
|
"version": "7.26.2",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz",
|
||||||
@@ -2392,11 +2429,19 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@types/webrtc/-/webrtc-0.0.37.tgz",
|
"resolved": "https://registry.npmjs.org/@types/webrtc/-/webrtc-0.0.37.tgz",
|
||||||
"integrity": "sha512-JGAJC/ZZDhcrrmepU4sPLQLIOIAgs5oIK+Ieq90K8fdaNMhfdfqmYatJdgif1NDQtvrSlTOGJDUYHIDunuufOg=="
|
"integrity": "sha512-JGAJC/ZZDhcrrmepU4sPLQLIOIAgs5oIK+Ieq90K8fdaNMhfdfqmYatJdgif1NDQtvrSlTOGJDUYHIDunuufOg=="
|
||||||
},
|
},
|
||||||
"node_modules/23": {
|
"node_modules/@typespec/ts-http-runtime": {
|
||||||
"version": "0.0.0",
|
"version": "0.3.8",
|
||||||
"resolved": "https://registry.npmjs.org/23/-/23-0.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@typespec/ts-http-runtime/-/ts-http-runtime-0.3.8.tgz",
|
||||||
"integrity": "sha512-uAETf9Okr72trtp1pNXYKhFCTTI1EKGcYMA8gw3jLGhlbaDX+grrNToEWrpt8luxRAvrZWBTvyB5wk3PpNjGQQ==",
|
"integrity": "sha512-bLMpVcWZNzq6lYOybwFwOAR1IXKcHnhUNqYeHjl1bET/qE3jFPFH+p8Wrh3rU4xwdnifPxmKNESBYnvnmc75aA==",
|
||||||
"license": "ISC"
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"http-proxy-agent": "^7.0.0",
|
||||||
|
"https-proxy-agent": "^7.0.0",
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=22.0.0"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"node_modules/abort-controller": {
|
"node_modules/abort-controller": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
@@ -3747,11 +3792,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz",
|
||||||
"integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A=="
|
"integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A=="
|
||||||
},
|
},
|
||||||
"node_modules/form-urlencoded": {
|
|
||||||
"version": "6.1.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/form-urlencoded/-/form-urlencoded-6.1.4.tgz",
|
|
||||||
"integrity": "sha512-vDFWgogZ04th20oxQtDSF8CDjrBgAPtP1V+W3kZni5IZqyasDDVNqCQGOXfYlmOJj0zpROgiAtPJXCmidtxDTQ=="
|
|
||||||
},
|
|
||||||
"node_modules/formdata-node": {
|
"node_modules/formdata-node": {
|
||||||
"version": "4.4.1",
|
"version": "4.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz",
|
||||||
@@ -5284,17 +5324,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/microsoft-cognitiveservices-speech-sdk": {
|
"node_modules/microsoft-cognitiveservices-speech-sdk": {
|
||||||
"version": "1.38.0",
|
"version": "1.51.0",
|
||||||
"resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.38.0.tgz",
|
"resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.51.0.tgz",
|
||||||
"integrity": "sha512-NA6J4eIDkeR9iN83rcn77Kn5AWQcizDEn1tLMjzRvSovUNB1FrZe0mWYO0fsGltUwMl3Ns5OZ3lGw42PU4fEYA==",
|
"integrity": "sha512-BLLovv5PegOr5Lp52h4CSgL2c/ViFAh9LoU49ILNPyb/Z0giGI7nPV3xNLcmTtHLT+kfYNRGUIA62vORLzP8TA==",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@azure/core-auth": "^1.9.0",
|
||||||
"@types/webrtc": "^0.0.37",
|
"@types/webrtc": "^0.0.37",
|
||||||
"agent-base": "^6.0.1",
|
"agent-base": "^6.0.1",
|
||||||
"bent": "^7.3.12",
|
"bent": "^7.3.12",
|
||||||
"https-proxy-agent": "^4.0.0",
|
"https-proxy-agent": "^4.0.0",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^11.1.1",
|
||||||
"ws": "^7.5.6"
|
"ws": "^8.21.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/microsoft-cognitiveservices-speech-sdk/node_modules/https-proxy-agent": {
|
"node_modules/microsoft-cognitiveservices-speech-sdk/node_modules/https-proxy-agent": {
|
||||||
@@ -5318,36 +5359,16 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/microsoft-cognitiveservices-speech-sdk/node_modules/uuid": {
|
"node_modules/microsoft-cognitiveservices-speech-sdk/node_modules/uuid": {
|
||||||
"version": "9.0.1",
|
"version": "11.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz",
|
||||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
|
"integrity": "sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ==",
|
||||||
"funding": [
|
"funding": [
|
||||||
"https://github.com/sponsors/broofa",
|
"https://github.com/sponsors/broofa",
|
||||||
"https://github.com/sponsors/ctavan"
|
"https://github.com/sponsors/ctavan"
|
||||||
],
|
],
|
||||||
"bin": {
|
|
||||||
"uuid": "dist/bin/uuid"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/microsoft-cognitiveservices-speech-sdk/node_modules/ws": {
|
|
||||||
"version": "7.5.10",
|
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
|
||||||
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"engines": {
|
"bin": {
|
||||||
"node": ">=8.3.0"
|
"uuid": "dist/esm/bin/uuid"
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"bufferutil": "^4.0.1",
|
|
||||||
"utf-8-validate": "^5.0.2"
|
|
||||||
},
|
|
||||||
"peerDependenciesMeta": {
|
|
||||||
"bufferutil": {
|
|
||||||
"optional": true
|
|
||||||
},
|
|
||||||
"utf-8-validate": {
|
|
||||||
"optional": true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/mime-db": {
|
"node_modules/mime-db": {
|
||||||
@@ -7037,15 +7058,6 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/undici": {
|
|
||||||
"version": "7.24.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.24.5.tgz",
|
|
||||||
"integrity": "sha512-3IWdCpjgxp15CbJnsi/Y9TCDE7HWVN19j1hmzVhoAkY/+CJx449tVxT5wZc1Gwg8J+P0LWvzlBzxYRnHJ+1i7Q==",
|
|
||||||
"license": "MIT",
|
|
||||||
"engines": {
|
|
||||||
"node": ">=20.18.1"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/undici-types": {
|
"node_modules/undici-types": {
|
||||||
"version": "5.26.5",
|
"version": "5.26.5",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||||
@@ -7348,11 +7360,6 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"23": {
|
|
||||||
"version": "0.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/23/-/23-0.0.0.tgz",
|
|
||||||
"integrity": "sha512-uAETf9Okr72trtp1pNXYKhFCTTI1EKGcYMA8gw3jLGhlbaDX+grrNToEWrpt8luxRAvrZWBTvyB5wk3PpNjGQQ=="
|
|
||||||
},
|
|
||||||
"@aashutoshrathi/word-wrap": {
|
"@aashutoshrathi/word-wrap": {
|
||||||
"version": "1.2.6",
|
"version": "1.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/@aashutoshrathi/word-wrap/-/word-wrap-1.2.6.tgz",
|
||||||
@@ -7930,6 +7937,34 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.4.tgz",
|
||||||
"integrity": "sha512-iY8yvjE0y651BixKNPgmv1WrQc+GZ142sb0z4gYnChDDY2YqI4P/jsSopBWrKfAt7LOJAkOXt7rC/hms+WclQQ=="
|
"integrity": "sha512-iY8yvjE0y651BixKNPgmv1WrQc+GZ142sb0z4gYnChDDY2YqI4P/jsSopBWrKfAt7LOJAkOXt7rC/hms+WclQQ=="
|
||||||
},
|
},
|
||||||
|
"@azure/abort-controller": {
|
||||||
|
"version": "2.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-2.2.0.tgz",
|
||||||
|
"integrity": "sha512-fNAjWnA/nZ2jz31kxR/AqRaUT8ewHBw/WuBIosK0moMy1C9e5ValbDfFdIxJzVOOYaYkV/b2F1S4H/aHiqfVQg==",
|
||||||
|
"requires": {
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@azure/core-auth": {
|
||||||
|
"version": "1.11.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@azure/core-auth/-/core-auth-1.11.0.tgz",
|
||||||
|
"integrity": "sha512-IUZydyTUkDnYdstOW9pFOOUQlBjAepK5teihDE3x6yxsPJs/hsAaaYpeGxdxrgtOiJbBKSjKW7MDk7AEhb4LRg==",
|
||||||
|
"requires": {
|
||||||
|
"@azure/abort-controller": "^2.1.2",
|
||||||
|
"@azure/core-util": "^1.13.0",
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@azure/core-util": {
|
||||||
|
"version": "1.14.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/@azure/core-util/-/core-util-1.14.0.tgz",
|
||||||
|
"integrity": "sha512-9n2pWK61veAuN0V20t9lOuoV4CFMdyAZ1ygZzvBGk/pBBJRib/PjL9PLXa/aI2CcPpyHfqVsxxqLCYl6uZlfDw==",
|
||||||
|
"requires": {
|
||||||
|
"@azure/abort-controller": "^2.1.2",
|
||||||
|
"@typespec/ts-http-runtime": "^0.3.0",
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@babel/code-frame": {
|
"@babel/code-frame": {
|
||||||
"version": "7.26.2",
|
"version": "7.26.2",
|
||||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz",
|
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.26.2.tgz",
|
||||||
@@ -9124,6 +9159,16 @@
|
|||||||
"resolved": "https://registry.npmjs.org/@types/webrtc/-/webrtc-0.0.37.tgz",
|
"resolved": "https://registry.npmjs.org/@types/webrtc/-/webrtc-0.0.37.tgz",
|
||||||
"integrity": "sha512-JGAJC/ZZDhcrrmepU4sPLQLIOIAgs5oIK+Ieq90K8fdaNMhfdfqmYatJdgif1NDQtvrSlTOGJDUYHIDunuufOg=="
|
"integrity": "sha512-JGAJC/ZZDhcrrmepU4sPLQLIOIAgs5oIK+Ieq90K8fdaNMhfdfqmYatJdgif1NDQtvrSlTOGJDUYHIDunuufOg=="
|
||||||
},
|
},
|
||||||
|
"@typespec/ts-http-runtime": {
|
||||||
|
"version": "0.3.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/@typespec/ts-http-runtime/-/ts-http-runtime-0.3.8.tgz",
|
||||||
|
"integrity": "sha512-bLMpVcWZNzq6lYOybwFwOAR1IXKcHnhUNqYeHjl1bET/qE3jFPFH+p8Wrh3rU4xwdnifPxmKNESBYnvnmc75aA==",
|
||||||
|
"requires": {
|
||||||
|
"http-proxy-agent": "^7.0.0",
|
||||||
|
"https-proxy-agent": "^7.0.0",
|
||||||
|
"tslib": "^2.6.2"
|
||||||
|
}
|
||||||
|
},
|
||||||
"abort-controller": {
|
"abort-controller": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/abort-controller/-/abort-controller-3.0.0.tgz",
|
||||||
@@ -10064,11 +10109,6 @@
|
|||||||
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/form-data-encoder/-/form-data-encoder-1.7.2.tgz",
|
||||||
"integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A=="
|
"integrity": "sha512-qfqtYan3rxrnCk1VYaA4H+Ms9xdpPqvLZa6xmMgFvhO32x7/3J/ExcTd6qpxM0vH2GdMI+poehyBZvqfMTto8A=="
|
||||||
},
|
},
|
||||||
"form-urlencoded": {
|
|
||||||
"version": "6.1.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/form-urlencoded/-/form-urlencoded-6.1.4.tgz",
|
|
||||||
"integrity": "sha512-vDFWgogZ04th20oxQtDSF8CDjrBgAPtP1V+W3kZni5IZqyasDDVNqCQGOXfYlmOJj0zpROgiAtPJXCmidtxDTQ=="
|
|
||||||
},
|
|
||||||
"formdata-node": {
|
"formdata-node": {
|
||||||
"version": "4.4.1",
|
"version": "4.4.1",
|
||||||
"resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz",
|
"resolved": "https://registry.npmjs.org/formdata-node/-/formdata-node-4.4.1.tgz",
|
||||||
@@ -11117,16 +11157,17 @@
|
|||||||
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="
|
"integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g=="
|
||||||
},
|
},
|
||||||
"microsoft-cognitiveservices-speech-sdk": {
|
"microsoft-cognitiveservices-speech-sdk": {
|
||||||
"version": "1.38.0",
|
"version": "1.51.0",
|
||||||
"resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.38.0.tgz",
|
"resolved": "https://registry.npmjs.org/microsoft-cognitiveservices-speech-sdk/-/microsoft-cognitiveservices-speech-sdk-1.51.0.tgz",
|
||||||
"integrity": "sha512-NA6J4eIDkeR9iN83rcn77Kn5AWQcizDEn1tLMjzRvSovUNB1FrZe0mWYO0fsGltUwMl3Ns5OZ3lGw42PU4fEYA==",
|
"integrity": "sha512-BLLovv5PegOr5Lp52h4CSgL2c/ViFAh9LoU49ILNPyb/Z0giGI7nPV3xNLcmTtHLT+kfYNRGUIA62vORLzP8TA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"@azure/core-auth": "^1.9.0",
|
||||||
"@types/webrtc": "^0.0.37",
|
"@types/webrtc": "^0.0.37",
|
||||||
"agent-base": "^6.0.1",
|
"agent-base": "^6.0.1",
|
||||||
"bent": "^7.3.12",
|
"bent": "^7.3.12",
|
||||||
"https-proxy-agent": "^4.0.0",
|
"https-proxy-agent": "^4.0.0",
|
||||||
"uuid": "^9.0.0",
|
"uuid": "^11.1.1",
|
||||||
"ws": "^7.5.6"
|
"ws": "^8.21.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"https-proxy-agent": {
|
"https-proxy-agent": {
|
||||||
@@ -11146,15 +11187,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"uuid": {
|
"uuid": {
|
||||||
"version": "9.0.1",
|
"version": "11.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/uuid/-/uuid-11.1.1.tgz",
|
||||||
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA=="
|
"integrity": "sha512-vIYxrBCC/N/K+Js3qSN88go7kIfNPssr/hHCesKCQNAjmgvYS2oqr69kIufEG+O4+PfezOH4EbIeHCfFov8ZgQ=="
|
||||||
},
|
|
||||||
"ws": {
|
|
||||||
"version": "7.5.10",
|
|
||||||
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.10.tgz",
|
|
||||||
"integrity": "sha512-+dbF1tHwZpXcbOJdVOkzLDxZP1ailvSxM6ZweXTegylPny803bFhA+vqBYw4s31NSAk4S2Qz+AKXK9a4wkdjcQ==",
|
|
||||||
"requires": {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -12358,11 +12393,6 @@
|
|||||||
"which-boxed-primitive": "^1.0.2"
|
"which-boxed-primitive": "^1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"undici": {
|
|
||||||
"version": "7.24.5",
|
|
||||||
"resolved": "https://registry.npmjs.org/undici/-/undici-7.24.5.tgz",
|
|
||||||
"integrity": "sha512-3IWdCpjgxp15CbJnsi/Y9TCDE7HWVN19j1hmzVhoAkY/+CJx449tVxT5wZc1Gwg8J+P0LWvzlBzxYRnHJ+1i7Q=="
|
|
||||||
},
|
|
||||||
"undici-types": {
|
"undici-types": {
|
||||||
"version": "5.26.5",
|
"version": "5.26.5",
|
||||||
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
|
||||||
|
|||||||
+3
-7
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@jambonz/speech-utils",
|
"name": "@jambonz/speech-utils",
|
||||||
"version": "1.0.4",
|
"version": "1.0.21",
|
||||||
"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",
|
||||||
@@ -13,7 +13,6 @@
|
|||||||
"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": "npm run jslint --fix",
|
"jslint:fix": "npm run jslint --fix",
|
||||||
"build": "./build_stubs.sh",
|
|
||||||
"prepare": "husky"
|
"prepare": "husky"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
@@ -26,7 +25,6 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/jambonz/speech-utils#readme",
|
"homepage": "https://github.com/jambonz/speech-utils#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"23": "^0.0.0",
|
|
||||||
"@aws-sdk/client-polly": "^3.496.0",
|
"@aws-sdk/client-polly": "^3.496.0",
|
||||||
"@aws-sdk/client-sts": "^3.496.0",
|
"@aws-sdk/client-sts": "^3.496.0",
|
||||||
"@cartesia/cartesia-js": "^2.2.7",
|
"@cartesia/cartesia-js": "^2.2.7",
|
||||||
@@ -35,11 +33,9 @@
|
|||||||
"@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.4",
|
|
||||||
"google-protobuf": "^3.21.2",
|
"google-protobuf": "^3.21.2",
|
||||||
"microsoft-cognitiveservices-speech-sdk": "1.38.0",
|
"microsoft-cognitiveservices-speech-sdk": "^1.51.0",
|
||||||
"openai": "^4.98.0",
|
"openai": "^4.98.0"
|
||||||
"undici": "^7.5.0"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"config": "^4.2.0",
|
"config": "^4.2.0",
|
||||||
|
|||||||
@@ -1,332 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package nuance.tts.v1;
|
|
||||||
|
|
||||||
/*
|
|
||||||
The Synthesizer service offers these functionalities:
|
|
||||||
* - 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.
|
|
||||||
* - UnarySynthesize: Synthesizes audio from input text and parameters, and returns a single audio response.
|
|
||||||
*/
|
|
||||||
service Synthesizer {
|
|
||||||
rpc GetVoices(GetVoicesRequest) returns (GetVoicesResponse) {}
|
|
||||||
rpc Synthesize(SynthesisRequest) returns (stream SynthesisResponse) {}
|
|
||||||
rpc UnarySynthesize(SynthesisRequest) returns (UnarySynthesisResponse) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message for [Synthesizer](#synthesizer) - GetVoices, to query voices available to the client.
|
|
||||||
*/
|
|
||||||
message GetVoicesRequest {
|
|
||||||
Voice voice = 1; // Optionally filter the voices to retrieve, e.g. set language to en-US to return only American English voices.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Output message for [Synthesizer](#synthesizer) - GetVoices. Includes a list of voices that matched the input criteria, if any.
|
|
||||||
*/
|
|
||||||
message GetVoicesResponse {
|
|
||||||
repeated Voice voices = 1; // Repeated. Voices and characteristics returned.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message for [Synthesizer](#synthesizer) - Synthesize. Specifies input text, audio parameters, and events to subscribe to, in exchange for synthesized audio.
|
|
||||||
*/
|
|
||||||
message SynthesisRequest {
|
|
||||||
Voice voice = 1; // The voice to use for audio synthesis. Mandatory.
|
|
||||||
AudioParameters audio_params = 2; // Output audio parameters, such as encoding and volume.
|
|
||||||
Input input = 3; // Input text to synthesize, tuning data, etc. Mandatory.
|
|
||||||
EventParameters event_params = 4; // Markers and other info to include in server events returned during synthesis.
|
|
||||||
map<string, string> client_data = 5; // Repeated. Client-supplied key-value pairs to inject into the call log.
|
|
||||||
string user_id = 6; // Identifies a particular user within an application.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input or output message for voices. When sent as input:
|
|
||||||
* - In [GetVoicesRequest](#getvoicesrequest), it filters the list of available voices.
|
|
||||||
* - In [SynthesisRequest](#synthesisrequest), it specifies the voice to use for synthesis.
|
|
||||||
|
|
||||||
When received as output in [GetVoicesResponse](#getvoicesresponse), it returns the list of available voices.
|
|
||||||
*/
|
|
||||||
message Voice {
|
|
||||||
string name = 1; // The voice's name, e.g. 'Evan'. Mandatory for SynthesisRequest.
|
|
||||||
string model = 2; // The voice's quality model, e.g. 'enhanced' or 'standard'. Mandatory for SynthesisRequest.
|
|
||||||
string language = 3; // IETF language code, e.g. 'en-US'. Used only for GetVoicesRequest and GetVoicesResponse, to search for voices with a certain mother tongue. Ignored otherwise.
|
|
||||||
EnumAgeGroup age_group = 4; // Used only for GetVoicesRequest and GetVoicesResponse, to search for adult or child voices. Ignored otherwise.
|
|
||||||
EnumGender gender = 5; // Used only for GetVoicesRequest and GetVoicesResponse, to search for voices with a certain gender. Ignored otherwise.
|
|
||||||
uint32 sample_rate_hz = 6; // Used only for GetVoicesRequest and GetVoicesResponse, to search for a certain native sample rate. Ignored otherwise.
|
|
||||||
string language_tlw = 7; // Used only for GetVoicesRequest and GetVoicesResponse. Three-letter language code (e.g. 'enu' for American English), for configuring language identification in [Input](#input).
|
|
||||||
bool restricted = 8; // Used only in GetVoicesResponse, to identify restricted voices. These are custom voices available only to specific customers. Ignored otherwise.
|
|
||||||
string version = 9; // Used only in GetVoicesResponse, to return the voice's version. Ignored otherwise.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input or output field specifying whether the voice uses its adult or child version, if available. Included in [Voice](#voice).
|
|
||||||
*/
|
|
||||||
enum EnumAgeGroup {
|
|
||||||
ADULT = 0; // Adult voice. Default for GetVoicesRequest.
|
|
||||||
CHILD = 1; // Child voice.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input or output field, specifying gender for voices that support multiple genders. Included in [Voice](#voice).
|
|
||||||
*/
|
|
||||||
enum EnumGender {
|
|
||||||
ANY = 0; // Any gender voice. Default for GetVoicesRequest.
|
|
||||||
MALE = 1; // Male voice.
|
|
||||||
FEMALE = 2; // Female voice.
|
|
||||||
NEUTRAL = 3; // Neutral gender voice.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message for audio-related parameters during synthesis, including encoding, volume, and audio length. Included in [SynthesisRequest](#synthesisrequest).
|
|
||||||
*/
|
|
||||||
message AudioParameters {
|
|
||||||
AudioFormat audio_format = 1; // Audio encoding. Default PCM 22.5kHz.
|
|
||||||
uint32 volume_percentage = 2; // Volume amplitude, from 0 to 100. Default 80.
|
|
||||||
float speaking_rate_factor = 3; // Speaking rate, from 0 to 2.0. Default 1.0.
|
|
||||||
uint32 audio_chunk_duration_ms = 4; // Maximum duration, in ms, of an audio chunk delivered to the client, from 1 to 60000. Default is 20000 (20 seconds). When this parameter is large enough (for example, 20 or 30 seconds), each audio chunk contains an audible segment surrounded by silence.
|
|
||||||
uint32 target_audio_length_ms = 5; // Maximum duration, in ms, of synthesized audio. When greater than 0, the server stops ongoing synthesis at the first sentence end, or silence, closest to the value.
|
|
||||||
bool disable_early_emission = 6; // By default, audio segments are emitted as soon as possible, even if they are not audible. This behavior may be disabled.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message for audio encoding of synthesized text. Included in [AudioParameters](#audioparameters).
|
|
||||||
*/
|
|
||||||
message AudioFormat {
|
|
||||||
oneof audio_format {
|
|
||||||
PCM pcm = 1; // Signed 16-bit little endian PCM.
|
|
||||||
ALaw alaw = 2; // G.711 A-law, 8kHz.
|
|
||||||
ULaw ulaw = 3; // G.711 Mu-law, 8kHz.
|
|
||||||
OggOpus ogg_opus = 4; // Ogg Opus, 8kHz, 16kHz or 24kHz.
|
|
||||||
Opus opus = 5; // Opus, 8kHz, 16kHZ or 24 kHz. The audio will be sent one Opus packet at a time.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message defining PCM sample rate. Included in [Audioformat](#audioformat).
|
|
||||||
*/
|
|
||||||
message PCM {
|
|
||||||
uint32 sample_rate_hz = 1; // Output sample rate: 8000, 16000, 22050 (default), 24000.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message defining A-law audio format. G.711 audio formats are set to 8kHz. Included in [Audioformat](#audioformat).
|
|
||||||
*/
|
|
||||||
message ALaw {}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message defining Mu-law audio format. G.711 audio formats are set to 8kHz. Included in [Audioformat](#audioformat).
|
|
||||||
*/
|
|
||||||
message ULaw {}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message defining Opus output rate. Included in [Audioformat](#audioformat).
|
|
||||||
*/
|
|
||||||
message Opus {
|
|
||||||
uint32 sample_rate_hz = 1; // Output sample rate. Supported values: 8000, 16000, 24000 Hz.
|
|
||||||
uint32 bit_rate_bps = 2; // Valid range is 500 to 256000 bps. Default 28000 bps.
|
|
||||||
float max_frame_duration_ms = 3; // Opus frame size, in ms: 2.5, 5, 10, 20, 40, 60. Default 20.
|
|
||||||
uint32 complexity = 4; // Computational complexity. A complexity of 0 means the codec default.
|
|
||||||
EnumVariableBitrate vbr = 5; // Variable bitrate. On by default.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message defining Ogg Opus output rate. Included in [Audioformat](#audioformat).
|
|
||||||
*/
|
|
||||||
message OggOpus {
|
|
||||||
uint32 sample_rate_hz = 1; // Output sample rate. Supported values: 8000, 16000, 24000 Hz.
|
|
||||||
uint32 bit_rate_bps = 2; // Valid range is 500 to 256000 bps. Default 28000 bps.
|
|
||||||
float max_frame_duration_ms = 3; // Opus frame size, in ms: 2.5, 5, 10, 20, 40, 60. Default 20.
|
|
||||||
uint32 complexity = 4; // Computational complexity. A complexity of 0 means the codec default.
|
|
||||||
EnumVariableBitrate vbr = 5; // Variable bitrate. On by default.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Settings for variable bitrate. Included in [OggOpus](#oggopus). Turned on by default.
|
|
||||||
*/
|
|
||||||
enum EnumVariableBitrate {
|
|
||||||
VARIABLE_BITRATE_ON = 0; // Use variable bitrate. Default.
|
|
||||||
VARIABLE_BITRATE_OFF = 1; // Do not use variable bitrate.
|
|
||||||
VARIABLE_BITRATE_CONSTRAINED = 2; // Use constrained variable bitrate.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message containing text to synthesize and synthesis parameters, including tuning data, etc. Included in [SynthesisRequest](#synthesisrequest). The type of input may be:
|
|
||||||
* - Plain text.
|
|
||||||
* - An SSML document.
|
|
||||||
* - An alternating sequence of plain text and Nuance control codes.
|
|
||||||
*/
|
|
||||||
message Input {
|
|
||||||
oneof input_data {
|
|
||||||
Text text = 1; // Text input.
|
|
||||||
SSML ssml = 2; // SSML input.
|
|
||||||
TokenizedSequence tokenized_sequence = 3; // Sequence of text and Nuance control codes.
|
|
||||||
}
|
|
||||||
repeated SynthesisResource resources = 4; // Repeated. Synthesis resources (user dictionaries, rulesets, etc.) to tune synthesized audio.
|
|
||||||
LanguageIdentificationParameters lid_params = 5; // LID parameters.
|
|
||||||
DownloadParameters download_params = 6; // Remote file download parameters.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message for synthesizing plain text. The encoding must be in UTF-8.
|
|
||||||
*/
|
|
||||||
message Text {
|
|
||||||
oneof text_data {
|
|
||||||
string text = 1; // Plain input text in UTF-8 encoding.
|
|
||||||
string uri = 2; // Remote URI to the plain input text. Disabled for Nuance-hosted TTS.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message for synthesizing an SSML document.
|
|
||||||
*/
|
|
||||||
message SSML {
|
|
||||||
oneof ssml_data {
|
|
||||||
string text = 1; // SSML input text.
|
|
||||||
string uri = 2; // Remote URI to the SSML input text. Disabled for Nuance-hosted TTS.
|
|
||||||
}
|
|
||||||
EnumSSMLValidationMode ssml_validation_mode = 3; // SSML validation mode. Default STRICT.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message for synthesizing a sequence of plain text and Nuance control codes.
|
|
||||||
*/
|
|
||||||
message TokenizedSequence {
|
|
||||||
repeated Token tokens = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
The unit when using TokenizedSequence for input. Each token can either be plain text or a Nuance control code.
|
|
||||||
*/
|
|
||||||
message Token {
|
|
||||||
oneof token_data {
|
|
||||||
string text = 1; // Plain input text.
|
|
||||||
ControlCode control_code = 2; // Nuance control code.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
A Nuance control code allows the user to control how text is spoken, similarly to SSML.
|
|
||||||
*/
|
|
||||||
message ControlCode {
|
|
||||||
string key = 1; // Name of the control code, e.g. "pause".
|
|
||||||
string value = 2; // Value of the control code.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message specifying the type of file to tune the synthesized output and its location or contents. Included in [Input](#input).
|
|
||||||
*/
|
|
||||||
message SynthesisResource {
|
|
||||||
EnumResourceType type = 1; // Resource type, e.g. user dictionary, etc. Default USER_DICTIONARY.
|
|
||||||
oneof resource_data {
|
|
||||||
string uri = 2; // URI to the remote resource, or
|
|
||||||
bytes body = 3; // For EnumResourceType USER_DICTIONARY, the contents of the file.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
The type of synthesis resource to tune the output. Included in [SynthesisResource](#synthesisresource). User dictionaries provide custom pronunciations, rulesets apply search-and-replace rules to input text and ActivePrompt databases help tune synthesized audio under certain conditions, using Nuance Vocalizer Studio.
|
|
||||||
*/
|
|
||||||
enum EnumResourceType {
|
|
||||||
USER_DICTIONARY = 0; // User dictionary (application/edct-bin-dictionary). Default.
|
|
||||||
TEXT_USER_RULESET = 1; // Text user ruleset (application/x-vocalizer-rettt+text).
|
|
||||||
BINARY_USER_RULESET = 2; // Binary user ruleset (application/x-vocalizer-rettt+bin).
|
|
||||||
ACTIVEPROMPT_DB = 3; // ActivePrompt database (application/x-vocalizer/activeprompt-db).
|
|
||||||
ACTIVEPROMPT_DB_AUTO = 4; // ActivePrompt database with automatic insertion (application/x-vocalizer/activeprompt-db;mode=automatic).
|
|
||||||
SYSTEM_DICTIONARY = 5; // Nuance system dictionary (application/sdct-bin-dictionary).
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
SSML validation mode when using SSML input. Included in [Input](#input). Strict by default but can be relaxed.
|
|
||||||
*/
|
|
||||||
enum EnumSSMLValidationMode {
|
|
||||||
STRICT = 0; // Strict SSL validation. Default.
|
|
||||||
WARN = 1; // Give warning only.
|
|
||||||
NONE = 2; // Do not validate.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message controlling the language identifier. Included in [Input](#input). The language identifier runs on input blocks labeled with the <ESC>\lang=unknown\ control sequence or SSML xml:lang="unknown". The language identifier automatically restricts the matched languages to the installed voices. This limits the permissible languages, and also sets the order of precedence (first to last) when they have equal confidence scores.
|
|
||||||
*/
|
|
||||||
message LanguageIdentificationParameters {
|
|
||||||
bool disable = 1; // Whether to disable language identification. Turned on by default.
|
|
||||||
repeated string languages = 2; // Repeated. List of three-letter language codes (e.g. enu, frc, spm) to restrict language identification results, in order of precedence. Use GetVoicesRequest - Voice - language_tlw to obtain the three-letter codes. Default blank.
|
|
||||||
bool always_use_highest_confidence = 3; // If enabled, language identification always chooses the language with the highest confidence score, even if the score is low. Default false, meaning use language with any confidence.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message containing parameters for remote file download, whether for input text (Input.uri) or a SynthesisResource (SynthesisResource.uri). Included in [Input](#input).
|
|
||||||
*/
|
|
||||||
message DownloadParameters {
|
|
||||||
map <string,string> headers = 1; // HTTP headers to include in outgoing requests. Only whitelisted headers will actually be sent.
|
|
||||||
bool refuse_cookies = 2; // Whether to disable cookies. By default, HTTP requests accept cookies.
|
|
||||||
oneof optional_download_parameter_request_timeout_ms {
|
|
||||||
uint32 request_timeout_ms = 3; // Request timeout in ms. Default (0) means server default, usually 30000 (30 seconds).
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Input message that defines event subscription parameters. Included in [SynthesisRequest](#synthesisrequest). Events that are requested are sent throughout the SynthesisResponse stream, when generated. Marker events can send events as certain parts of the synthesized audio are reached, for example, at the end of a word, sentence, or user-defined bookmark.
|
|
||||||
|
|
||||||
* Log events are produced throughout a synthesis request for events such as a voice loaded by the server or an audio chunk being ready to send.
|
|
||||||
*/
|
|
||||||
message EventParameters {
|
|
||||||
bool send_sentence_marker_events = 1; // Sentence marker. Default: do not send.
|
|
||||||
bool send_word_marker_events = 2; // Word marker. Default: do not send.
|
|
||||||
bool send_phoneme_marker_events = 3; // Phoneme marker. Default: do not send.
|
|
||||||
bool send_bookmark_marker_events = 4; // Bookmark marker. Default: do not send.
|
|
||||||
bool send_paragraph_marker_events = 5; // Paragraph marker. Default: do not send.
|
|
||||||
bool send_visemes = 6; // Lipsync information. Default: do not send.
|
|
||||||
bool send_log_events = 7; // Whether to log events during synthesis. By default, logging is turned off.
|
|
||||||
bool suppress_input = 8; // Whether to omit input text and URIs from log events. By default, these items are included.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
The [Synthesizer](#synthesizer) - Synthesize RPC call returns a stream of SynthesisResponse messages. The response contains one of:
|
|
||||||
* - A status response, indicating completion or failure of the request. This is received only once and signifies the end of a Synthesize call.
|
|
||||||
* - A list of events the client has requested. This can be received many times. See EventParameters for details.
|
|
||||||
* - An audio buffer. This may be received many times.
|
|
||||||
*/
|
|
||||||
message SynthesisResponse {
|
|
||||||
oneof response {
|
|
||||||
Status status = 1; // A status response, indicating completion or failure of the request.
|
|
||||||
Events events = 2; // A list of events. See EventParameters for details.
|
|
||||||
bytes audio = 3; // The latest audio buffer.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
The [Synthesizer](#synthesizer) - UnarySynthesize RPC call returns a single UnarySynthesisResponse message. It is similar to a SynthesisResponse message but includes all the information instead of a single type of response. The response contains:
|
|
||||||
* - A status response, indicating completion or failure of the request.
|
|
||||||
* - A list of events the client has requested. See EventParameters for details.
|
|
||||||
* - The complete audio buffer of the synthesized text.
|
|
||||||
*/
|
|
||||||
message UnarySynthesisResponse {
|
|
||||||
Status status = 1; // A status response, indicating completion or failure of the request.
|
|
||||||
Events events = 2; // A list of events. See EventParameters for details.
|
|
||||||
bytes audio = 3; // Audio buffer of the synthesized text.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Output message containing a status response, indicating completion or failure of a SynthesisRequest. Included in [SynthesisResponse](#synthesisresponse) and [UnarySynthesisResponse](#unarysynthesisresponse).
|
|
||||||
*/
|
|
||||||
message Status {
|
|
||||||
uint32 code = 1; // HTTP-style return code: 200, 4xx, or 5xx as appropriate.
|
|
||||||
string message = 2; // Brief description of the status.
|
|
||||||
string details = 3; // Longer description if available.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Output message defining a container for a list of events. This container is needed because oneof does not allow repeated parameters in Protobuf. Included in [SynthesisResponse](#synthesisresponse) and [UnarySynthesisResponse](#unarysynthesisresponse).
|
|
||||||
*/
|
|
||||||
message Events {
|
|
||||||
repeated Event events = 1; // Repeated. One or more events.
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Output message defining an event message. Included in [Events](#events). See EventParameters for details.
|
|
||||||
*/
|
|
||||||
message Event {
|
|
||||||
string name = 1; // Either "Markers" or the name of the event in the case of a Log Event.
|
|
||||||
map<string, string> values = 2; // Repeated. Key-value data relevant to the current event.
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
// GENERATED CODE -- DO NOT EDIT!
|
|
||||||
|
|
||||||
'use strict';
|
|
||||||
var grpc = require('@grpc/grpc-js');
|
|
||||||
var synthesizer_pb = require('./synthesizer_pb.js');
|
|
||||||
|
|
||||||
function serialize_nuance_tts_v1_GetVoicesRequest(arg) {
|
|
||||||
if (!(arg instanceof synthesizer_pb.GetVoicesRequest)) {
|
|
||||||
throw new Error('Expected argument of type nuance.tts.v1.GetVoicesRequest');
|
|
||||||
}
|
|
||||||
return Buffer.from(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_nuance_tts_v1_GetVoicesRequest(buffer_arg) {
|
|
||||||
return synthesizer_pb.GetVoicesRequest.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_nuance_tts_v1_GetVoicesResponse(arg) {
|
|
||||||
if (!(arg instanceof synthesizer_pb.GetVoicesResponse)) {
|
|
||||||
throw new Error('Expected argument of type nuance.tts.v1.GetVoicesResponse');
|
|
||||||
}
|
|
||||||
return Buffer.from(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_nuance_tts_v1_GetVoicesResponse(buffer_arg) {
|
|
||||||
return synthesizer_pb.GetVoicesResponse.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_nuance_tts_v1_SynthesisRequest(arg) {
|
|
||||||
if (!(arg instanceof synthesizer_pb.SynthesisRequest)) {
|
|
||||||
throw new Error('Expected argument of type nuance.tts.v1.SynthesisRequest');
|
|
||||||
}
|
|
||||||
return Buffer.from(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_nuance_tts_v1_SynthesisRequest(buffer_arg) {
|
|
||||||
return synthesizer_pb.SynthesisRequest.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_nuance_tts_v1_SynthesisResponse(arg) {
|
|
||||||
if (!(arg instanceof synthesizer_pb.SynthesisResponse)) {
|
|
||||||
throw new Error('Expected argument of type nuance.tts.v1.SynthesisResponse');
|
|
||||||
}
|
|
||||||
return Buffer.from(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_nuance_tts_v1_SynthesisResponse(buffer_arg) {
|
|
||||||
return synthesizer_pb.SynthesisResponse.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
function serialize_nuance_tts_v1_UnarySynthesisResponse(arg) {
|
|
||||||
if (!(arg instanceof synthesizer_pb.UnarySynthesisResponse)) {
|
|
||||||
throw new Error('Expected argument of type nuance.tts.v1.UnarySynthesisResponse');
|
|
||||||
}
|
|
||||||
return Buffer.from(arg.serializeBinary());
|
|
||||||
}
|
|
||||||
|
|
||||||
function deserialize_nuance_tts_v1_UnarySynthesisResponse(buffer_arg) {
|
|
||||||
return synthesizer_pb.UnarySynthesisResponse.deserializeBinary(new Uint8Array(buffer_arg));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
|
||||||
// The Synthesizer service offers these functionalities:
|
|
||||||
// - 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.
|
|
||||||
// - UnarySynthesize: Synthesizes audio from input text and parameters, and returns a single audio response.
|
|
||||||
var SynthesizerService = exports.SynthesizerService = {
|
|
||||||
getVoices: {
|
|
||||||
path: '/nuance.tts.v1.Synthesizer/GetVoices',
|
|
||||||
requestStream: false,
|
|
||||||
responseStream: false,
|
|
||||||
requestType: synthesizer_pb.GetVoicesRequest,
|
|
||||||
responseType: synthesizer_pb.GetVoicesResponse,
|
|
||||||
requestSerialize: serialize_nuance_tts_v1_GetVoicesRequest,
|
|
||||||
requestDeserialize: deserialize_nuance_tts_v1_GetVoicesRequest,
|
|
||||||
responseSerialize: serialize_nuance_tts_v1_GetVoicesResponse,
|
|
||||||
responseDeserialize: deserialize_nuance_tts_v1_GetVoicesResponse,
|
|
||||||
},
|
|
||||||
synthesize: {
|
|
||||||
path: '/nuance.tts.v1.Synthesizer/Synthesize',
|
|
||||||
requestStream: false,
|
|
||||||
responseStream: true,
|
|
||||||
requestType: synthesizer_pb.SynthesisRequest,
|
|
||||||
responseType: synthesizer_pb.SynthesisResponse,
|
|
||||||
requestSerialize: serialize_nuance_tts_v1_SynthesisRequest,
|
|
||||||
requestDeserialize: deserialize_nuance_tts_v1_SynthesisRequest,
|
|
||||||
responseSerialize: serialize_nuance_tts_v1_SynthesisResponse,
|
|
||||||
responseDeserialize: deserialize_nuance_tts_v1_SynthesisResponse,
|
|
||||||
},
|
|
||||||
unarySynthesize: {
|
|
||||||
path: '/nuance.tts.v1.Synthesizer/UnarySynthesize',
|
|
||||||
requestStream: false,
|
|
||||||
responseStream: false,
|
|
||||||
requestType: synthesizer_pb.SynthesisRequest,
|
|
||||||
responseType: synthesizer_pb.UnarySynthesisResponse,
|
|
||||||
requestSerialize: serialize_nuance_tts_v1_SynthesisRequest,
|
|
||||||
requestDeserialize: deserialize_nuance_tts_v1_SynthesisRequest,
|
|
||||||
responseSerialize: serialize_nuance_tts_v1_UnarySynthesisResponse,
|
|
||||||
responseDeserialize: deserialize_nuance_tts_v1_UnarySynthesisResponse,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
exports.SynthesizerClient = grpc.makeGenericClientConstructor(SynthesizerService);
|
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Resolve AWS credentials for the test suite.
|
||||||
|
*
|
||||||
|
* Returns null when AWS is not configured, so the caller skips.
|
||||||
|
*
|
||||||
|
* When AWS_SESSION_TOKEN is set the credentials are temporary -- GitHub OIDC in CI, or
|
||||||
|
* `aws sso login` locally -- and the key pair must not be passed through. Doing so sends
|
||||||
|
* lib/get-aws-sts-token.js down its accessKeyId branch, which calls GetSessionToken, and
|
||||||
|
* AWS rejects GetSessionToken when it is called with session credentials. Returning the
|
||||||
|
* region alone routes to the SDK's default credential provider chain instead, which
|
||||||
|
* handles temporary credentials correctly.
|
||||||
|
*/
|
||||||
|
module.exports = () => {
|
||||||
|
const region = process.env.AWS_REGION;
|
||||||
|
if (!region) return null;
|
||||||
|
|
||||||
|
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
||||||
|
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
||||||
|
|
||||||
|
if (process.env.AWS_SESSION_TOKEN) return {region};
|
||||||
|
if (accessKeyId && secretAccessKey) return {accessKeyId, secretAccessKey, region};
|
||||||
|
return {region};
|
||||||
|
};
|
||||||
+11
-11
@@ -6,33 +6,33 @@ process.on('unhandledRejection', (reason, p) => {
|
|||||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const awsCredentials = require('./aws-credentials');
|
||||||
|
|
||||||
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
test('AWS - create and cache auth token', async(t) => {
|
test('AWS - create and cache auth token', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {client, getAwsAuthToken} = fn(opts, logger);
|
const {client, getAwsAuthToken} = fn(opts, logger);
|
||||||
|
|
||||||
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY || !process.env.AWS_REGION) {
|
const credentials = awsCredentials();
|
||||||
|
if (!credentials) {
|
||||||
t.pass('skipping AWS auth token tests since no AWS credentials provided');
|
t.pass('skipping AWS auth token tests since no AWS credentials provided');
|
||||||
t.end();
|
t.end();
|
||||||
client.quit();
|
client.quit();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// getAwsAuthToken derives its cache key from roleArn || accessKeyId || speech_credential_sid.
|
||||||
|
// With temporary credentials none of the first two are passed, so supply a stable sid --
|
||||||
|
// which is what production does for instance-profile credentials.
|
||||||
|
const args = {...credentials, speech_credential_sid: 'test-aws-speech-credential'};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let obj = await getAwsAuthToken({
|
let obj = await getAwsAuthToken(args);
|
||||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
||||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
||||||
region: process.env.AWS_REGION
|
|
||||||
});
|
|
||||||
//console.log({obj}, 'received auth token from AWS');
|
//console.log({obj}, 'received auth token from AWS');
|
||||||
t.ok(obj.securityToken && !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({
|
obj = await getAwsAuthToken(args);
|
||||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
||||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
||||||
region: 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.securityToken && obj.servedFromCache, 'successfully received access token from cache');
|
t.ok(obj.securityToken && obj.servedFromCache, 'successfully received access token from cache');
|
||||||
|
|
||||||
|
|||||||
@@ -3,5 +3,4 @@ require('./synth');
|
|||||||
require('./list-voices');
|
require('./list-voices');
|
||||||
require('./aws');
|
require('./aws');
|
||||||
|
|
||||||
require('./nuance');
|
|
||||||
require('./docker_stop');
|
require('./docker_stop');
|
||||||
|
|||||||
+5
-100
@@ -1,4 +1,5 @@
|
|||||||
const test = require('tape').test ;
|
const test = require('tape').test ;
|
||||||
|
const awsCredentials = require('./aws-credentials');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const opts = config.get('redis');
|
const opts = config.get('redis');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -12,99 +13,6 @@ 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('Nuance hosted tests', async(t) => {
|
|
||||||
const fn = require('..');
|
|
||||||
const {client, getTtsVoices} = fn(opts, logger);
|
|
||||||
|
|
||||||
if (!process.env.NUANCE_CLIENT_ID || !process.env.NUANCE_SECRET ) {
|
|
||||||
t.pass('skipping Nuance hosted test since no Nuance client_id and secret provided');
|
|
||||||
t.end();
|
|
||||||
client.quit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const opts = {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
client_id: process.env.NUANCE_CLIENT_ID,
|
|
||||||
secret: process.env.NUANCE_SECRET
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let voices = await getTtsVoices(opts);
|
|
||||||
t.ok(voices.length > 0 && voices[0].language,
|
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
|
||||||
|
|
||||||
await client.flushall();
|
|
||||||
|
|
||||||
t.end();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
t.end(err);
|
|
||||||
}
|
|
||||||
client.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Nuance on-prem tests', async(t) => {
|
|
||||||
const fn = require('..');
|
|
||||||
const {client, getTtsVoices} = fn(opts, logger);
|
|
||||||
|
|
||||||
if (!process.env.NUANCE_TTS_URI ) {
|
|
||||||
t.pass('skipping Nuance on-prem test since no Nuance uri provided');
|
|
||||||
t.end();
|
|
||||||
client.quit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const opts = {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
nuance_tts_uri: process.env.NUANCE_TTS_URI
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let voices = await getTtsVoices(opts);
|
|
||||||
t.ok(voices.length > 0 && voices[0].language,
|
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
|
||||||
|
|
||||||
await client.flushall();
|
|
||||||
|
|
||||||
t.end();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
t.end(err);
|
|
||||||
}
|
|
||||||
client.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Google tests', async(t) => {
|
test('Google tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {client, getTtsVoices} = fn(opts, logger);
|
const {client, getTtsVoices} = fn(opts, logger);
|
||||||
@@ -138,18 +46,15 @@ test('AWS tests', async(t) => {
|
|||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {client, getTtsVoices} = fn(opts, logger);
|
const {client, getTtsVoices} = fn(opts, logger);
|
||||||
|
|
||||||
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY || !process.env.AWS_REGION) {
|
const credentials = awsCredentials();
|
||||||
t.pass('skipping AWS speech synth tests since AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or AWS_REGION not provided');
|
if (!credentials) {
|
||||||
|
t.pass('skipping AWS speech synth tests since AWS_REGION not provided');
|
||||||
return t.end();
|
return t.end();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const opts = {
|
const opts = {
|
||||||
vendor: 'aws',
|
vendor: 'aws',
|
||||||
credentials: {
|
credentials
|
||||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
||||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
||||||
region: process.env.AWS_REGION,
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
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`);
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
const test = require('tape').test ;
|
|
||||||
const config = require('config');
|
|
||||||
const opts = config.get('redis');
|
|
||||||
const fs = require('fs');
|
|
||||||
const logger = require('pino')({level: 'error'});
|
|
||||||
process.on('unhandledRejection', (reason, p) => {
|
|
||||||
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
|
||||||
});
|
|
||||||
|
|
||||||
const stats = {
|
|
||||||
increment: () => {},
|
|
||||||
histogram: () => {}
|
|
||||||
};
|
|
||||||
|
|
||||||
test('Nuance hosted tests', async(t) => {
|
|
||||||
const fn = require('..');
|
|
||||||
const {client, getTtsVoices} = fn(opts, logger);
|
|
||||||
|
|
||||||
if (!process.env.NUANCE_CLIENT_ID || !process.env.NUANCE_SECRET ) {
|
|
||||||
t.pass('skipping Nuance hosted test since no Nuance client_id and secret provided');
|
|
||||||
t.end();
|
|
||||||
client.quit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const opts = {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
client_id: process.env.NUANCE_CLIENT_ID,
|
|
||||||
secret: process.env.NUANCE_SECRET
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let voices = await getTtsVoices(opts);
|
|
||||||
t.ok(voices.length > 0 && voices[0].language,
|
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
|
||||||
|
|
||||||
await client.flushall();
|
|
||||||
|
|
||||||
t.end();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
t.end(err);
|
|
||||||
}
|
|
||||||
client.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Nuance on-prem tests', async(t) => {
|
|
||||||
const fn = require('..');
|
|
||||||
const {client, getTtsVoices} = fn(opts, logger);
|
|
||||||
|
|
||||||
if (!process.env.NUANCE_TTS_URI ) {
|
|
||||||
t.pass('skipping Nuance on-prem test since no Nuance uri provided');
|
|
||||||
t.end();
|
|
||||||
client.quit();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const opts = {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
nuance_tts_uri: process.env.NUANCE_TTS_URI
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let voices = await getTtsVoices(opts);
|
|
||||||
t.ok(voices.length > 0 && voices[0].language,
|
|
||||||
`GetVoices: successfully retrieved ${voices.length} voices from Nuance`);
|
|
||||||
|
|
||||||
await client.flushall();
|
|
||||||
|
|
||||||
t.end();
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
t.end(err);
|
|
||||||
}
|
|
||||||
client.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
+427
-172
@@ -1,4 +1,5 @@
|
|||||||
const test = require('tape').test;
|
const test = require('tape').test;
|
||||||
|
const awsCredentials = require('./aws-credentials');
|
||||||
const config = require('config');
|
const config = require('config');
|
||||||
const opts = config.get('redis');
|
const opts = config.get('redis');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -442,6 +443,95 @@ test('Google TTS streaming tests (!JAMBONES_DISABLE_TTS_STREAMING)', async(t) =>
|
|||||||
});
|
});
|
||||||
t.ok(result.filePath.includes('api_mode=tts'), 'options.apiMode=tts overrides HD voice default');
|
t.ok(result.filePath.includes('api_mode=tts'), 'options.apiMode=tts overrides HD voice default');
|
||||||
|
|
||||||
|
/* AudioConfig settings (speakingRate, pitch, volumeGainDb) */
|
||||||
|
const googleCreds = {
|
||||||
|
credentials: {
|
||||||
|
client_email: creds.client_email,
|
||||||
|
private_key: creds.private_key,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test 9: AudioConfig nested under options.audioConfig, as in google's API docs
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-Wavenet-D',
|
||||||
|
text: 'Testing nested audioConfig settings.',
|
||||||
|
options: { audioConfig: { speakingRate: 1.4, pitch: -2.5, volumeGainDb: 6 } },
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(result.filePath.includes(',speaking_rate=1.4'), 'nested audioConfig sets speaking_rate');
|
||||||
|
t.ok(result.filePath.includes(',pitch=-2.5'), 'nested audioConfig sets pitch');
|
||||||
|
t.ok(result.filePath.includes(',volume_gain_db=6'), 'nested audioConfig sets volume_gain_db');
|
||||||
|
|
||||||
|
// Test 10: AudioConfig flat at the top level of options, in camelCase or snake_case
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-Wavenet-D',
|
||||||
|
text: 'Testing flat audioConfig settings.',
|
||||||
|
options: { speaking_rate: '0.8', volumeGainDb: 3 },
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(result.filePath.includes(',speaking_rate=0.8'), 'flat snake_case speaking_rate is honored');
|
||||||
|
t.ok(result.filePath.includes(',volume_gain_db=3'), 'flat camelCase volumeGainDb is honored');
|
||||||
|
t.ok(!result.filePath.includes(',pitch='), 'unspecified audioConfig setting is omitted');
|
||||||
|
|
||||||
|
// Test 11: zero is a meaningful value for pitch and volumeGainDb, not an absent one
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-Wavenet-D',
|
||||||
|
text: 'Testing zero audioConfig settings.',
|
||||||
|
options: { audioConfig: { pitch: 0, volumeGainDb: 0 } },
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(result.filePath.includes(',pitch=0'), 'pitch=0 is passed through rather than dropped');
|
||||||
|
t.ok(result.filePath.includes(',volume_gain_db=0'), 'volume_gain_db=0 is passed through rather than dropped');
|
||||||
|
|
||||||
|
// Test 12: non-numeric values are ignored, so they cannot corrupt the freeswitch param string
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-Wavenet-D',
|
||||||
|
text: 'Testing invalid audioConfig settings.',
|
||||||
|
options: { audioConfig: { speakingRate: 'fast,evil=1', pitch: null, volumeGainDb: '' } },
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(!result.filePath.includes('speaking_rate'), 'non-numeric speakingRate is ignored');
|
||||||
|
t.ok(!result.filePath.includes('evil=1'), 'non-numeric value cannot inject extra params');
|
||||||
|
t.ok(!result.filePath.includes('pitch='), 'null pitch is ignored');
|
||||||
|
t.ok(!result.filePath.includes('volume_gain_db'), 'empty volumeGainDb is ignored');
|
||||||
|
|
||||||
|
// Test 13: no audioConfig supplied leaves the param string untouched
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-Wavenet-D',
|
||||||
|
text: 'Testing absent audioConfig settings.',
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(!/speaking_rate|pitch=|volume_gain_db/.test(result.filePath),
|
||||||
|
'no audioConfig params are added when none are supplied');
|
||||||
|
|
||||||
|
// Test 14: HD voice (api_mode=live) also carries speaking_rate, the one setting google streams support
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-Chirp3-HD-Charon',
|
||||||
|
text: 'Testing audioConfig on an HD voice.',
|
||||||
|
options: { audioConfig: { speakingRate: 1.25 } },
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(result.filePath.includes('api_mode=live'), 'HD voice with audioConfig still uses api_mode=live');
|
||||||
|
t.ok(result.filePath.includes(',speaking_rate=1.25'), 'HD voice streaming path carries speaking_rate');
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
t.end(err);
|
t.end(err);
|
||||||
@@ -526,6 +616,42 @@ test('Google TTS non-streaming tests (JAMBONES_DISABLE_TTS_STREAMING=true)', asy
|
|||||||
t.ok(!result.filePath.startsWith('say:'), 'Gemini TTS does NOT return streaming say: path when disabled');
|
t.ok(!result.filePath.startsWith('say:'), 'Gemini TTS does NOT return streaming say: path when disabled');
|
||||||
t.ok(result.filePath.endsWith('.mp3'), 'Gemini TTS returns mp3 file path');
|
t.ok(result.filePath.endsWith('.mp3'), 'Gemini TTS returns mp3 file path');
|
||||||
|
|
||||||
|
const googleCreds = {
|
||||||
|
credentials: {
|
||||||
|
client_email: creds.client_email,
|
||||||
|
private_key: creds.private_key,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test 4: AudioConfig settings are accepted by the synthesize API.
|
||||||
|
* Google rejects out-of-range values with a 400, so a successful render also confirms
|
||||||
|
* the settings reached the request rather than being silently dropped.
|
||||||
|
*/
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'en-US-Wavenet-D',
|
||||||
|
text: 'This is a test of audioConfig with streaming disabled.',
|
||||||
|
options: { audioConfig: { speakingRate: 1.4, pitch: -2.5, volumeGainDb: 6 } },
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(result.filePath.endsWith('.mp3'), 'standard voice renders mp3 with audioConfig settings applied');
|
||||||
|
|
||||||
|
/* Test 5: gemini voices ignore the AudioConfig settings rather than failing on them */
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'google',
|
||||||
|
credentials: googleCreds,
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'Kore',
|
||||||
|
model: geminiModel,
|
||||||
|
text: 'This is a test of audioConfig on Gemini TTS.',
|
||||||
|
options: { audioConfig: { speakingRate: 1.4, pitch: -2.5, volumeGainDb: 6 } },
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(result.filePath.endsWith('.mp3'), 'gemini voice renders mp3 with audioConfig settings skipped');
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
t.end(err);
|
t.end(err);
|
||||||
@@ -543,18 +669,15 @@ 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);
|
||||||
|
|
||||||
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY || !process.env.AWS_REGION) {
|
const credentials = awsCredentials();
|
||||||
t.pass('skipping AWS speech synth tests since AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or AWS_REGION not provided');
|
if (!credentials) {
|
||||||
|
t.pass('skipping AWS speech synth tests since AWS_REGION not provided');
|
||||||
return t.end();
|
return t.end();
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
let opts = await synthAudio(stats, {
|
let opts = await synthAudio(stats, {
|
||||||
vendor: 'aws',
|
vendor: 'aws',
|
||||||
credentials: {
|
credentials,
|
||||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
||||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
||||||
region: process.env.AWS_REGION,
|
|
||||||
},
|
|
||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'Joey',
|
voice: 'Joey',
|
||||||
text: 'This is a test. This is only a test',
|
text: 'This is a test. This is only a test',
|
||||||
@@ -564,11 +687,7 @@ test('AWS speech synth tests', async(t) => {
|
|||||||
|
|
||||||
opts = await synthAudio(stats, {
|
opts = await synthAudio(stats, {
|
||||||
vendor: 'aws',
|
vendor: 'aws',
|
||||||
credentials: {
|
credentials,
|
||||||
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
||||||
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
||||||
region: process.env.AWS_REGION,
|
|
||||||
},
|
|
||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'Joey',
|
voice: 'Joey',
|
||||||
text: 'This is a test. This is only a test',
|
text: 'This is a test. This is only a test',
|
||||||
@@ -599,9 +718,18 @@ test('AWS speech synth tests by RoleArn', async(t) => {
|
|||||||
},
|
},
|
||||||
language: 'en-US',
|
language: 'en-US',
|
||||||
voice: 'Joey',
|
voice: 'Joey',
|
||||||
text: 'This is a test. This is only a test',
|
// Distinct text on purpose: the 'AWS speech synth tests' above cache audio for
|
||||||
|
// the same vendor/voice/language, and identical text would hit that cache entry,
|
||||||
|
// making servedFromCache true and this assertion fail.
|
||||||
|
text: 'This is a roleArn test. This is only a roleArn test',
|
||||||
|
// Without this, synthPolly returns the mediajam streaming params string, which
|
||||||
|
// embeds accessKeyId/secretAccessKey/sessionToken (see lib/synth-audio.js).
|
||||||
|
// Every other synth test in this file renders for caching; this one did not,
|
||||||
|
// so it printed live credentials into a public CI log.
|
||||||
|
renderForCaching: true,
|
||||||
});
|
});
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized aws by roleArn audio to ${opts.filePath}`);
|
// Deliberately does not interpolate opts.filePath -- it can carry credentials.
|
||||||
|
t.ok(!opts.servedFromCache, 'successfully synthesized aws by roleArn audio');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
t.end(err);
|
t.end(err);
|
||||||
@@ -759,82 +887,6 @@ test('Azure custom voice speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Nuance hosted speech synth tests', async(t) => {
|
|
||||||
const fn = require('..');
|
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
|
||||||
|
|
||||||
if (!process.env.NUANCE_CLIENT_ID || !process.env.NUANCE_SECRET) {
|
|
||||||
t.pass('skipping Nuance speech synth tests since NUANCE_CLIENT_ID or NUANCE_SECRET not provided');
|
|
||||||
return t.end();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
let opts = await synthAudio(stats, {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
client_id: process.env.NUANCE_CLIENT_ID,
|
|
||||||
secret: process.env.NUANCE_SECRET,
|
|
||||||
},
|
|
||||||
language: 'en-US',
|
|
||||||
voice: 'Evan',
|
|
||||||
text: 'This is a test. This is only a test',
|
|
||||||
});
|
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized nuance audio to ${opts.filePath}`);
|
|
||||||
|
|
||||||
opts = await synthAudio(stats, {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
client_id: process.env.NUANCE_CLIENT_ID,
|
|
||||||
secret: process.env.NUANCE_SECRET,
|
|
||||||
},
|
|
||||||
language: 'en-US',
|
|
||||||
voice: 'Evan',
|
|
||||||
text: 'This is a test. This is only a test',
|
|
||||||
});
|
|
||||||
t.ok(opts.servedFromCache, `successfully retrieved nuance audio from cache ${opts.filePath}`);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
t.end(err);
|
|
||||||
}
|
|
||||||
client.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Nuance on-prem speech synth tests', async(t) => {
|
|
||||||
const fn = require('..');
|
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
|
||||||
|
|
||||||
if (!process.env.NUANCE_TTS_URI) {
|
|
||||||
t.pass('skipping Nuance on prem speech synth tests since NUANCE_TTS_URI not provided');
|
|
||||||
return t.end();
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
let opts = await synthAudio(stats, {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
nuance_tts_uri: process.env.NUANCE_TTS_URI
|
|
||||||
},
|
|
||||||
language: 'en-US',
|
|
||||||
voice: 'Evan',
|
|
||||||
text: 'This is a test of on-prem. This is only a test',
|
|
||||||
});
|
|
||||||
t.ok(!opts.servedFromCache, `successfully synthesized nuance audio to ${opts.filePath}`);
|
|
||||||
|
|
||||||
opts = await synthAudio(stats, {
|
|
||||||
vendor: 'nuance',
|
|
||||||
credentials: {
|
|
||||||
nuance_tts_uri: process.env.NUANCE_TTS_URI
|
|
||||||
},
|
|
||||||
language: 'en-US',
|
|
||||||
voice: 'Evan',
|
|
||||||
text: 'This is a test of on-prem. This is only a test',
|
|
||||||
});
|
|
||||||
t.ok(opts.servedFromCache, `successfully retrieved nuance audio from cache ${opts.filePath}`);
|
|
||||||
} catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
t.end(err);
|
|
||||||
}
|
|
||||||
client.quit();
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Nvidia speech synth tests', async(t) => {
|
test('Nvidia speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -975,55 +1027,6 @@ test('Elevenlabs speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
const testPlayHT = async(t, voice_engine) => {
|
|
||||||
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! ' + Date.now();
|
|
||||||
try {
|
|
||||||
const opts = await synthAudio(stats, {
|
|
||||||
vendor: 'playht',
|
|
||||||
credentials: {
|
|
||||||
api_key: process.env.PLAYHT_API_KEY,
|
|
||||||
user_id: process.env.PLAYHT_USER_ID,
|
|
||||||
voice_engine,
|
|
||||||
options: JSON.stringify({
|
|
||||||
quality: 'medium',
|
|
||||||
speed: 1,
|
|
||||||
seed: 1,
|
|
||||||
temperature: 1,
|
|
||||||
emotion: 'female_happy',
|
|
||||||
voice_guidance: 3,
|
|
||||||
style_guidance: 20,
|
|
||||||
text_guidance: 1,
|
|
||||||
})
|
|
||||||
},
|
|
||||||
language: 'english',
|
|
||||||
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('PlayHT speech synth tests', async(t) => {
|
|
||||||
await testPlayHT(t, 'PlayHT2.0-turbo');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('PlayHT3.0 speech synth tests', async(t) => {
|
|
||||||
await testPlayHT(t, 'Play3.0');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Cartesia speech synth tests', async(t) => {
|
test('Cartesia speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -1058,6 +1061,165 @@ test('Cartesia speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('gradium speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.GRADIUM_API_KEY) {
|
||||||
|
t.pass('skipping gradium speech synth tests since GRADIUM_API_KEY is not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones! ' + Date.now();
|
||||||
|
try {
|
||||||
|
const opts = await synthAudio(stats, {
|
||||||
|
vendor: 'gradium',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.GRADIUM_API_KEY,
|
||||||
|
model_id: 'default'
|
||||||
|
},
|
||||||
|
voice: 'YTpq7expH9539ERJ',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthed gradium audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('kugelaudio speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.KUGELAUDIO_API_KEY) {
|
||||||
|
t.pass('skipping kugelaudio speech synth tests since KUGELAUDIO_API_KEY is not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Guten Tag und willkommen bei jambonz! Ihre Bestellung kostet 12,99 Euro. ' + Date.now();
|
||||||
|
try {
|
||||||
|
const opts = await synthAudio(stats, {
|
||||||
|
vendor: 'kugelaudio',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.KUGELAUDIO_API_KEY,
|
||||||
|
model_id: 'kugel-3'
|
||||||
|
},
|
||||||
|
language: 'de-DE',
|
||||||
|
voice: '1930',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthed kugelaudio audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('speechify speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.SPEECHIFY_API_KEY) {
|
||||||
|
t.pass('skipping speechify speech synth tests since SPEECHIFY_API_KEY is not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambonz! ' + Date.now();
|
||||||
|
try {
|
||||||
|
const opts = await synthAudio(stats, {
|
||||||
|
vendor: 'speechify',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.SPEECHIFY_API_KEY
|
||||||
|
},
|
||||||
|
language: 'en-US',
|
||||||
|
voice: 'geffen_32',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthed speechify audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fishaudio speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.FISHAUDIO_API_KEY) {
|
||||||
|
t.pass('skipping fishaudio speech synth tests since FISHAUDIO_API_KEY is not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones! ' + Date.now();
|
||||||
|
try {
|
||||||
|
/* voice 'default' means "send no reference_id" — fish's own default voice */
|
||||||
|
const o = await synthAudio(stats, {
|
||||||
|
vendor: 'fishaudio',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.FISHAUDIO_API_KEY,
|
||||||
|
model_id: 's2.1-pro'
|
||||||
|
},
|
||||||
|
voice: 'default',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!o.servedFromCache, `successfully synthed fishaudio audio to ${o.filePath}`);
|
||||||
|
|
||||||
|
/* the cache render must be raw 8k pcm (r8): fish's wav header carries a
|
||||||
|
placeholder RIFF size, so we never ask for wav */
|
||||||
|
const o2 = await synthAudio(stats, {
|
||||||
|
vendor: 'fishaudio',
|
||||||
|
credentials: {api_key: process.env.FISHAUDIO_API_KEY},
|
||||||
|
voice: 'default',
|
||||||
|
text: text + ' two',
|
||||||
|
renderForCaching: true,
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(!o2.servedFromCache, 'fishaudio synthed a second uncached render');
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('nineninesix speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.NINENINESIX_API_KEY) {
|
||||||
|
t.pass('skipping nineninesix speech synth tests since NINENINESIX_API_KEY is not provided');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones! ' + Date.now();
|
||||||
|
try {
|
||||||
|
const opts = await synthAudio(stats, {
|
||||||
|
vendor: 'nineninesix',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.NINENINESIX_API_KEY,
|
||||||
|
model_id: 'gepard-1.0'
|
||||||
|
},
|
||||||
|
language: 'en',
|
||||||
|
voice: '775e4dfd-819c-4325-92ec-250f487ef7e3',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthed nineninesix audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
test('inworld speech synth', async(t) => {
|
test('inworld speech synth', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -1088,6 +1250,69 @@ test('inworld speech synth', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('inworld streaming say: params', async(t) => {
|
||||||
|
/* This test asserts the streaming say: path, so it must run with streaming
|
||||||
|
enabled. The Google non-streaming test above sets
|
||||||
|
JAMBONES_DISABLE_TTS_STREAMING and, on its no-credentials skip path,
|
||||||
|
deletes the env var WITHOUT clearing the require cache — so lib/config can
|
||||||
|
still be holding 'true' by the time we get here. Re-require to be
|
||||||
|
independent of what ran before us.
|
||||||
|
*/
|
||||||
|
delete process.env.JAMBONES_DISABLE_TTS_STREAMING;
|
||||||
|
delete require.cache[require.resolve('../lib/config')];
|
||||||
|
delete require.cache[require.resolve('../lib/synth-audio')];
|
||||||
|
delete require.cache[require.resolve('..')];
|
||||||
|
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.INWORLD_API_KEY) {
|
||||||
|
t.pass('skipping inworld streaming say: param tests since INWORLD_API_KEY is not provided');
|
||||||
|
client.quit();
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let result = await synthAudio(stats, {
|
||||||
|
vendor: 'inworld',
|
||||||
|
credentials: {api_key: process.env.INWORLD_API_KEY, model_id: 'inworld-tts-1.5-mini'},
|
||||||
|
language: 'en',
|
||||||
|
voice: 'Ashley',
|
||||||
|
text: 'This is a test of inworld streaming.',
|
||||||
|
options: {temperature: 0.9, audioConfig: {pitch: 2.5, speakingRate: 1.2}},
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(result.filePath.startsWith('say:'), 'inworld returns streaming say: path');
|
||||||
|
t.ok(result.filePath.includes('vendor=inworld'), 'streaming path contains vendor=inworld');
|
||||||
|
t.ok(result.filePath.includes('voice=Ashley'), 'streaming path contains voice');
|
||||||
|
t.ok(result.filePath.includes('model_id=inworld-tts-1.5-mini'), 'streaming path contains model_id');
|
||||||
|
t.ok(result.filePath.includes('temperature=0.9'), 'streaming path contains temperature');
|
||||||
|
/* pitch and speakingRate are nested under audioConfig; they used to be read
|
||||||
|
from the top level and emitted as "undefined"
|
||||||
|
*/
|
||||||
|
t.ok(result.filePath.includes('speakingRate=1.2'), 'audioConfig.speakingRate reaches the say: params');
|
||||||
|
t.ok(result.filePath.includes('pitch=2.5'), 'audioConfig.pitch reaches the say: params');
|
||||||
|
t.ok(!result.filePath.includes('undefined'), 'no undefined values in the say: params');
|
||||||
|
|
||||||
|
/* options omitted entirely: no stray keys */
|
||||||
|
result = await synthAudio(stats, {
|
||||||
|
vendor: 'inworld',
|
||||||
|
credentials: {api_key: process.env.INWORLD_API_KEY, model_id: 'inworld-tts-1.5-mini'},
|
||||||
|
language: 'en',
|
||||||
|
voice: 'Ashley',
|
||||||
|
text: 'This is a test of inworld streaming.',
|
||||||
|
disableTtsCache: true
|
||||||
|
});
|
||||||
|
t.ok(!result.filePath.includes('speakingRate='), 'speakingRate omitted when unset');
|
||||||
|
t.ok(!result.filePath.includes('pitch='), 'pitch omitted when unset');
|
||||||
|
t.ok(!result.filePath.includes('undefined'), 'no undefined values when options are omitted');
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
test('resemble speech synth', async(t) => {
|
test('resemble speech synth', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -1215,39 +1440,6 @@ test('whisper speech synth tests', async(t) => {
|
|||||||
client.quit();
|
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) => {
|
test('Deepgram speech synth tests', async(t) => {
|
||||||
const fn = require('..');
|
const fn = require('..');
|
||||||
const {synthAudio, client} = fn(opts, logger);
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
@@ -1276,6 +1468,69 @@ test('Deepgram speech synth tests', async(t) => {
|
|||||||
client.quit();
|
client.quit();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Deepgram Flux speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.DEEPGRAM_API_KEY) {
|
||||||
|
t.pass('skipping Deepgram Flux speech synth tests since DEEPGRAM_API_KEY');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
const opts = await synthAudio(stats, {
|
||||||
|
vendor: 'deepgramflux',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.DEEPGRAM_API_KEY
|
||||||
|
},
|
||||||
|
model: process.env.DEEPGRAM_FLUX_MODEL || 'flux-alexis-en',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache, `successfully synthesized deepgramflux audio to ${opts.filePath}`);
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(JSON.stringify(err));
|
||||||
|
t.end(err);
|
||||||
|
}
|
||||||
|
client.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('xai speech synth tests', async(t) => {
|
||||||
|
const fn = require('..');
|
||||||
|
const {synthAudio, client} = fn(opts, logger);
|
||||||
|
|
||||||
|
if (!process.env.XAI_API_KEY) {
|
||||||
|
t.pass('skipping xai speech synth tests - no XAI_API_KEY');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
const text = 'Hi there and welcome to jambones!';
|
||||||
|
try {
|
||||||
|
const opts = await synthAudio(stats, {
|
||||||
|
vendor: 'xai',
|
||||||
|
credentials: {
|
||||||
|
api_key: process.env.XAI_API_KEY,
|
||||||
|
options: JSON.stringify({
|
||||||
|
voice: process.env.XAI_VOICE || 'eve',
|
||||||
|
speed: 1.0,
|
||||||
|
optimize_streaming_latency: 1,
|
||||||
|
text_normalization: true
|
||||||
|
})
|
||||||
|
},
|
||||||
|
language: 'en',
|
||||||
|
voice: process.env.XAI_VOICE || 'eve',
|
||||||
|
text,
|
||||||
|
renderForCaching: true
|
||||||
|
});
|
||||||
|
t.ok(!opts.servedFromCache && opts.filePath, `successfully synthesized xai 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