mirror of
https://github.com/jambonz/speech-utils.git
synced 2026-10-03 23:33:59 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c0a79090c2 | ||
|
|
7a9a3e2468 | ||
|
|
ab2b3f7fb2 | ||
|
|
e848d0276e | ||
|
|
d2447d477d | ||
|
|
ec8bbacc2c | ||
|
|
9694714a7f | ||
|
|
6a6de9b7a1 | ||
|
|
04d1fb548b | ||
|
|
bbf0167b40 | ||
|
|
4cfa286242 | ||
|
|
42ac63adc6 | ||
|
|
12a121672d | ||
|
|
7b94a5a969 | ||
|
|
c47b4883c7 | ||
|
|
7d076bb8b4 | ||
|
|
142323a151 | ||
|
|
d176a644fe | ||
|
|
644f2918dc | ||
|
|
4f430b9785 | ||
|
|
18c658d20c | ||
|
|
062608cf13 | ||
|
|
a2ea94c14a | ||
|
|
04bb85ef81 | ||
|
|
c123f19898 | ||
|
|
305695d068 | ||
|
|
1477752d40 | ||
|
|
fbedfe947f | ||
|
|
ab88facd52 | ||
|
|
a2be64da89 | ||
|
|
c5e0f256e6 | ||
|
|
d0378751ba | ||
|
|
a7e391fcb2 | ||
|
|
10095de25d | ||
|
|
89007ba7cc | ||
|
|
29edccd5bf | ||
|
|
ca9538030f | ||
|
|
417d58080e | ||
|
|
62fec6f5e4 | ||
|
|
490d23a703 | ||
|
|
b91e6cc145 | ||
|
|
0e33358254 | ||
|
|
6b2b35acfb | ||
|
|
ded60cb7aa | ||
|
|
460ca70ea7 | ||
|
|
0fbbbb8053 | ||
|
|
0ea7082da2 | ||
|
|
5f7e7458bb | ||
|
|
f6714fb9e1 | ||
|
|
c04ef29f7c | ||
|
|
8154944252 | ||
|
|
16fe8dce01 | ||
|
|
11a955500d | ||
|
|
c122129b55 | ||
|
|
41b26b966b | ||
|
|
aa09c15b20 | ||
|
|
32d5f12638 | ||
|
|
4e336822a0 | ||
|
|
b898d794b0 | ||
|
|
fb754ca101 | ||
|
|
8d8195be9a | ||
|
|
eb4e1a773f | ||
|
|
6fecb8755d | ||
|
|
fdb56cbc77 | ||
|
|
5328a60de8 | ||
|
|
ea1ab301d5 | ||
|
|
0a4994c5a3 | ||
|
|
cb71460189 | ||
|
|
f08efa49b1 | ||
|
|
80eda37ef6 | ||
|
|
7768e58b19 | ||
|
|
6efc99ad83 | ||
|
|
127d01a8c1 | ||
|
|
1900b26d8b | ||
|
|
aa25a6f6d9 | ||
|
|
8dfe17b600 | ||
|
|
5463e9f56e | ||
|
|
2eb36af650 | ||
|
|
b186cbc4f2 | ||
|
|
b1b9c182a9 | ||
|
|
15c77626fc | ||
|
|
76126ec0b3 | ||
|
|
55431ee511 | ||
|
|
1c76f74b4a | ||
|
|
62ad8abb8e | ||
|
|
92734aaedb | ||
|
|
fe4ccfe7d7 | ||
|
|
ab05976032 | ||
|
|
babd8abc51 | ||
|
|
91f85e16b2 | ||
|
|
8a0c5e3dbd | ||
|
|
d40e012138 | ||
|
|
49b23f5240 | ||
|
|
043642ea5f | ||
|
|
91ea9820f9 | ||
|
|
fad0f57b13 | ||
|
|
2608e149a8 | ||
|
|
d21289acd6 | ||
|
|
a7b19e1d8a | ||
|
|
09c7aa9a5f | ||
|
|
f311c21327 | ||
|
|
535d0191da | ||
|
|
c00d4f9be4 | ||
|
|
db135ee5ad | ||
|
|
5eac4c2ad8 | ||
|
|
e23a1a6d09 | ||
|
|
3a78300a08 | ||
|
|
1d7390e7ae | ||
|
|
3c0940f657 | ||
|
|
6fb6195b16 | ||
|
|
2ff8587601 | ||
|
|
925bd26a70 | ||
|
|
ddea485f5f | ||
|
|
49de25feb8 | ||
|
|
08b55b8d79 | ||
|
|
59bca302b9 | ||
|
|
0d98f73c43 | ||
|
|
36670e0080 | ||
|
|
61672f9868 | ||
|
|
ddeca8eb99 | ||
|
|
6e8271b2f6 | ||
|
|
74a4938eb6 | ||
|
|
cb50f603cd | ||
|
|
9a524f00bc | ||
|
|
545df0b770 | ||
|
|
9409405769 | ||
|
|
7dc3bbdb01 | ||
|
|
f8f9de2645 | ||
|
|
467d7ede26 | ||
|
|
fc211ab2e7 | ||
|
|
536f8aab31 | ||
|
|
69b3fdffbe | ||
|
|
53fe72d89e | ||
|
|
e79c15c5da | ||
|
|
a4a427e174 | ||
|
|
b697bc5268 | ||
|
|
d35d7f0aec | ||
|
|
ed1c564fa2 | ||
|
|
7189d471c1 | ||
|
|
04080cc5ec | ||
|
|
3e5ab4af27 | ||
|
|
f06dddd2f7 | ||
|
|
7b4a71f55d | ||
|
|
d552b65618 | ||
|
|
f701b50244 | ||
|
|
199e502fbe | ||
|
|
6769779189 | ||
|
|
4b43c3986c | ||
|
|
e1292772e6 | ||
|
|
37fb045431 | ||
|
|
c328df67a2 | ||
|
|
877cba7065 | ||
|
|
35a178b468 | ||
|
|
7327190471 | ||
|
|
e5b5e3d0c6 | ||
|
|
3760be088b | ||
|
|
5cb52eb8ec | ||
|
|
8a390a8edf | ||
|
|
d96ab5cdf3 | ||
|
|
3bf74671c6 | ||
|
|
a47ef6d7c4 | ||
|
|
84089fa528 | ||
|
|
72be44eea2 | ||
|
|
05d6c4b32d | ||
|
|
0c7e15d0a2 | ||
|
|
63efecf9d9 | ||
|
|
153ac3f1a4 | ||
|
|
115faa9f89 | ||
|
|
f183852961 | ||
|
|
34c3e01729 | ||
|
|
9b2b16199e | ||
|
|
9112c5f0ea | ||
|
|
50783dfd0a | ||
|
|
ca0ef76fe1 | ||
|
|
7c91c537e4 | ||
|
|
9747526664 | ||
|
|
31a0c7b02c | ||
|
|
c18fbacd1b | ||
|
|
b0fee6bbf1 | ||
|
|
f6cead6e92 | ||
|
|
05fc96edc0 | ||
|
|
6794a0b3be | ||
|
|
1a04fd736c | ||
|
|
1846203807 | ||
|
|
75be8658c1 | ||
|
|
91a5eebbaf | ||
|
|
c96f1e86ee | ||
|
|
8016c0886a | ||
|
|
8f216e64d8 | ||
|
|
e1f4486e01 | ||
|
|
b0d6272974 | ||
|
|
ef23b0807a | ||
|
|
ab7e25243d | ||
|
|
bf0ea14423 | ||
|
|
305dabd84b | ||
|
|
b6a3fa5081 | ||
|
|
73feadc4c4 | ||
|
|
aad0f4d62c | ||
|
|
602b0cc60e | ||
|
|
8511e762c8 | ||
|
|
b75d3068c9 | ||
|
|
461178e726 | ||
|
|
e0e4d47340 | ||
|
|
a595faa378 | ||
|
|
7fd1e1a3c3 | ||
|
|
7f6a3d349c | ||
|
|
50429ff535 | ||
|
|
3bf0ef8ea3 | ||
|
|
e9a5e83e36 | ||
|
|
86a64ac091 | ||
|
|
97e06b3ab3 | ||
|
|
09e833d910 | ||
|
|
8c4e12e54f | ||
|
|
2642bd71a4 | ||
|
|
c4feac916f | ||
|
|
2ec56f564e | ||
|
|
9399ddcb58 | ||
|
|
aebf4eda30 | ||
|
|
6b0bdfdf2f | ||
|
|
d214c3184f | ||
|
|
c335a508a3 | ||
|
|
d7797d5691 | ||
|
|
b81f3313cb | ||
|
|
49fe64744c | ||
|
|
106238cca5 | ||
|
|
01735ccf2f | ||
|
|
ce81cb8d24 | ||
|
|
c9d7a9046f | ||
|
|
a9ba383667 | ||
|
|
06b97bcb0f | ||
|
|
90152b36ef | ||
|
|
92484b7441 | ||
|
|
398904785b | ||
|
|
531fa21f88 | ||
|
|
904495d819 | ||
|
|
f13fc84853 | ||
|
|
e099bbb58f | ||
|
|
e60a2d2ba3 | ||
|
|
39d54050cc | ||
|
|
7618d334db | ||
|
|
71f20178d3 | ||
|
|
cb6ab2479f | ||
|
|
2212be341b | ||
|
|
5d2d921f31 | ||
|
|
acb2d0c7ce | ||
|
|
90d6048f52 | ||
|
|
e5985620c0 | ||
|
|
eb57f4d290 | ||
|
|
f0a1ab139c | ||
|
|
79289a7249 | ||
|
|
5998eebdca | ||
|
|
e6a7017b55 | ||
|
|
c8571af129 | ||
|
|
6144a9c164 | ||
|
|
68a7f2b0d4 | ||
|
|
0d1cd37097 | ||
|
|
3de8e5ff57 | ||
|
|
b4aad7991b | ||
|
|
8a5c5c1966 | ||
|
|
08a56d1a40 | ||
|
|
ba61f20334 | ||
|
|
10316d786e | ||
|
|
38cdc106cc | ||
|
|
410b99ef24 | ||
|
|
51db63f992 | ||
|
|
c86dceadde | ||
|
|
f56f98f40f | ||
|
|
12a36593aa | ||
|
|
8382491477 | ||
|
|
545d559e27 | ||
|
|
cc8963802f | ||
|
|
282d87f922 | ||
|
|
6a288c1db0 | ||
|
|
8650328e64 | ||
|
|
85fa6da5b5 | ||
|
|
e54e913fdd | ||
|
|
b088c0d7d9 | ||
|
|
f154a40692 | ||
|
|
0471b94ebe | ||
|
|
8279891dff | ||
|
|
f546ca998d | ||
|
|
bf229d0ab0 | ||
|
|
f08fedb8ca | ||
|
|
f3cc38089c | ||
|
|
fbed59e5de | ||
|
|
4f1685a365 | ||
|
|
2701af102a | ||
|
|
7f939b96d2 | ||
|
|
4d58ca6daf | ||
|
|
16dd7a2805 | ||
|
|
8f3e930004 | ||
|
|
3f4c444d82 | ||
|
|
fd7d8b8bcd | ||
|
|
46f833c7fa | ||
|
|
4eabfbe4b7 | ||
|
|
f3ab2baa6a | ||
|
|
fb412e2ddf | ||
|
|
f06f96a6f0 | ||
|
|
2988e800b1 | ||
|
|
dbfabeaddf | ||
|
|
c3188e40bb | ||
|
|
d0dfd07204 | ||
|
|
04a2466f54 | ||
|
|
0f9a9edc4d | ||
|
|
31a54f595b | ||
|
|
3560a6d4d9 | ||
|
|
be8053db4f | ||
|
|
4ffae38a3f | ||
|
|
9e74760c39 | ||
|
|
ced1a0ef0d | ||
|
|
1609d0b205 | ||
|
|
ef8ada2793 | ||
|
|
444ad2522f | ||
|
|
1caea60803 | ||
|
|
97c3588cfd | ||
|
|
da3aa5aadb | ||
|
|
2fe89f132c | ||
|
|
4bca840ba2 | ||
|
|
f858ccb781 | ||
|
|
3cf9894b44 | ||
|
|
436b15d648 | ||
|
|
c3b7ea4cd1 | ||
|
|
4b5430d61d | ||
|
|
9fc8fe8341 | ||
|
|
b31e40b8a5 | ||
|
|
62e1c69f69 | ||
|
|
bc68b672ac | ||
|
|
da1e279128 | ||
|
|
60bcfe07d7 | ||
|
|
d343c81088 | ||
|
|
706f6d5808 | ||
|
|
1b1a0f19d0 | ||
|
|
119ac50f7f | ||
|
|
cb479f04d5 | ||
|
|
7e21e0b666 | ||
|
|
dabdb5b584 | ||
|
|
f36ba027d0 | ||
|
|
08aae32975 | ||
|
|
4cfc730d92 | ||
|
|
4ef8538bcd | ||
|
|
16a746398f | ||
|
|
4a75f353ee | ||
|
|
bbff7963fd | ||
|
|
7b1d226403 | ||
|
|
95c29ce105 | ||
|
|
a46ae01d9c | ||
|
|
562dd0ac79 | ||
|
|
a0612bd1f9 | ||
|
|
2dcbf2b0f1 | ||
|
|
048b7e871e | ||
|
|
4cae96eacb | ||
|
|
1e57d00b55 | ||
|
|
4ead5ee417 | ||
|
|
a517f37473 | ||
|
|
3ac5a98e3a | ||
|
|
689fab6857 | ||
|
|
be3c484527 |
@@ -1 +0,0 @@
|
||||
test/*
|
||||
-126
@@ -1,126 +0,0 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true
|
||||
},
|
||||
"parserOptions": {
|
||||
"ecmaFeatures": {
|
||||
"jsx": false,
|
||||
"modules": false
|
||||
},
|
||||
"ecmaVersion": 2020
|
||||
},
|
||||
"plugins": ["promise"],
|
||||
"rules": {
|
||||
"promise/always-return": "error",
|
||||
"promise/no-return-wrap": "error",
|
||||
"promise/param-names": "error",
|
||||
"promise/catch-or-return": "error",
|
||||
"promise/no-native": "off",
|
||||
"promise/no-nesting": "warn",
|
||||
"promise/no-promise-in-callback": "warn",
|
||||
"promise/no-callback-in-promise": "warn",
|
||||
"promise/no-return-in-finally": "warn",
|
||||
|
||||
// Possible Errors
|
||||
// http://eslint.org/docs/rules/#possible-errors
|
||||
"comma-dangle": [2, "only-multiline"],
|
||||
"no-control-regex": 2,
|
||||
"no-debugger": 2,
|
||||
"no-dupe-args": 2,
|
||||
"no-dupe-keys": 2,
|
||||
"no-duplicate-case": 2,
|
||||
"no-empty-character-class": 2,
|
||||
"no-ex-assign": 2,
|
||||
"no-extra-boolean-cast" : 2,
|
||||
"no-extra-parens": [2, "functions"],
|
||||
"no-extra-semi": 2,
|
||||
"no-func-assign": 2,
|
||||
"no-invalid-regexp": 2,
|
||||
"no-irregular-whitespace": 2,
|
||||
"no-negated-in-lhs": 2,
|
||||
"no-obj-calls": 2,
|
||||
"no-proto": 2,
|
||||
"no-unexpected-multiline": 2,
|
||||
"no-unreachable": 2,
|
||||
"use-isnan": 2,
|
||||
"valid-typeof": 2,
|
||||
|
||||
// Best Practices
|
||||
// http://eslint.org/docs/rules/#best-practices
|
||||
"no-fallthrough": 2,
|
||||
"no-octal": 2,
|
||||
"no-redeclare": 2,
|
||||
"no-self-assign": 2,
|
||||
"no-unused-labels": 2,
|
||||
|
||||
// Strict Mode
|
||||
// http://eslint.org/docs/rules/#strict-mode
|
||||
"strict": [2, "never"],
|
||||
|
||||
// Variables
|
||||
// http://eslint.org/docs/rules/#variables
|
||||
"no-delete-var": 2,
|
||||
"no-undef": 2,
|
||||
"no-unused-vars": [2, {"args": "none"}],
|
||||
|
||||
// Node.js and CommonJS
|
||||
// http://eslint.org/docs/rules/#nodejs-and-commonjs
|
||||
"no-mixed-requires": 2,
|
||||
"no-new-require": 2,
|
||||
"no-path-concat": 2,
|
||||
"no-restricted-modules": [2, "sys", "_linklist"],
|
||||
|
||||
// Stylistic Issues
|
||||
// http://eslint.org/docs/rules/#stylistic-issues
|
||||
"comma-spacing": 2,
|
||||
"eol-last": 2,
|
||||
"indent": [2, 2, {"SwitchCase": 1}],
|
||||
"keyword-spacing": 2,
|
||||
"max-len": [2, 120, 2],
|
||||
"new-parens": 2,
|
||||
"no-mixed-spaces-and-tabs": 2,
|
||||
"no-multiple-empty-lines": [2, {"max": 2}],
|
||||
"no-trailing-spaces": [2, {"skipBlankLines": false }],
|
||||
"quotes": [2, "single", "avoid-escape"],
|
||||
"semi": 2,
|
||||
"space-before-blocks": [2, "always"],
|
||||
"space-before-function-paren": [2, "never"],
|
||||
"space-in-parens": [2, "never"],
|
||||
"space-infix-ops": 2,
|
||||
"space-unary-ops": 2,
|
||||
|
||||
// ECMAScript 6
|
||||
// http://eslint.org/docs/rules/#ecmascript-6
|
||||
"arrow-parens": [2, "always"],
|
||||
"arrow-spacing": [2, {"before": true, "after": true}],
|
||||
"constructor-super": 2,
|
||||
"no-class-assign": 2,
|
||||
"no-confusing-arrow": 2,
|
||||
"no-const-assign": 2,
|
||||
"no-dupe-class-members": 2,
|
||||
"no-new-symbol": 2,
|
||||
"no-this-before-super": 2,
|
||||
"prefer-const": 2
|
||||
},
|
||||
"globals": {
|
||||
"DTRACE_HTTP_CLIENT_REQUEST" : false,
|
||||
"LTTNG_HTTP_CLIENT_REQUEST" : false,
|
||||
"COUNTER_HTTP_CLIENT_REQUEST" : false,
|
||||
"DTRACE_HTTP_CLIENT_RESPONSE" : false,
|
||||
"LTTNG_HTTP_CLIENT_RESPONSE" : false,
|
||||
"COUNTER_HTTP_CLIENT_RESPONSE" : false,
|
||||
"DTRACE_HTTP_SERVER_REQUEST" : false,
|
||||
"LTTNG_HTTP_SERVER_REQUEST" : false,
|
||||
"COUNTER_HTTP_SERVER_REQUEST" : false,
|
||||
"DTRACE_HTTP_SERVER_RESPONSE" : false,
|
||||
"LTTNG_HTTP_SERVER_RESPONSE" : false,
|
||||
"COUNTER_HTTP_SERVER_RESPONSE" : false,
|
||||
"DTRACE_NET_STREAM_END" : false,
|
||||
"LTTNG_NET_STREAM_END" : false,
|
||||
"COUNTER_NET_SERVER_CONNECTION_CLOSE" : false,
|
||||
"DTRACE_NET_SERVER_CONNECTION" : false,
|
||||
"LTTNG_NET_SERVER_CONNECTION" : false,
|
||||
"COUNTER_NET_SERVER_CONNECTION" : false
|
||||
}
|
||||
}
|
||||
@@ -8,24 +8,29 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: lts/*
|
||||
node-version: '20'
|
||||
- run: npm install
|
||||
- run: npm run jslint
|
||||
- run: sudo apt update && sudo apt install -y squid
|
||||
- run: sudo cp test/squid.conf /etc/squid/squid.conf
|
||||
- run: sudo systemctl start squid
|
||||
- run: npm test
|
||||
env:
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
||||
AWS_REGION: ${{ secrets.AWS_REGION }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
GCP_JSON_KEY: ${{ secrets.GCP_JSON_KEY }}
|
||||
IBM_API_KEY: ${{ secrets.IBM_API_KEY }}
|
||||
IBM_TTS_API_KEY: ${{ secrets.IBM_TTS_API_KEY }}
|
||||
IBM_TTS_REGION: ${{ secrets.IBM_TTS_REGION }}
|
||||
|
||||
MICROSOFT_API_KEY: ${{ secrets.MICROSOFT_API_KEY }}
|
||||
MICROSOFT_REGION: ${{ secrets.MICROSOFT_REGION }}
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
ELEVENLABS_API_KEY: ${{ secrets.ELEVENLABS_API_KEY }}
|
||||
ELEVENLABS_VOICE_ID: ${{ secrets.ELEVENLABS_VOICE_ID }}
|
||||
ELEVENLABS_MODEL_ID: ${{ secrets.ELEVENLABS_MODEL_ID }}
|
||||
PLAYHT_USER_ID: ${{ secrets.PLAYHT_USER_ID }}
|
||||
PLAYHT_API_KEY: ${{ secrets.PLAYHT_API_KEY }}
|
||||
JAMBONES_HTTP_PROXY_IP: 127.0.0.1
|
||||
JAMBONES_HTTP_PROXY_PORT: 3128
|
||||
|
||||
@@ -12,8 +12,8 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: lts/*
|
||||
registry-url: 'https://registry.npmjs.org'
|
||||
|
||||
@@ -39,3 +39,5 @@ node_modules
|
||||
examples/*
|
||||
|
||||
.vscode
|
||||
|
||||
.env
|
||||
@@ -0,0 +1,3 @@
|
||||
#npm audit
|
||||
npm run jslint:fix || true
|
||||
npm test
|
||||
@@ -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,3 +1,3 @@
|
||||
# speech-utils
|
||||
# speech-utils 
|
||||
TTS-related speech utilities for jambonz.
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -0,0 +1,140 @@
|
||||
const promise = require('eslint-plugin-promise');
|
||||
const globals = require('globals');
|
||||
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
files: ['**/*.js', '*.js'],
|
||||
languageOptions: {
|
||||
|
||||
ecmaVersion: 2020,
|
||||
parserOptions: {
|
||||
'node': true,
|
||||
'es6': true,
|
||||
ecmaFeatures: {
|
||||
jsx: false,
|
||||
modules: false,
|
||||
}
|
||||
},
|
||||
sourceType: 'module',
|
||||
globals: {
|
||||
...globals.node,
|
||||
'DTRACE_HTTP_CLIENT_REQUEST': false,
|
||||
'LTTNG_HTTP_CLIENT_REQUEST': false,
|
||||
'COUNTER_HTTP_CLIENT_REQUEST': false,
|
||||
'DTRACE_HTTP_CLIENT_RESPONSE': false,
|
||||
'LTTNG_HTTP_CLIENT_RESPONSE': false,
|
||||
'COUNTER_HTTP_CLIENT_RESPONSE': false,
|
||||
'DTRACE_HTTP_SERVER_REQUEST': false,
|
||||
'LTTNG_HTTP_SERVER_REQUEST': false,
|
||||
'COUNTER_HTTP_SERVER_REQUEST': false,
|
||||
'DTRACE_HTTP_SERVER_RESPONSE': false,
|
||||
'LTTNG_HTTP_SERVER_RESPONSE': false,
|
||||
'COUNTER_HTTP_SERVER_RESPONSE': false,
|
||||
'DTRACE_NET_STREAM_END': false,
|
||||
'LTTNG_NET_STREAM_END': false,
|
||||
'COUNTER_NET_SERVER_CONNECTION_CLOSE': false,
|
||||
'DTRACE_NET_SERVER_CONNECTION': false,
|
||||
'LTTNG_NET_SERVER_CONNECTION': false,
|
||||
'COUNTER_NET_SERVER_CONNECTION': false
|
||||
},
|
||||
|
||||
},
|
||||
'plugins': {
|
||||
promise
|
||||
},
|
||||
'rules': {
|
||||
'promise/always-return': 'error',
|
||||
'promise/no-return-wrap': 'error',
|
||||
'promise/param-names': 'error',
|
||||
'promise/catch-or-return': 'error',
|
||||
'promise/no-native': 'off',
|
||||
'promise/no-nesting': 'warn',
|
||||
'promise/no-promise-in-callback': 'warn',
|
||||
'promise/no-callback-in-promise': 'warn',
|
||||
'promise/no-return-in-finally': 'warn',
|
||||
|
||||
// Possible Errors
|
||||
// http://eslint.org/docs/rules/#possible-errors
|
||||
'comma-dangle': [2, 'only-multiline'],
|
||||
'no-control-regex': 2,
|
||||
'no-debugger': 2,
|
||||
'no-dupe-args': 2,
|
||||
'no-dupe-keys': 2,
|
||||
'no-duplicate-case': 2,
|
||||
'no-empty-character-class': 2,
|
||||
'no-ex-assign': 2,
|
||||
'no-extra-boolean-cast': 2,
|
||||
'no-extra-parens': [2, 'functions'],
|
||||
'no-extra-semi': 2,
|
||||
'no-func-assign': 2,
|
||||
'no-invalid-regexp': 2,
|
||||
'no-irregular-whitespace': 2,
|
||||
'no-negated-in-lhs': 2,
|
||||
'no-obj-calls': 2,
|
||||
'no-proto': 2,
|
||||
'no-unexpected-multiline': 2,
|
||||
'no-unreachable': 2,
|
||||
'use-isnan': 2,
|
||||
'valid-typeof': 2,
|
||||
|
||||
// Best Practices
|
||||
// http://eslint.org/docs/rules/#best-practices
|
||||
'no-fallthrough': 2,
|
||||
'no-octal': 2,
|
||||
'no-redeclare': 2,
|
||||
'no-self-assign': 2,
|
||||
'no-unused-labels': 2,
|
||||
|
||||
// Strict Mode
|
||||
// http://eslint.org/docs/rules/#strict-mode
|
||||
'strict': [2, 'never'],
|
||||
|
||||
// Variables
|
||||
// http://eslint.org/docs/rules/#variables
|
||||
'no-delete-var': 2,
|
||||
'no-undef': 2,
|
||||
'no-unused-vars': [2, { 'args': 'none' }],
|
||||
|
||||
// Node.js and CommonJS
|
||||
// http://eslint.org/docs/rules/#nodejs-and-commonjs
|
||||
'no-mixed-requires': 2,
|
||||
'no-new-require': 2,
|
||||
'no-path-concat': 2,
|
||||
'no-restricted-modules': [2, 'sys', '_linklist'],
|
||||
|
||||
// Stylistic Issues
|
||||
// http://eslint.org/docs/rules/#stylistic-issues
|
||||
'comma-spacing': 2,
|
||||
'eol-last': 2,
|
||||
'indent': [2, 2, { 'SwitchCase': 1 }],
|
||||
'keyword-spacing': 2,
|
||||
'max-len': [2, 120, 2],
|
||||
'new-parens': 2,
|
||||
'no-mixed-spaces-and-tabs': 2,
|
||||
'no-multiple-empty-lines': [2, { 'max': 2 }],
|
||||
'no-trailing-spaces': [2, { 'skipBlankLines': false }],
|
||||
'quotes': [2, 'single', 'avoid-escape'],
|
||||
'semi': 2,
|
||||
'space-before-blocks': [2, 'always'],
|
||||
'space-before-function-paren': [2, 'never'],
|
||||
'space-in-parens': [2, 'never'],
|
||||
'space-infix-ops': 2,
|
||||
'space-unary-ops': 2,
|
||||
|
||||
// ECMAScript 6
|
||||
// http://eslint.org/docs/rules/#ecmascript-6
|
||||
'arrow-parens': [2, 'always'],
|
||||
'arrow-spacing': [2, { 'before': true, 'after': true }],
|
||||
'constructor-super': 2,
|
||||
'no-class-assign': 2,
|
||||
'no-confusing-arrow': 2,
|
||||
'no-const-assign': 2,
|
||||
'no-dupe-class-members': 2,
|
||||
'no-new-symbol': 2,
|
||||
'no-this-before-super': 2,
|
||||
'prefer-const': 2
|
||||
},
|
||||
'ignores': []
|
||||
}
|
||||
];
|
||||
@@ -2,22 +2,20 @@ const {noopLogger} = require('./lib/utils');
|
||||
|
||||
module.exports = (opts, logger) => {
|
||||
logger = logger || noopLogger;
|
||||
let client = opts.redis_client;
|
||||
const {
|
||||
client: redisClient,
|
||||
client,
|
||||
createHash,
|
||||
retrieveHash
|
||||
} = require('@jambonz/realtimedb-helpers')(opts, logger);
|
||||
client = opts.redis_client || redisClient;
|
||||
|
||||
return {
|
||||
client,
|
||||
getTtsSize: require('./lib/get-tts-size').bind(null, client, logger),
|
||||
purgeTtsCache: require('./lib/purge-tts-cache').bind(null, client, logger),
|
||||
synthAudio: require('./lib/synth-audio').bind(null, client, logger),
|
||||
getNuanceAccessToken: require('./lib/get-nuance-access-token').bind(null, client, logger),
|
||||
getIbmAccessToken: require('./lib/get-ibm-access-token').bind(null, client, logger),
|
||||
addFileToCache: require('./lib/add-file-to-cache').bind(null, client, logger),
|
||||
synthAudio: require('./lib/synth-audio').bind(null, client, createHash, retrieveHash, logger),
|
||||
|
||||
getAwsAuthToken: require('./lib/get-aws-sts-token').bind(null, logger, createHash, retrieveHash),
|
||||
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, logger),
|
||||
getTtsVoices: require('./lib/get-tts-voices').bind(null, client, createHash, retrieveHash, logger),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
const fs = require('fs/promises');
|
||||
const {noopLogger, makeSynthKey} = require('./utils');
|
||||
const {JAMBONES_TTS_CACHE_DURATION_MINS} = require('./config');
|
||||
const EXPIRES = JAMBONES_TTS_CACHE_DURATION_MINS;
|
||||
|
||||
function getExtensionAndSampleRate(path) {
|
||||
const match = path.match(/\.([^.]*)$/);
|
||||
if (!match) {
|
||||
//default should be wav file.
|
||||
return ['wav', 8000];
|
||||
}
|
||||
|
||||
const extension = match[1];
|
||||
const sampleRateMap = {
|
||||
r8: 8000,
|
||||
r16: 16000,
|
||||
r24: 24000,
|
||||
r44: 44100,
|
||||
r48: 48000,
|
||||
r96: 96000,
|
||||
};
|
||||
|
||||
const sampleRate = sampleRateMap[extension] || 8000;
|
||||
return [extension, sampleRate];
|
||||
}
|
||||
|
||||
async function addFileToCache(client, logger, path,
|
||||
{account_sid, vendor, language, voice, deploymentId, engine, model, text, instructions}) {
|
||||
let key;
|
||||
logger = logger || noopLogger;
|
||||
|
||||
try {
|
||||
key = makeSynthKey({
|
||||
account_sid,
|
||||
vendor,
|
||||
language: language || '',
|
||||
voice: voice || deploymentId,
|
||||
engine,
|
||||
model,
|
||||
text,
|
||||
instructions
|
||||
});
|
||||
const [extension, sampleRate] = getExtensionAndSampleRate(path);
|
||||
const audioBuffer = await fs.readFile(path);
|
||||
await client.setex(key, EXPIRES, JSON.stringify(
|
||||
{
|
||||
audioContent: audioBuffer.toString('base64'),
|
||||
extension,
|
||||
sampleRate
|
||||
}
|
||||
));
|
||||
} catch (err) {
|
||||
logger.error(err, 'addFileToCache: Error');
|
||||
return;
|
||||
}
|
||||
|
||||
logger.debug(`addFileToCache: added ${path} to cache with key ${key}`);
|
||||
return key;
|
||||
}
|
||||
|
||||
module.exports = addFileToCache;
|
||||
@@ -0,0 +1,27 @@
|
||||
const JAMBONES_TTS_TRIM_SILENCE = process.env.JAMBONES_TTS_TRIM_SILENCE;
|
||||
const JAMBONES_DISABLE_TTS_STREAMING = process.env.JAMBONES_DISABLE_TTS_STREAMING;
|
||||
const JAMBONES_DISABLE_AZURE_TTS_STREAMING = process.env.JAMBONES_DISABLE_AZURE_TTS_STREAMING;
|
||||
const JAMBONES_EAGERLY_PRE_CACHE_AUDIO = process.env.JAMBONES_EAGERLY_PRE_CACHE_AUDIO;
|
||||
const JAMBONES_AZURE_ENABLE_SSML = process.env.JAMBONES_AZURE_ENABLE_SSML;
|
||||
|
||||
const JAMBONES_HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP;
|
||||
const JAMBONES_HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT;
|
||||
const JAMBONES_TTS_CACHE_DURATION_MINS =
|
||||
(parseInt(process.env.JAMBONES_TTS_CACHE_DURATION_MINS) || 4 * 60) * 60; // cache tts for 4 hours
|
||||
|
||||
const TMP_FOLDER = process.env.JAMBONES_TMP_FOLDER || '/tmp';
|
||||
|
||||
const HTTP_TIMEOUT = 5000;
|
||||
|
||||
module.exports = {
|
||||
JAMBONES_TTS_TRIM_SILENCE,
|
||||
JAMBONES_DISABLE_TTS_STREAMING,
|
||||
JAMBONES_DISABLE_AZURE_TTS_STREAMING,
|
||||
JAMBONES_HTTP_PROXY_IP,
|
||||
JAMBONES_HTTP_PROXY_PORT,
|
||||
JAMBONES_TTS_CACHE_DURATION_MINS,
|
||||
JAMBONES_EAGERLY_PRE_CACHE_AUDIO,
|
||||
TMP_FOLDER,
|
||||
HTTP_TIMEOUT,
|
||||
JAMBONES_AZURE_ENABLE_SSML
|
||||
};
|
||||
+53
-20
@@ -1,38 +1,71 @@
|
||||
const { STSClient, GetSessionTokenCommand } = require('@aws-sdk/client-sts');
|
||||
const { STSClient, GetSessionTokenCommand, AssumeRoleCommand } = require('@aws-sdk/client-sts');
|
||||
const {makeAwsKey, noopLogger} = require('./utils');
|
||||
const debug = require('debug')('jambonz:speech-utils');
|
||||
const EXPIRY = 3600;
|
||||
const EXPIRY = process.env.AWS_STS_SESSION_DURATION || 3600;
|
||||
// by default reset aws session before expiry time 10 mins
|
||||
const CACHE_EXPIRY = process.env.AWS_STS_SESSION_RESET_EXPIRY || (EXPIRY - 600);
|
||||
|
||||
async function getAwsAuthToken(
|
||||
logger,
|
||||
createHash, retrieveHash,
|
||||
awsAccessKeyId, awsSecretAccessKey, awsRegion) {
|
||||
logger, createHash, retrieveHash,
|
||||
{speech_credential_sid, accessKeyId, secretAccessKey, region, roleArn}) {
|
||||
logger = logger || noopLogger;
|
||||
try {
|
||||
const key = makeAwsKey(awsAccessKeyId);
|
||||
// if incase instance profile is used, speech_credential_sid will be used as key to lookup cache
|
||||
const key = makeAwsKey(roleArn || accessKeyId || speech_credential_sid);
|
||||
const obj = await retrieveHash(key);
|
||||
if (obj) return {...obj, servedFromCache: true};
|
||||
|
||||
/* access token not found in cache, so generate it using STS */
|
||||
const stsClient = new STSClient({
|
||||
region: awsRegion,
|
||||
credentials: {
|
||||
accessKeyId: awsAccessKeyId,
|
||||
secretAccessKey: awsSecretAccessKey,
|
||||
let data;
|
||||
let expiry = CACHE_EXPIRY;
|
||||
if (roleArn) {
|
||||
const stsClient = new STSClient({ region });
|
||||
const roleToAssume = { RoleArn: roleArn, RoleSessionName: 'Jambonz_Speech', DurationSeconds: EXPIRY};
|
||||
const command = new AssumeRoleCommand(roleToAssume);
|
||||
|
||||
data = await stsClient.send(command);
|
||||
} else if (accessKeyId) {
|
||||
const stsClient = new STSClient({
|
||||
region,
|
||||
credentials: {
|
||||
accessKeyId,
|
||||
secretAccessKey,
|
||||
}
|
||||
});
|
||||
const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
|
||||
data = await stsClient.send(command);
|
||||
} else {
|
||||
// instance profile is used.
|
||||
const stsClient = new STSClient({ region });
|
||||
const cred = await stsClient.config.credentials();
|
||||
// method in the AWS SDK automatically fetches credentials using the default credential
|
||||
// provider chain. If the credentials come from an instance profile or an environment
|
||||
// variable, their expiration is controlled by AWS and not explicitly by our code.
|
||||
if (cred && cred.expiration) {
|
||||
const currentTime = new Date();
|
||||
const expiryTime = new Date(cred.expiration);
|
||||
const remainingTimeInSeconds = Math.round((expiryTime - currentTime) / 1000);
|
||||
expiry = remainingTimeInSeconds;
|
||||
}
|
||||
});
|
||||
const command = new GetSessionTokenCommand({DurationSeconds: EXPIRY});
|
||||
const data = await stsClient.send(command);
|
||||
data = {
|
||||
Credentials: {
|
||||
AccessKeyId: cred.accessKeyId,
|
||||
SecretAccessKey: cred.secretAccessKey,
|
||||
SessionToken: cred.sessionToken
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const credentials = {
|
||||
accessKeyId: data.Credentials.AccessKeyId,
|
||||
secretAccessKey: data.Credentials.SecretAccessKey,
|
||||
sessionToken: data.Credentials.SessionToken
|
||||
sessionToken: data.Credentials.SessionToken,
|
||||
securityToken: data.Credentials.SessionToken
|
||||
};
|
||||
|
||||
/* expire 10 minutes before the hour, so we don't lose the use of it during a call */
|
||||
createHash(key, credentials, EXPIRY - 600)
|
||||
.catch((err) => logger.error(err, `Error saving hash for key ${key}`));
|
||||
// Only cache if expiry is good
|
||||
if (expiry > 0) {
|
||||
createHash(key, credentials, expiry)
|
||||
.catch((err) => logger.error(err, `Error saving hash for key ${key}`));
|
||||
}
|
||||
|
||||
return {...credentials, servedFromCache: false};
|
||||
} catch (err) {
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
const formurlencoded = require('form-urlencoded');
|
||||
const {Pool} = require('undici');
|
||||
const pool = new Pool('https://iam.cloud.ibm.com');
|
||||
const {makeIbmKey, noopLogger} = require('./utils');
|
||||
const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||
const HTTP_TIMEOUT = 5000;
|
||||
|
||||
async function getIbmAccessToken(client, logger, apiKey) {
|
||||
logger = logger || noopLogger;
|
||||
try {
|
||||
const key = makeIbmKey(apiKey);
|
||||
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 Ibm */
|
||||
const payload = {
|
||||
grant_type: 'urn:ibm:params:oauth:grant-type:apikey',
|
||||
apikey: apiKey
|
||||
};
|
||||
const {statusCode, headers, body} = await pool.request({
|
||||
path: '/identity/token',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
},
|
||||
body: formurlencoded(payload),
|
||||
timeout: HTTP_TIMEOUT,
|
||||
followRedirects: false
|
||||
});
|
||||
|
||||
if (200 !== statusCode) {
|
||||
const json = await body.json();
|
||||
logger.debug({statusCode, headers, body: json}, 'error fetching access token from Ibm');
|
||||
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, 'getIbmAccessToken: Error retrieving Ibm access token');
|
||||
logger.error(err, 'getIbmAccessToken: Error retrieving Ibm access token for client_id ${clientId}');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = getIbmAccessToken;
|
||||
@@ -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 debug = require('debug')('jambonz:realtimedb-helpers');
|
||||
const HTTP_TIMEOUT = 5000;
|
||||
|
||||
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;
|
||||
+30
-97
@@ -1,103 +1,40 @@
|
||||
const assert = require('assert');
|
||||
const {noopLogger, createNuanceClient, createKryptonClient} = require('./utils');
|
||||
const getNuanceAccessToken = require('./get-nuance-access-token');
|
||||
const {GetVoicesRequest, Voice} = require('../stubs/nuance/synthesizer_pb');
|
||||
const TextToSpeechV1 = require('ibm-watson/text-to-speech/v1');
|
||||
const { IamAuthenticator } = require('ibm-watson/auth');
|
||||
const {noopLogger} = require('./utils');
|
||||
const ttsGoogle = require('@google-cloud/text-to-speech');
|
||||
const { PollyClient, DescribeVoicesCommand } = require('@aws-sdk/client-polly');
|
||||
|
||||
const getIbmVoices = async(client, logger, credentials) => {
|
||||
const {tts_region, tts_api_key} = credentials;
|
||||
console.log(`region: ${tts_region}, api_key: ${tts_api_key}`);
|
||||
|
||||
const textToSpeech = new TextToSpeechV1({
|
||||
authenticator: new IamAuthenticator({
|
||||
apikey: tts_api_key,
|
||||
}),
|
||||
serviceUrl: `https://api.${tts_region}.text-to-speech.watson.cloud.ibm.com`
|
||||
});
|
||||
|
||||
const voices = await textToSpeech.listVoices();
|
||||
return voices;
|
||||
};
|
||||
|
||||
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 getAwsAuthToken = require('./get-aws-sts-token');
|
||||
|
||||
const getGoogleVoices = async(_client, logger, credentials) => {
|
||||
const client = new ttsGoogle.TextToSpeechClient({credentials});
|
||||
return await client.listVoices();
|
||||
};
|
||||
|
||||
const getAwsVoices = async(_client, logger, credentials) => {
|
||||
const getAwsVoices = async(_client, createHash, retrieveHash, logger, credentials) => {
|
||||
try {
|
||||
const {region, accessKeyId, secretAccessKey} = credentials;
|
||||
const client = new PollyClient({
|
||||
region,
|
||||
credentials: {
|
||||
accessKeyId,
|
||||
secretAccessKey
|
||||
}
|
||||
});
|
||||
const command = new DescribeVoicesCommand({LanguageCode: 'en-US'});
|
||||
const {region, accessKeyId, secretAccessKey, roleArn} = credentials;
|
||||
let client = null;
|
||||
if (accessKeyId && secretAccessKey) {
|
||||
client = new PollyClient({
|
||||
region,
|
||||
credentials: {
|
||||
accessKeyId,
|
||||
secretAccessKey
|
||||
}
|
||||
});
|
||||
} else if (roleArn) {
|
||||
client = new PollyClient({
|
||||
region,
|
||||
credentials: await getAwsAuthToken(
|
||||
logger, createHash, retrieveHash,
|
||||
{
|
||||
region,
|
||||
roleArn
|
||||
}),
|
||||
});
|
||||
} else {
|
||||
client = new PollyClient({region});
|
||||
}
|
||||
const command = new DescribeVoicesCommand({});
|
||||
const response = await client.send(command);
|
||||
return response;
|
||||
} catch (err) {
|
||||
@@ -122,22 +59,18 @@ const getAwsVoices = async(_client, logger, credentials) => {
|
||||
* @returns object containing filepath to an mp3 file in the /tmp folder containing
|
||||
* the synthesized audio, and a variable indicating whether it was served from cache
|
||||
*/
|
||||
async function getTtsVoices(client, logger, {vendor, credentials}) {
|
||||
async function getTtsVoices(client, createHash, retrieveHash, logger, {vendor, credentials}) {
|
||||
logger = logger || noopLogger;
|
||||
|
||||
assert.ok(['nuance', 'ibm', 'google', 'aws', 'polly'].includes(vendor),
|
||||
assert.ok(['google', 'aws', 'polly'].includes(vendor),
|
||||
`getTtsVoices not supported for vendor ${vendor}`);
|
||||
|
||||
switch (vendor) {
|
||||
case 'nuance':
|
||||
return getNuanceVoices(client, logger, credentials);
|
||||
case 'ibm':
|
||||
return getIbmVoices(client, logger, credentials);
|
||||
case 'google':
|
||||
return getGoogleVoices(client, logger, credentials);
|
||||
case 'aws':
|
||||
case 'polly':
|
||||
return getAwsVoices(client, logger, credentials);
|
||||
return getAwsVoices(client, createHash, retrieveHash, logger, credentials);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ const debug = require('debug')('jambonz:realtimedb-helpers');
|
||||
* @returns {object} result - {error, purgedCount}
|
||||
*/
|
||||
async function purgeTtsCache(client, logger, {all, account_sid, vendor,
|
||||
language, voice, deploymentId, engine, text} = {all: true}) {
|
||||
language, voice, deploymentId, engine, model, text, instructions} = {all: true}) {
|
||||
logger = logger || noopLogger;
|
||||
|
||||
let purgedCount = 0, error;
|
||||
@@ -33,7 +33,9 @@ async function purgeTtsCache(client, logger, {all, account_sid, vendor,
|
||||
language: language || '',
|
||||
voice: voice || deploymentId,
|
||||
engine,
|
||||
model,
|
||||
text,
|
||||
instructions
|
||||
});
|
||||
purgedCount = await client.del(key);
|
||||
if (purgedCount === 0) error = 'Specified item not found';
|
||||
|
||||
+1218
-240
File diff suppressed because it is too large
Load Diff
+23
-98
@@ -1,112 +1,43 @@
|
||||
const crypto = require('crypto');
|
||||
const {SynthesizerClient} = require('../stubs/nuance/synthesizer_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 HTTP_TIMEOUT = 5000;
|
||||
const NUANCE_AUTH_ENDPOINT = 'tts.api.nuance.com:443';
|
||||
const grpc = require('@grpc/grpc-js');
|
||||
const formurlencoded = require('form-urlencoded');
|
||||
const { TMP_FOLDER } = 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({account_sid = '', vendor, language, voice, engine = '', text}) {
|
||||
function makeSynthKey({
|
||||
account_sid = '',
|
||||
vendor,
|
||||
language,
|
||||
voice,
|
||||
engine = '',
|
||||
model = '',
|
||||
text,
|
||||
instructions = '',
|
||||
}) {
|
||||
const hash = crypto.createHash('sha1');
|
||||
hash.update(`${language}:${vendor}:${voice}:${engine}:${text}`);
|
||||
return `tts${account_sid ? (':' + account_sid) : ''}:${hash.digest('hex')}`;
|
||||
hash.update(`${language}:${vendor}:${voice}:${engine}:${model}:${text}:${instructions}`);
|
||||
const hexHashKey = hash.digest('hex');
|
||||
const accountKey = account_sid ? `:${account_sid}` : '';
|
||||
const key = `tts${accountKey}:${hexHashKey}`;
|
||||
return key;
|
||||
}
|
||||
|
||||
function makeFilePath({key, salt = '', extension}) {
|
||||
return `${TMP_FOLDER}/${key.replace('tts:', `tts-${salt}`)}.${extension}`;
|
||||
}
|
||||
|
||||
|
||||
const noopLogger = {
|
||||
info: () => {},
|
||||
debug: () => {},
|
||||
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 makeIbmKey(apiKey) {
|
||||
const hash = crypto.createHash('sha1');
|
||||
hash.update(apiKey);
|
||||
return `ibm:${hash.digest('hex')}`;
|
||||
}
|
||||
|
||||
function makeAwsKey(awsAccessKeyId) {
|
||||
const hash = crypto.createHash('sha1');
|
||||
hash.update(awsAccessKeyId);
|
||||
return `aws:${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 client = new RivaSpeechSynthesisClient(rivaUri, grpc.credentials.createInsecure());
|
||||
return client;
|
||||
@@ -114,14 +45,8 @@ const createRivaClient = async(rivaUri) => {
|
||||
|
||||
module.exports = {
|
||||
makeSynthKey,
|
||||
makeNuanceKey,
|
||||
makeIbmKey,
|
||||
makeAwsKey,
|
||||
getNuanceAccessToken,
|
||||
createNuanceClient,
|
||||
createKryptonClient,
|
||||
createRivaClient,
|
||||
makeBasicAuthHeader,
|
||||
NUANCE_AUTH_ENDPOINT,
|
||||
noopLogger
|
||||
noopLogger,
|
||||
makeFilePath
|
||||
};
|
||||
|
||||
Generated
+4379
-4908
File diff suppressed because it is too large
Load Diff
+18
-16
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@jambonz/speech-utils",
|
||||
"version": "0.0.28",
|
||||
"version": "1.0.13",
|
||||
"description": "TTS-related speech utilities for jambonz",
|
||||
"main": "index.js",
|
||||
"author": "Dave Horton",
|
||||
@@ -12,7 +12,8 @@
|
||||
"test": "NODE_ENV=test node test/ ",
|
||||
"coverage": "nyc --reporter html --report-dir ./coverage npm run test",
|
||||
"jslint": "eslint index.js lib",
|
||||
"build": "./build_stubs.sh"
|
||||
"jslint:fix": "npm run jslint --fix",
|
||||
"prepare": "husky"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
@@ -24,26 +25,27 @@
|
||||
},
|
||||
"homepage": "https://github.com/jambonz/speech-utils#readme",
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-polly": "^3.359.0",
|
||||
"@aws-sdk/client-sts": "^3.458.0",
|
||||
"@google-cloud/text-to-speech": "^4.2.1",
|
||||
"@grpc/grpc-js": "^1.8.13",
|
||||
"23": "^0.0.0",
|
||||
"@aws-sdk/client-polly": "^3.496.0",
|
||||
"@aws-sdk/client-sts": "^3.496.0",
|
||||
"@cartesia/cartesia-js": "^2.2.7",
|
||||
"@google-cloud/text-to-speech": "^6.4.0",
|
||||
"@grpc/grpc-js": "^1.9.14",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.7",
|
||||
"bent": "^7.3.12",
|
||||
"debug": "^4.3.4",
|
||||
"form-urlencoded": "^6.1.0",
|
||||
"google-protobuf": "^3.21.2",
|
||||
"ibm-watson": "^8.0.0",
|
||||
"microsoft-cognitiveservices-speech-sdk": "1.32.0",
|
||||
"openai": "^4.16.2",
|
||||
"undici": "^5.21.0"
|
||||
"microsoft-cognitiveservices-speech-sdk": "^1.51.0",
|
||||
"openai": "^4.98.0",
|
||||
"undici": "^7.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"config": "^3.3.9",
|
||||
"eslint": "^8.33.0",
|
||||
"eslint-plugin-promise": "^6.1.1",
|
||||
"config": "^4.2.0",
|
||||
"eslint": "^9.3.0",
|
||||
"eslint-plugin-promise": "^6.2.0",
|
||||
"husky": "^9.0.11",
|
||||
"nyc": "^15.1.0",
|
||||
"pino": "^7.2.0",
|
||||
"tape": "^5.1.1"
|
||||
"pino": "^9.1.0",
|
||||
"tape": "^5.7.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
@@ -1 +1 @@
|
||||
// GENERATED CODE -- NO SERVICES IN PROTO
|
||||
// GENERATED CODE -- NO SERVICES IN PROTO
|
||||
|
||||
@@ -57,7 +57,7 @@ function deserialize_nvidia_riva_tts_SynthesizeSpeechResponse(buffer_arg) {
|
||||
var RivaSpeechSynthesisService = exports.RivaSpeechSynthesisService = {
|
||||
// Used to request text-to-speech from the service. Submit a request containing the
|
||||
// desired text and configuration, and receive audio bytes in the requested format.
|
||||
synthesize: {
|
||||
synthesize: {
|
||||
path: '/nvidia.riva.tts.RivaSpeechSynthesis/Synthesize',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
@@ -69,9 +69,9 @@ synthesize: {
|
||||
responseDeserialize: deserialize_nvidia_riva_tts_SynthesizeSpeechResponse,
|
||||
},
|
||||
// Used to request text-to-speech returned via stream as it becomes available.
|
||||
// Submit a SynthesizeSpeechRequest with desired text and configuration,
|
||||
// and receive stream of bytes in the requested format.
|
||||
synthesizeOnline: {
|
||||
// Submit a SynthesizeSpeechRequest with desired text and configuration,
|
||||
// and receive stream of bytes in the requested format.
|
||||
synthesizeOnline: {
|
||||
path: '/nvidia.riva.tts.RivaSpeechSynthesis/SynthesizeOnline',
|
||||
requestStream: false,
|
||||
responseStream: true,
|
||||
@@ -83,7 +83,7 @@ synthesizeOnline: {
|
||||
responseDeserialize: deserialize_nvidia_riva_tts_SynthesizeSpeechResponse,
|
||||
},
|
||||
// Enables clients to request the configuration of the current Synthesize service, or a specific model within the service.
|
||||
getRivaSynthesisConfig: {
|
||||
getRivaSynthesisConfig: {
|
||||
path: '/nvidia.riva.tts.RivaSpeechSynthesis/GetRivaSynthesisConfig',
|
||||
requestStream: false,
|
||||
responseStream: false,
|
||||
|
||||
+12
-4
@@ -19,14 +19,22 @@ test('AWS - create and cache auth token', async(t) => {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
|
||||
let obj = await getAwsAuthToken({
|
||||
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');
|
||||
t.ok(obj.sessionToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
|
||||
t.ok(obj.securityToken && !obj.servedFromCache, 'successfullY generated auth token from AWS');
|
||||
|
||||
await sleep(250);
|
||||
obj = await getAwsAuthToken(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY, process.env.AWS_REGION);
|
||||
obj = await getAwsAuthToken({
|
||||
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');
|
||||
t.ok(obj.sessionToken && obj.servedFromCache, 'successfully received access token from cache');
|
||||
t.ok(obj.securityToken && obj.servedFromCache, 'successfully received access token from cache');
|
||||
|
||||
await client.flushall();
|
||||
t.end();
|
||||
|
||||
@@ -2,7 +2,7 @@ const test = require('tape').test ;
|
||||
const exec = require('child_process').exec ;
|
||||
|
||||
test('starting docker network..', (t) => {
|
||||
exec(`docker-compose -f ${__dirname}/docker-compose-testbed.yaml up -d`, (err, stdout, stderr) => {
|
||||
exec(`docker compose -f ${__dirname}/docker-compose-testbed.yaml up -d`, (err, stdout, stderr) => {
|
||||
setTimeout(() => {
|
||||
t.end(err);
|
||||
}, 2000);
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ const exec = require('child_process').exec ;
|
||||
|
||||
test('stopping docker network..', (t) => {
|
||||
t.timeoutAfter(10000);
|
||||
exec(`docker-compose -f ${__dirname}/docker-compose-testbed.yaml down`, (err, stdout, stderr) => {
|
||||
exec(`docker compose -f ${__dirname}/docker-compose-testbed.yaml down`, (err, stdout, stderr) => {
|
||||
//console.log(`stderr: ${stderr}`);
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
-78
@@ -1,78 +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('IBM - create access key', async(t) => {
|
||||
const fn = require('..');
|
||||
const {client, getIbmAccessToken} = fn(opts, logger);
|
||||
|
||||
if (!process.env.IBM_API_KEY ) {
|
||||
t.pass('skipping IBM test since no IBM api_key provided');
|
||||
t.end();
|
||||
client.quit();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let obj = await getIbmAccessToken(process.env.IBM_API_KEY);
|
||||
//console.log({obj}, 'received access token from IBM');
|
||||
t.ok(obj.access_token && !obj.servedFromCache, 'successfull received access token from IBM');
|
||||
|
||||
obj = await getIbmAccessToken(process.env.IBM_API_KEY);
|
||||
//console.log({obj}, 'received access token from IBM - second request');
|
||||
t.ok(obj.access_token && obj.servedFromCache, 'successfully received access token from cache');
|
||||
|
||||
await client.flushall();
|
||||
t.end();
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
t.end(err);
|
||||
}
|
||||
client.quit();
|
||||
});
|
||||
|
||||
test('IBM - retrieve tts voices test', async(t) => {
|
||||
const fn = require('..');
|
||||
const {client, getTtsVoices} = fn(opts, logger);
|
||||
|
||||
if (!process.env.IBM_TTS_API_KEY || !process.env.IBM_TTS_REGION) {
|
||||
t.pass('skipping IBM test since no IBM api_key and/or region provided');
|
||||
t.end();
|
||||
client.quit();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const opts = {
|
||||
vendor: 'ibm',
|
||||
credentials: {
|
||||
tts_api_key: process.env.IBM_TTS_API_KEY,
|
||||
tts_region: process.env.IBM_TTS_REGION
|
||||
}
|
||||
};
|
||||
const obj = await getTtsVoices(opts);
|
||||
const {voices} = obj.result;
|
||||
//console.log(JSON.stringify(voices));
|
||||
t.ok(voices.length > 0 && voices[0].language,
|
||||
`GetVoices: successfully retrieved ${voices.length} voices from IBM`);
|
||||
|
||||
await client.flushall();
|
||||
|
||||
t.end();
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
t.end(err);
|
||||
}
|
||||
client.quit();
|
||||
});
|
||||
+1
-2
@@ -2,6 +2,5 @@ require('./docker_start');
|
||||
require('./synth');
|
||||
require('./list-voices');
|
||||
require('./aws');
|
||||
require('./ibm');
|
||||
require('./nuance');
|
||||
|
||||
require('./docker_stop');
|
||||
|
||||
@@ -12,138 +12,6 @@ const stats = {
|
||||
histogram: () => {}
|
||||
};
|
||||
|
||||
test('IBM - create access key', async(t) => {
|
||||
const fn = require('..');
|
||||
const {client, getIbmAccessToken} = fn(opts, logger);
|
||||
|
||||
if (!process.env.IBM_API_KEY ) {
|
||||
t.pass('skipping IBM test since no IBM api_key provided');
|
||||
t.end();
|
||||
client.quit();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
let obj = await getIbmAccessToken(process.env.IBM_API_KEY);
|
||||
//console.log({obj}, 'received access token from IBM');
|
||||
t.ok(obj.access_token && !obj.servedFromCache, 'successfull received access token from IBM');
|
||||
|
||||
obj = await getIbmAccessToken(process.env.IBM_API_KEY);
|
||||
//console.log({obj}, 'received access token from IBM - second request');
|
||||
t.ok(obj.access_token && obj.servedFromCache, 'successfully received access token from cache');
|
||||
|
||||
await client.flushall();
|
||||
t.end();
|
||||
}
|
||||
catch (err) {
|
||||
console.error(err);
|
||||
t.end(err);
|
||||
}
|
||||
client.quit();
|
||||
});
|
||||
|
||||
test('IBM - retrieve tts voices test', async(t) => {
|
||||
const fn = require('..');
|
||||
const {client, getTtsVoices} = fn(opts, logger);
|
||||
|
||||
if (!process.env.IBM_TTS_API_KEY || !process.env.IBM_TTS_REGION) {
|
||||
t.pass('skipping IBM test since no IBM api_key and/or region provided');
|
||||
t.end();
|
||||
client.quit();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const opts = {
|
||||
vendor: 'ibm',
|
||||
credentials: {
|
||||
tts_api_key: process.env.IBM_TTS_API_KEY,
|
||||
tts_region: process.env.IBM_TTS_REGION
|
||||
}
|
||||
};
|
||||
const obj = await getTtsVoices(opts);
|
||||
const {voices} = obj.result;
|
||||
//console.log(JSON.stringify(voices));
|
||||
t.ok(voices.length > 0 && voices[0].language,
|
||||
`GetVoices: successfully retrieved ${voices.length} voices from IBM`);
|
||||
|
||||
await client.flushall();
|
||||
|
||||
t.end();
|
||||
|
||||
}
|
||||
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) => {
|
||||
const fn = require('..');
|
||||
const {client, getTtsVoices} = fn(opts, logger);
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
#
|
||||
# Recommended minimum configuration:
|
||||
#
|
||||
|
||||
# Example rule allowing access from your local networks.
|
||||
# Adapt to list your (internal) IP networks from where browsing
|
||||
# should be allowed
|
||||
acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
|
||||
acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
|
||||
acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
|
||||
acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
|
||||
acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
|
||||
acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
|
||||
acl localnet src fc00::/7 # RFC 4193 local private network range
|
||||
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
|
||||
|
||||
acl SSL_ports port 443
|
||||
acl Safe_ports port 80 # http
|
||||
acl Safe_ports port 21 # ftp
|
||||
acl Safe_ports port 443 # https
|
||||
acl Safe_ports port 70 # gopher
|
||||
acl Safe_ports port 210 # wais
|
||||
acl Safe_ports port 1025-65535 # unregistered ports
|
||||
acl Safe_ports port 280 # http-mgmt
|
||||
acl Safe_ports port 488 # gss-http
|
||||
acl Safe_ports port 591 # filemaker
|
||||
acl Safe_ports port 777 # multiling http
|
||||
|
||||
#
|
||||
# Recommended minimum Access Permission configuration:
|
||||
#
|
||||
# Deny requests to certain unsafe ports
|
||||
http_access deny !Safe_ports
|
||||
|
||||
# Deny CONNECT to other than secure SSL ports
|
||||
http_access allow CONNECT !SSL_ports
|
||||
|
||||
# Only allow cachemgr access from localhost
|
||||
http_access allow localhost manager
|
||||
http_access deny manager
|
||||
|
||||
# This default configuration only allows localhost requests because a more
|
||||
# permissive Squid installation could introduce new attack vectors into the
|
||||
# network by proxying external TCP connections to unprotected services.
|
||||
http_access allow localhost
|
||||
|
||||
# The two deny rules below are unnecessary in this default configuration
|
||||
# because they are followed by a "deny all" rule. However, they may become
|
||||
# critically important when you start allowing external requests below them.
|
||||
|
||||
# Protect web applications running on the same server as Squid. They often
|
||||
# assume that only local users can access them at "localhost" ports.
|
||||
http_access deny to_localhost
|
||||
|
||||
# Protect cloud servers that provide local users with sensitive info about
|
||||
# their server via certain well-known link-local (a.k.a. APIPA) addresses.
|
||||
http_access deny to_linklocal
|
||||
|
||||
#
|
||||
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
|
||||
#
|
||||
|
||||
# For example, to allow access from your local networks, you may uncomment the
|
||||
# following rule (and/or add rules that match your definition of "local"):
|
||||
# http_access allow localnet
|
||||
|
||||
# And finally deny all other access to this proxy
|
||||
http_access deny all
|
||||
|
||||
# Squid normally listens to port 3128
|
||||
http_port 3128
|
||||
|
||||
# Uncomment and adjust the following to add a disk cache directory.
|
||||
#cache_dir ufs /usr/local/var/cache/squid 100 16 256
|
||||
|
||||
# Leave coredumps in the first cache dir
|
||||
coredump_dir /usr/local/var/cache/squid
|
||||
|
||||
#
|
||||
# Add any of your own refresh_pattern entries above these.
|
||||
#
|
||||
refresh_pattern ^ftp: 1440 20% 10080
|
||||
refresh_pattern ^gopher: 1440 0% 1440
|
||||
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
|
||||
refresh_pattern . 0 20% 4320
|
||||
+1000
-135
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user