@jambonz/speech-utils 0.0.31 → 0.0.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/ci.yml +5 -0
- package/README.md +1 -1
- package/lib/synth-audio.js +31 -3
- package/package.json +1 -1
- package/test/squid.conf +85 -0
- package/test/synth.js +30 -1
package/.github/workflows/ci.yml
CHANGED
|
@@ -14,6 +14,9 @@ jobs:
|
|
|
14
14
|
node-version: lts/*
|
|
15
15
|
- run: npm install
|
|
16
16
|
- run: npm run jslint
|
|
17
|
+
- run: sudo apt update && sudo apt install -y squid
|
|
18
|
+
- run: sudo cp test/squid.conf /etc/squid/squid.conf
|
|
19
|
+
- run: sudo systemctl start squid
|
|
17
20
|
- run: npm test
|
|
18
21
|
env:
|
|
19
22
|
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
|
|
@@ -29,3 +32,5 @@ jobs:
|
|
|
29
32
|
ELEVENLABS_API_KEY: ${{ secrets.ELEVENLABS_API_KEY }}
|
|
30
33
|
ELEVENLABS_VOICE_ID: ${{ secrets.ELEVENLABS_VOICE_ID }}
|
|
31
34
|
ELEVENLABS_MODEL_ID: ${{ secrets.ELEVENLABS_MODEL_ID }}
|
|
35
|
+
JAMBONES_HTTP_PROXY_IP: 127.0.0.1
|
|
36
|
+
JAMBONES_HTTP_PROXY_PORT: 3128
|
package/README.md
CHANGED
package/lib/synth-audio.js
CHANGED
|
@@ -84,7 +84,7 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|
|
84
84
|
logger = logger || noopLogger;
|
|
85
85
|
|
|
86
86
|
assert.ok(['google', 'aws', 'polly', 'microsoft',
|
|
87
|
-
'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs', 'whisper'].includes(vendor) ||
|
|
87
|
+
'wellsaid', 'nuance', 'nvidia', 'ibm', 'elevenlabs', 'whisper', 'deepgram'].includes(vendor) ||
|
|
88
88
|
vendor.startsWith('custom'),
|
|
89
89
|
`synthAudio supported vendors are google, aws, microsoft, nuance, nvidia and wellsaid, not ${vendor}`);
|
|
90
90
|
if ('google' === vendor) {
|
|
@@ -199,6 +199,9 @@ async function synthAudio(client, logger, stats, { account_sid,
|
|
|
199
199
|
case 'whisper':
|
|
200
200
|
audioBuffer = await synthWhisper(logger, {credentials, stats, voice, text});
|
|
201
201
|
break;
|
|
202
|
+
case 'deepgram':
|
|
203
|
+
audioBuffer = await synthDeepgram(logger, {credentials, stats, model, text});
|
|
204
|
+
break;
|
|
202
205
|
case vendor.startsWith('custom') ? vendor : 'cant_match_value':
|
|
203
206
|
({ audioBuffer, filePath } = await synthCustomVendor(logger,
|
|
204
207
|
{credentials, stats, language, voice, text, filePath}));
|
|
@@ -400,6 +403,12 @@ const synthMicrosoft = async(logger, {
|
|
|
400
403
|
speechConfig.speechSynthesisOutputFormat = trimSilence ?
|
|
401
404
|
SpeechSynthesisOutputFormat.Raw8Khz16BitMonoPcm :
|
|
402
405
|
SpeechSynthesisOutputFormat.Audio16Khz32KBitRateMonoMp3;
|
|
406
|
+
|
|
407
|
+
if (process.env.JAMBONES_HTTP_PROXY_IP && process.env.JAMBONES_HTTP_PROXY_PORT) {
|
|
408
|
+
logger.debug(
|
|
409
|
+
`synthMicrosoft: using proxy ${process.env.JAMBONES_HTTP_PROXY_IP}:${process.env.JAMBONES_HTTP_PROXY_PORT}`);
|
|
410
|
+
speechConfig.setProxy(process.env.JAMBONES_HTTP_PROXY_IP, process.env.JAMBONES_HTTP_PROXY_PORT);
|
|
411
|
+
}
|
|
403
412
|
const synthesizer = new SpeechSynthesizer(speechConfig);
|
|
404
413
|
|
|
405
414
|
if (content.startsWith('<speak>')) {
|
|
@@ -634,8 +643,27 @@ const synthWhisper = async(logger, {credentials, stats, voice, text}) => {
|
|
|
634
643
|
stats.increment('tts.count', ['vendor:openai', 'accepted:no']);
|
|
635
644
|
throw err;
|
|
636
645
|
}
|
|
637
|
-
}
|
|
638
|
-
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
const synthDeepgram = async(logger, {credentials, stats, model, text}) => {
|
|
649
|
+
const {api_key} = credentials;
|
|
650
|
+
try {
|
|
651
|
+
const post = bent('https://api.beta.deepgram.com', 'POST', 'buffer', {
|
|
652
|
+
'Authorization': `Token ${api_key}`,
|
|
653
|
+
'Accept': 'audio/mpeg',
|
|
654
|
+
'Content-Type': 'application/json'
|
|
655
|
+
});
|
|
656
|
+
const mp3 = await post(`/v1/speak?model=${model}`, {
|
|
657
|
+
text
|
|
658
|
+
});
|
|
659
|
+
return mp3;
|
|
660
|
+
} catch (err) {
|
|
661
|
+
logger.info({err}, 'synth Deepgram returned error');
|
|
662
|
+
stats.increment('tts.count', ['vendor:deepgram', 'accepted:no']);
|
|
663
|
+
throw err;
|
|
664
|
+
}
|
|
665
|
+
};
|
|
666
|
+
|
|
639
667
|
const getFileExtFromMime = (mime) => {
|
|
640
668
|
switch (mime) {
|
|
641
669
|
case 'audio/wav':
|
package/package.json
CHANGED
package/test/squid.conf
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Recommended minimum configuration:
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
# Example rule allowing access from your local networks.
|
|
6
|
+
# Adapt to list your (internal) IP networks from where browsing
|
|
7
|
+
# should be allowed
|
|
8
|
+
acl localnet src 0.0.0.1-0.255.255.255 # RFC 1122 "this" network (LAN)
|
|
9
|
+
acl localnet src 10.0.0.0/8 # RFC 1918 local private network (LAN)
|
|
10
|
+
acl localnet src 100.64.0.0/10 # RFC 6598 shared address space (CGN)
|
|
11
|
+
acl localnet src 169.254.0.0/16 # RFC 3927 link-local (directly plugged) machines
|
|
12
|
+
acl localnet src 172.16.0.0/12 # RFC 1918 local private network (LAN)
|
|
13
|
+
acl localnet src 192.168.0.0/16 # RFC 1918 local private network (LAN)
|
|
14
|
+
acl localnet src fc00::/7 # RFC 4193 local private network range
|
|
15
|
+
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
|
|
16
|
+
|
|
17
|
+
acl SSL_ports port 443
|
|
18
|
+
acl Safe_ports port 80 # http
|
|
19
|
+
acl Safe_ports port 21 # ftp
|
|
20
|
+
acl Safe_ports port 443 # https
|
|
21
|
+
acl Safe_ports port 70 # gopher
|
|
22
|
+
acl Safe_ports port 210 # wais
|
|
23
|
+
acl Safe_ports port 1025-65535 # unregistered ports
|
|
24
|
+
acl Safe_ports port 280 # http-mgmt
|
|
25
|
+
acl Safe_ports port 488 # gss-http
|
|
26
|
+
acl Safe_ports port 591 # filemaker
|
|
27
|
+
acl Safe_ports port 777 # multiling http
|
|
28
|
+
|
|
29
|
+
#
|
|
30
|
+
# Recommended minimum Access Permission configuration:
|
|
31
|
+
#
|
|
32
|
+
# Deny requests to certain unsafe ports
|
|
33
|
+
http_access deny !Safe_ports
|
|
34
|
+
|
|
35
|
+
# Deny CONNECT to other than secure SSL ports
|
|
36
|
+
http_access allow CONNECT !SSL_ports
|
|
37
|
+
|
|
38
|
+
# Only allow cachemgr access from localhost
|
|
39
|
+
http_access allow localhost manager
|
|
40
|
+
http_access deny manager
|
|
41
|
+
|
|
42
|
+
# This default configuration only allows localhost requests because a more
|
|
43
|
+
# permissive Squid installation could introduce new attack vectors into the
|
|
44
|
+
# network by proxying external TCP connections to unprotected services.
|
|
45
|
+
http_access allow localhost
|
|
46
|
+
|
|
47
|
+
# The two deny rules below are unnecessary in this default configuration
|
|
48
|
+
# because they are followed by a "deny all" rule. However, they may become
|
|
49
|
+
# critically important when you start allowing external requests below them.
|
|
50
|
+
|
|
51
|
+
# Protect web applications running on the same server as Squid. They often
|
|
52
|
+
# assume that only local users can access them at "localhost" ports.
|
|
53
|
+
http_access deny to_localhost
|
|
54
|
+
|
|
55
|
+
# Protect cloud servers that provide local users with sensitive info about
|
|
56
|
+
# their server via certain well-known link-local (a.k.a. APIPA) addresses.
|
|
57
|
+
http_access deny to_linklocal
|
|
58
|
+
|
|
59
|
+
#
|
|
60
|
+
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
|
|
61
|
+
#
|
|
62
|
+
|
|
63
|
+
# For example, to allow access from your local networks, you may uncomment the
|
|
64
|
+
# following rule (and/or add rules that match your definition of "local"):
|
|
65
|
+
# http_access allow localnet
|
|
66
|
+
|
|
67
|
+
# And finally deny all other access to this proxy
|
|
68
|
+
http_access deny all
|
|
69
|
+
|
|
70
|
+
# Squid normally listens to port 3128
|
|
71
|
+
http_port 3128
|
|
72
|
+
|
|
73
|
+
# Uncomment and adjust the following to add a disk cache directory.
|
|
74
|
+
#cache_dir ufs /usr/local/var/cache/squid 100 16 256
|
|
75
|
+
|
|
76
|
+
# Leave coredumps in the first cache dir
|
|
77
|
+
coredump_dir /usr/local/var/cache/squid
|
|
78
|
+
|
|
79
|
+
#
|
|
80
|
+
# Add any of your own refresh_pattern entries above these.
|
|
81
|
+
#
|
|
82
|
+
refresh_pattern ^ftp: 1440 20% 10080
|
|
83
|
+
refresh_pattern ^gopher: 1440 0% 1440
|
|
84
|
+
refresh_pattern -i (/cgi-bin/|\?) 0 0% 0
|
|
85
|
+
refresh_pattern . 0 20% 4320
|
package/test/synth.js
CHANGED
|
@@ -182,7 +182,9 @@ test('Azure speech synth tests', async(t) => {
|
|
|
182
182
|
text: longText,
|
|
183
183
|
});
|
|
184
184
|
t.ok(!opts.servedFromCache, `successfully synthesized microsoft audio to ${opts.filePath}`);
|
|
185
|
-
|
|
185
|
+
if (process.env.JAMBONES_HTTP_PROXY_IP && process.env.JAMBONES_HTTP_PROXY_PORT) {
|
|
186
|
+
t.pass('successfully used proxy to reach microsoft tts service');
|
|
187
|
+
}
|
|
186
188
|
|
|
187
189
|
opts = await synthAudio(stats, {
|
|
188
190
|
vendor: 'microsoft',
|
|
@@ -512,6 +514,33 @@ test('whisper speech synth tests', async(t) => {
|
|
|
512
514
|
client.quit();
|
|
513
515
|
})
|
|
514
516
|
|
|
517
|
+
test('Deepgram speech synth tests', async(t) => {
|
|
518
|
+
const fn = require('..');
|
|
519
|
+
const {synthAudio, client} = fn(opts, logger);
|
|
520
|
+
|
|
521
|
+
if (!process.env.DEEPGRAM_API_KEY) {
|
|
522
|
+
t.pass('skipping Deepgram speech synth tests since DEEPGRAM_API_KEY');
|
|
523
|
+
return t.end();
|
|
524
|
+
}
|
|
525
|
+
const text = 'Hi there and welcome to jambones!';
|
|
526
|
+
try {
|
|
527
|
+
let opts = await synthAudio(stats, {
|
|
528
|
+
vendor: 'deepgram',
|
|
529
|
+
credentials: {
|
|
530
|
+
api_key: process.env.DEEPGRAM_API_KEY
|
|
531
|
+
},
|
|
532
|
+
model: 'alpha-asteria-en-v2',
|
|
533
|
+
text,
|
|
534
|
+
});
|
|
535
|
+
t.ok(!opts.servedFromCache, `successfully synthesized deepgram audio to ${opts.filePath}`);
|
|
536
|
+
|
|
537
|
+
} catch (err) {
|
|
538
|
+
console.error(JSON.stringify(err));
|
|
539
|
+
t.end(err);
|
|
540
|
+
}
|
|
541
|
+
client.quit();
|
|
542
|
+
})
|
|
543
|
+
|
|
515
544
|
test('TTS Cache tests', async(t) => {
|
|
516
545
|
const fn = require('..');
|
|
517
546
|
const {purgeTtsCache, getTtsSize, client} = fn(opts, logger);
|