mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-02-10 08:21:33 +00:00
Compare commits
139 Commits
v0.8.5-2
...
v0.9.1-rc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5e19bf775 | ||
|
|
498dd64025 | ||
|
|
24b6d2464b | ||
|
|
cd5421120f | ||
|
|
d7c3a4a632 | ||
|
|
c53ad89154 | ||
|
|
10b98630d3 | ||
|
|
d132bdb92b | ||
|
|
6be3fd9b64 | ||
|
|
844b0cb05d | ||
|
|
c0b56d4fc6 | ||
|
|
d27de284e7 | ||
|
|
5e97847a2f | ||
|
|
17c379df47 | ||
|
|
e7bc0b0737 | ||
|
|
dfe623e78a | ||
|
|
56b8f0623b | ||
|
|
7bcbab5b74 | ||
|
|
44e6a3513d | ||
|
|
fad16144b9 | ||
|
|
6523a861c0 | ||
|
|
cff67f5e4c | ||
|
|
c77bd84e0e | ||
|
|
3cd7a619ad | ||
|
|
59cf02bd04 | ||
|
|
a18d55e9ab | ||
|
|
d474b9d604 | ||
|
|
8d2b60c284 | ||
|
|
9cf9d4f587 | ||
|
|
bd002ede48 | ||
|
|
1a2aa91973 | ||
|
|
e322b7d8d3 | ||
|
|
7da11df88e | ||
|
|
09cf1345f6 | ||
|
|
2595f527ff | ||
|
|
1d77c0cd20 | ||
|
|
9eab81268b | ||
|
|
ecf3d140d6 | ||
|
|
4a52be9171 | ||
|
|
9b722ae36d | ||
|
|
370b046fac | ||
|
|
fca391c32e | ||
|
|
043860c4a3 | ||
|
|
a021ee3112 | ||
|
|
8999c85a71 | ||
|
|
72147a8110 | ||
|
|
93d0e41e31 | ||
|
|
5b1d8a8ff3 | ||
|
|
ec58232b61 | ||
|
|
65c241bcd1 | ||
|
|
75b6f89e0c | ||
|
|
b80d39d205 | ||
|
|
40f70e3531 | ||
|
|
1914b88af9 | ||
|
|
c946a5d14d | ||
|
|
878578fe0f | ||
|
|
9b3be6c0b9 | ||
|
|
4ae661daea | ||
|
|
dbd3b59901 | ||
|
|
06b066a3f2 | ||
|
|
fc3655c9bd | ||
|
|
1b5f801830 | ||
|
|
d0ebe3f99f | ||
|
|
51a379998f | ||
|
|
c2ae42a456 | ||
|
|
c187685054 | ||
|
|
81234a583c | ||
|
|
206849fa25 | ||
|
|
662b6d3d95 | ||
|
|
5c070597cf | ||
|
|
42be9ff1ca | ||
|
|
f0533c881b | ||
|
|
c894369a13 | ||
|
|
565478cc0a | ||
|
|
cdd25ca33d | ||
|
|
ef2306e558 | ||
|
|
9c33a790bd | ||
|
|
9f9a9ec598 | ||
|
|
75566bb268 | ||
|
|
a55f81676b | ||
|
|
48a81072e8 | ||
|
|
74ede31cd3 | ||
|
|
048229f019 | ||
|
|
71e266ae32 | ||
|
|
5b607693dc | ||
|
|
0491c5ce25 | ||
|
|
a7fa2f95dd | ||
|
|
901e412343 | ||
|
|
e57c7ba90a | ||
|
|
b867395d87 | ||
|
|
1a80910f91 | ||
|
|
5d4f25622d | ||
|
|
aabf37e269 | ||
|
|
b45275789b | ||
|
|
6d5ef6a215 | ||
|
|
b423a51638 | ||
|
|
b4ff2ea702 | ||
|
|
f22d66dfd6 | ||
|
|
09a83e3a31 | ||
|
|
d3d494191f | ||
|
|
859e816a8e | ||
|
|
29bbcf1be0 | ||
|
|
6f6d7a06b0 | ||
|
|
a2ba80a9a3 | ||
|
|
9d70ed96a1 | ||
|
|
8173a306f7 | ||
|
|
2e69630544 | ||
|
|
15829139c1 | ||
|
|
2c48083c26 | ||
|
|
9d8291f892 | ||
|
|
3e8474867f | ||
|
|
9eb315ecd6 | ||
|
|
2ec1460b4e | ||
|
|
e30782ea7b | ||
|
|
83c1c07eb0 | ||
|
|
47fbc1a4a4 | ||
|
|
7474a359a4 | ||
|
|
30977b309c | ||
|
|
bcb4bf43bf | ||
|
|
077460d0e2 | ||
|
|
6629b45671 | ||
|
|
353a9c1917 | ||
|
|
230fe9ea11 | ||
|
|
bb81f9f3da | ||
|
|
a7673c1819 | ||
|
|
59248c7638 | ||
|
|
46755f909c | ||
|
|
4273196447 | ||
|
|
e5b60ca9b0 | ||
|
|
86a14daf79 | ||
|
|
c66ad39001 | ||
|
|
0a0cbd57ba | ||
|
|
eb2d90ffaa | ||
|
|
454ff7d1b8 | ||
|
|
7e349fe4e5 | ||
|
|
9478f3a1b8 | ||
|
|
a3c241b569 | ||
|
|
5a68563f96 | ||
|
|
1cdd0cf611 |
6
.github/workflows/build.yml
vendored
6
.github/workflows/build.yml
vendored
@@ -6,10 +6,10 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- uses: actions/setup-node@v3
|
- uses: actions/setup-node@v4
|
||||||
with:
|
with:
|
||||||
node-version: 18
|
node-version: 20
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run jslint
|
- run: npm run jslint
|
||||||
- run: docker pull drachtio/sipp
|
- run: docker pull drachtio/sipp
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -42,3 +42,4 @@ ecosystem.config.js
|
|||||||
test/credentials/*.json
|
test/credentials/*.json
|
||||||
run-tests.sh
|
run-tests.sh
|
||||||
run-coverage.sh
|
run-coverage.sh
|
||||||
|
.vscode
|
||||||
17
.vscode/launch.json
vendored
17
.vscode/launch.json
vendored
@@ -1,17 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"type": "node",
|
|
||||||
"request": "launch",
|
|
||||||
"name": "Launch Program",
|
|
||||||
"program": "${workspaceFolder}/test/index.js",
|
|
||||||
"env": {
|
|
||||||
"NODE_ENV": "test"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -40,6 +40,8 @@ Configuration is provided via environment variables:
|
|||||||
|JAMBONZ_RECORD_WS_BASE_URL| recording websocket URL to send the recording audio|no|
|
|JAMBONZ_RECORD_WS_BASE_URL| recording websocket URL to send the recording audio|no|
|
||||||
|JAMBONZ_RECORD_WS_USERNAME| recording websocket username|no|
|
|JAMBONZ_RECORD_WS_USERNAME| recording websocket username|no|
|
||||||
|JAMBONZ_RECORD_WS_PASSWORD| recording websocket password|no|
|
|JAMBONZ_RECORD_WS_PASSWORD| recording websocket password|no|
|
||||||
|
|ANCHOR_MEDIA_ALWAYS| keep media on media server|no|
|
||||||
|
|JAMBONZ_DISABLE_DIAL_PAI_HEADER| control P-Asserted-Identity header on B-Leg|no|
|
||||||
|
|
||||||
### running under pm2
|
### running under pm2
|
||||||
Typically, this application runs under [pm2](https://pm2.io) using an [ecosystem.config.js](https://pm2.keymetrics.io/docs/usage/application-declaration/) file similar to this:
|
Typically, this application runs under [pm2](https://pm2.io) using an [ecosystem.config.js](https://pm2.keymetrics.io/docs/usage/application-declaration/) file similar to this:
|
||||||
|
|||||||
2
app.js
2
app.js
@@ -109,7 +109,7 @@ const disconnect = () => {
|
|||||||
httpServer?.on('close', resolve);
|
httpServer?.on('close', resolve);
|
||||||
httpServer?.close();
|
httpServer?.close();
|
||||||
srf.disconnect();
|
srf.disconnect();
|
||||||
srf.locals.mediaservers.forEach((ms) => ms.disconnect());
|
srf.locals.mediaservers?.forEach((ms) => ms.disconnect());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
0
bin/k8s-pre-stop-hook.js
Executable file → Normal file
0
bin/k8s-pre-stop-hook.js
Executable file → Normal file
@@ -9,7 +9,112 @@
|
|||||||
"can't take your call",
|
"can't take your call",
|
||||||
"will get back to you",
|
"will get back to you",
|
||||||
"I'll get back to you",
|
"I'll get back to you",
|
||||||
"we are unable"
|
"we are unable",
|
||||||
|
"Unable to take your call now",
|
||||||
|
"I'll reply soon",
|
||||||
|
"I'll call back",
|
||||||
|
"I'll reach out to you as soon as possible",
|
||||||
|
"Leave a message",
|
||||||
|
"Away from phone",
|
||||||
|
"Not available now",
|
||||||
|
"I'll return call",
|
||||||
|
"On another call",
|
||||||
|
"Currently on another call",
|
||||||
|
"I will return call later",
|
||||||
|
"Busy please leave message",
|
||||||
|
"Message will be returned promptly",
|
||||||
|
"Currently unavailable to answer",
|
||||||
|
"Planning to return your call soon",
|
||||||
|
"Apologies for missing your call",
|
||||||
|
"Not by the phone at the moment",
|
||||||
|
"Expecting to return your call",
|
||||||
|
"Currently not accessible",
|
||||||
|
"Intend to call back",
|
||||||
|
"Appreciate your patience!",
|
||||||
|
"Engaged in another conversation",
|
||||||
|
"I Will respond promptly",
|
||||||
|
"Kindly leave a message",
|
||||||
|
"Currently occupied leave a message",
|
||||||
|
"Unfortunately unable to answer right now",
|
||||||
|
"Occupied at the moment",
|
||||||
|
"Not present leave a message",
|
||||||
|
"Regrettably unavailable kindly leave a message",
|
||||||
|
"Will ensure a prompt response to your message",
|
||||||
|
"Currently engaged",
|
||||||
|
"Will return your call at the earliest opportunity",
|
||||||
|
"Your message will receive my prompt attention",
|
||||||
|
"I'll respond as soon as I can",
|
||||||
|
"Your message is important please leave it after the beep",
|
||||||
|
"Away from the phone at the moment",
|
||||||
|
"Unable to answer right now",
|
||||||
|
"Engaged in another task",
|
||||||
|
"Not by the phone presently",
|
||||||
|
"I'll respond at my earliest convenience",
|
||||||
|
"Away from the phone momentarily",
|
||||||
|
"I'll return your call shortly",
|
||||||
|
"Currently not able to answer",
|
||||||
|
"Your message is important please leave it after the tone",
|
||||||
|
"I'm unable to take your call right now",
|
||||||
|
"Please leave your message for me",
|
||||||
|
"I'll get back to you soon",
|
||||||
|
"Your call has been missed",
|
||||||
|
"Please leave a detailed message for me to respond to",
|
||||||
|
"Leave a message I'll make sure to respond",
|
||||||
|
"Feel free to leave a message",
|
||||||
|
"Your call is important to me",
|
||||||
|
"I'll get back to you shortly",
|
||||||
|
"Your message will be attended to promptly",
|
||||||
|
"Not available at the moment",
|
||||||
|
"I'll be sure to get back to you",
|
||||||
|
"I'll call you back soon",
|
||||||
|
"I'll ensure a prompt response",
|
||||||
|
"Sorry for the inconvenience",
|
||||||
|
"I'll return your call",
|
||||||
|
"I'll make sure to get back to you",
|
||||||
|
"I'll call you back shortly",
|
||||||
|
"I'll return your call as soon as possible",
|
||||||
|
"Apologies for the inconvenience leave your message",
|
||||||
|
"Your call is appreciated",
|
||||||
|
"I'm unavailable to answer",
|
||||||
|
"I'm currently away",
|
||||||
|
"I'll return your call as soon as I can",
|
||||||
|
"I'm away from the phone",
|
||||||
|
"I'm currently unavailable to take your call",
|
||||||
|
"Sorry for missing your call",
|
||||||
|
"I'll ensure it receives my immediate attention",
|
||||||
|
"I'm away from the phone momentarily",
|
||||||
|
"I'll reach out to you shortly",
|
||||||
|
"Apologies for the inconvenience",
|
||||||
|
"Currently occupied",
|
||||||
|
"Unable to answer your call at the moment",
|
||||||
|
"I'll make sure to follow up with you",
|
||||||
|
"Sorry for not being available",
|
||||||
|
"I'll reach out to you as soon as I can",
|
||||||
|
"I'm currently engaged",
|
||||||
|
"I'm currently busy",
|
||||||
|
"I'm currently unavailable",
|
||||||
|
"I'll respond to you at my earliest convenience",
|
||||||
|
"Your message is appreciated",
|
||||||
|
"I'll get back to you promptly",
|
||||||
|
"I'll get back to you without delay",
|
||||||
|
"Currently away from the phone",
|
||||||
|
"I'll return your call at my earliest opportunity",
|
||||||
|
"Sorry for the missed call",
|
||||||
|
"I'll make sure to address your concerns",
|
||||||
|
"Please provide your details for a callback",
|
||||||
|
"I'll make every effort to respond promptly",
|
||||||
|
"I'll ensure it's attended to promptly",
|
||||||
|
"Away from the phone temporarily",
|
||||||
|
"I'll get back to you as soon as I return",
|
||||||
|
"Currently not in a position to answer your call",
|
||||||
|
"Your call cannot be answered at the moment",
|
||||||
|
"I'll ensure to respond as soon as I'm able",
|
||||||
|
"Your call is important please leave a message",
|
||||||
|
"Unable to answer right now please leave your message",
|
||||||
|
"Currently not accessible intending to return your call",
|
||||||
|
"I'll respond promptly to your message",
|
||||||
|
"leave a memo",
|
||||||
|
"please leave a memo"
|
||||||
],
|
],
|
||||||
"es-ES": [
|
"es-ES": [
|
||||||
"le pasamos la llamada",
|
"le pasamos la llamada",
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ The GCP credential is the JSON service key in stringified format.
|
|||||||
|
|
||||||
#### Install Docker
|
#### Install Docker
|
||||||
|
|
||||||
The test suite ralso equires [Docker](https://www.docker.com/) and docker-compose to be installed on your laptop. Docker is used to set up a network with all of the elements required to test the jambonz-feature-server in a black-box type of fashion.
|
The test suite also requires [Docker](https://www.docker.com/) and docker-compose to be installed on your laptop. Docker is used to set up a network with all of the elements required to test the jambonz-feature-server in a black-box type of fashion.
|
||||||
|
|
||||||
Once you have docker installed, you can optionally make sure everything Docker-wise is working properly by running this command from the project folder:
|
Once you have docker installed, you can optionally make sure everything Docker-wise is working properly by running this command from the project folder:
|
||||||
|
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ const HTTP_TIMEOUT = 10000;
|
|||||||
const HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP;
|
const HTTP_PROXY_IP = process.env.JAMBONES_HTTP_PROXY_IP;
|
||||||
const HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT;
|
const HTTP_PROXY_PORT = process.env.JAMBONES_HTTP_PROXY_PORT;
|
||||||
const HTTP_PROXY_PROTOCOL = process.env.JAMBONES_HTTP_PROXY_PROTOCOL || 'http';
|
const HTTP_PROXY_PROTOCOL = process.env.JAMBONES_HTTP_PROXY_PROTOCOL || 'http';
|
||||||
|
const HTTP_USER_AGENT_HEADER = process.env.JAMBONES_HTTP_USER_AGENT_HEADER || 'jambonz';
|
||||||
|
|
||||||
const OPTIONS_PING_INTERVAL = parseInt(process.env.OPTIONS_PING_INTERVAL, 10) || 30000;
|
const OPTIONS_PING_INTERVAL = parseInt(process.env.OPTIONS_PING_INTERVAL, 10) || 30000;
|
||||||
|
|
||||||
@@ -129,6 +130,10 @@ const JAMBONZ_RECORD_WS_PASSWORD = process.env.JAMBONZ_RECORD_WS_PASSWORD || pro
|
|||||||
const JAMBONZ_DISABLE_DIAL_PAI_HEADER = process.env.JAMBONZ_DISABLE_DIAL_PAI_HEADER || false;
|
const JAMBONZ_DISABLE_DIAL_PAI_HEADER = process.env.JAMBONZ_DISABLE_DIAL_PAI_HEADER || false;
|
||||||
const JAMBONES_DISABLE_DIRECT_P2P_CALL = process.env.JAMBONES_DISABLE_DIRECT_P2P_CALL || false;
|
const JAMBONES_DISABLE_DIRECT_P2P_CALL = process.env.JAMBONES_DISABLE_DIRECT_P2P_CALL || false;
|
||||||
|
|
||||||
|
const JAMBONES_EAGERLY_PRE_CACHE_AUDIO = parseInt(process.env.JAMBONES_EAGERLY_PRE_CACHE_AUDIO, 10) || 0;
|
||||||
|
|
||||||
|
const JAMBONES_USE_FREESWITCH_TIMER_FD = process.env.JAMBONES_USE_FREESWITCH_TIMER_FD;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
JAMBONES_MYSQL_HOST,
|
JAMBONES_MYSQL_HOST,
|
||||||
JAMBONES_MYSQL_USER,
|
JAMBONES_MYSQL_USER,
|
||||||
@@ -151,6 +156,7 @@ module.exports = {
|
|||||||
JAMBONES_API_BASE_URL,
|
JAMBONES_API_BASE_URL,
|
||||||
JAMBONES_TIME_SERIES_HOST,
|
JAMBONES_TIME_SERIES_HOST,
|
||||||
JAMBONES_INJECT_CONTENT,
|
JAMBONES_INJECT_CONTENT,
|
||||||
|
JAMBONES_EAGERLY_PRE_CACHE_AUDIO,
|
||||||
JAMBONES_ESL_LISTEN_ADDRESS,
|
JAMBONES_ESL_LISTEN_ADDRESS,
|
||||||
JAMBONES_SBCS,
|
JAMBONES_SBCS,
|
||||||
JAMBONES_OTEL_ENABLED,
|
JAMBONES_OTEL_ENABLED,
|
||||||
@@ -193,6 +199,7 @@ module.exports = {
|
|||||||
HTTP_PROXY_IP,
|
HTTP_PROXY_IP,
|
||||||
HTTP_PROXY_PORT,
|
HTTP_PROXY_PORT,
|
||||||
HTTP_PROXY_PROTOCOL,
|
HTTP_PROXY_PROTOCOL,
|
||||||
|
HTTP_USER_AGENT_HEADER,
|
||||||
OPTIONS_PING_INTERVAL,
|
OPTIONS_PING_INTERVAL,
|
||||||
RESPONSE_TIMEOUT_MS,
|
RESPONSE_TIMEOUT_MS,
|
||||||
JAMBONES_WS_HANDSHAKE_TIMEOUT_MS,
|
JAMBONES_WS_HANDSHAKE_TIMEOUT_MS,
|
||||||
@@ -208,5 +215,6 @@ module.exports = {
|
|||||||
JAMBONZ_RECORD_WS_USERNAME,
|
JAMBONZ_RECORD_WS_USERNAME,
|
||||||
JAMBONZ_RECORD_WS_PASSWORD,
|
JAMBONZ_RECORD_WS_PASSWORD,
|
||||||
JAMBONZ_DISABLE_DIAL_PAI_HEADER,
|
JAMBONZ_DISABLE_DIAL_PAI_HEADER,
|
||||||
JAMBONES_DISABLE_DIRECT_P2P_CALL
|
JAMBONES_DISABLE_DIRECT_P2P_CALL,
|
||||||
|
JAMBONES_USE_FREESWITCH_TIMER_FD
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -30,6 +30,20 @@ const appsMap = {
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
}]
|
}]
|
||||||
|
},
|
||||||
|
conference: {
|
||||||
|
// Dummy hook to follow later feature server logic.
|
||||||
|
call_hook: {
|
||||||
|
url: 'https://jambonz.org',
|
||||||
|
method: 'GET'
|
||||||
|
},
|
||||||
|
account_sid: '',
|
||||||
|
app_json: [{
|
||||||
|
verb: 'conference',
|
||||||
|
name: '',
|
||||||
|
beep: false,
|
||||||
|
startConferenceOnEnter: true
|
||||||
|
}]
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -38,6 +52,7 @@ const createJambonzApp = (type, {account_sid, name, caller_id}) => {
|
|||||||
app.account_sid = account_sid;
|
app.account_sid = account_sid;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'queue':
|
case 'queue':
|
||||||
|
case 'conference':
|
||||||
app.app_json[0].name = name;
|
app.app_json[0].name = name;
|
||||||
break;
|
break;
|
||||||
case 'user':
|
case 'user':
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const CallInfo = require('../../session/call-info');
|
|||||||
const {CallDirection, CallStatus} = require('../../utils/constants');
|
const {CallDirection, CallStatus} = require('../../utils/constants');
|
||||||
const uuidv4 = require('uuid-random');
|
const uuidv4 = require('uuid-random');
|
||||||
const SipError = require('drachtio-srf').SipError;
|
const SipError = require('drachtio-srf').SipError;
|
||||||
const { validationResult } = require('express-validator');
|
const { validationResult, body } = require('express-validator');
|
||||||
const { validate } = require('@jambonz/verb-specifications');
|
const { validate } = require('@jambonz/verb-specifications');
|
||||||
const sysError = require('./error');
|
const sysError = require('./error');
|
||||||
const HttpRequestor = require('../../utils/http-requestor');
|
const HttpRequestor = require('../../utils/http-requestor');
|
||||||
@@ -13,7 +13,7 @@ const WsRequestor = require('../../utils/ws-requestor');
|
|||||||
const RootSpan = require('../../utils/call-tracer');
|
const RootSpan = require('../../utils/call-tracer');
|
||||||
const dbUtils = require('../../utils/db-utils');
|
const dbUtils = require('../../utils/db-utils');
|
||||||
const { mergeSdpMedia, extractSdpMedia } = require('../../utils/sdp-utils');
|
const { mergeSdpMedia, extractSdpMedia } = require('../../utils/sdp-utils');
|
||||||
const { createCallSchema } = require('../schemas/create-call');
|
const { createCallSchema, customSanitizeFunction } = require('../schemas/create-call');
|
||||||
|
|
||||||
const removeNullProperties = (obj) => (Object.keys(obj).forEach((key) => obj[key] === null && delete obj[key]), obj);
|
const removeNullProperties = (obj) => (Object.keys(obj).forEach((key) => obj[key] === null && delete obj[key]), obj);
|
||||||
const removeNulls = (req, res, next) => {
|
const removeNulls = (req, res, next) => {
|
||||||
@@ -24,6 +24,12 @@ const removeNulls = (req, res, next) => {
|
|||||||
router.post('/',
|
router.post('/',
|
||||||
removeNulls,
|
removeNulls,
|
||||||
createCallSchema,
|
createCallSchema,
|
||||||
|
body('tag').custom((value) => {
|
||||||
|
if (value) {
|
||||||
|
customSanitizeFunction(value);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}),
|
||||||
async(req, res) => {
|
async(req, res) => {
|
||||||
const {logger} = req.app.locals;
|
const {logger} = req.app.locals;
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ function retrieveCallSession(callSid, opts) {
|
|||||||
router.post('/:callSid', async(req, res) => {
|
router.post('/:callSid', async(req, res) => {
|
||||||
const logger = req.app.locals.logger;
|
const logger = req.app.locals.logger;
|
||||||
const callSid = req.params.callSid;
|
const callSid = req.params.callSid;
|
||||||
logger.debug({body: req.body}, 'got upateCall request');
|
logger.debug({body: req.body}, 'got updateCall request');
|
||||||
try {
|
try {
|
||||||
const cs = retrieveCallSession(callSid, req.body);
|
const cs = retrieveCallSession(callSid, req.body);
|
||||||
if (!cs) {
|
if (!cs) {
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ const createCallSchema = checkSchema({
|
|||||||
optional: true,
|
optional: true,
|
||||||
errorMessage: 'Invalid tag',
|
errorMessage: 'Invalid tag',
|
||||||
},
|
},
|
||||||
'tag.*': {
|
|
||||||
trim: true,
|
|
||||||
escape: true,
|
|
||||||
stripLow: true,
|
|
||||||
},
|
|
||||||
app_json: {
|
app_json: {
|
||||||
isString: true,
|
isString: true,
|
||||||
optional: true,
|
optional: true,
|
||||||
@@ -109,6 +104,31 @@ const createCallSchema = checkSchema({
|
|||||||
}
|
}
|
||||||
}, ['body']);
|
}, ['body']);
|
||||||
|
|
||||||
module.exports = {
|
const customSanitizeFunction = (value) => {
|
||||||
createCallSchema
|
try {
|
||||||
|
if (Array.isArray(value)) {
|
||||||
|
value = value.map((item) => customSanitizeFunction(item));
|
||||||
|
} else if (typeof value === 'object') {
|
||||||
|
Object.keys(value).forEach((key) => {
|
||||||
|
value[key] = customSanitizeFunction(value[key]);
|
||||||
|
});
|
||||||
|
} else if (typeof value === 'string') {
|
||||||
|
/* trims characters at the beginning and at the end of a string */
|
||||||
|
value = value.trim();
|
||||||
|
|
||||||
|
/* Verify strings including 'http' via new URL */
|
||||||
|
if (value.includes('http')) {
|
||||||
|
value = new URL(value).toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
value = `Error: ${error.message}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
createCallSchema,
|
||||||
|
customSanitizeFunction
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,14 +52,20 @@ module.exports = function(srf, logger) {
|
|||||||
let clientDb = null;
|
let clientDb = null;
|
||||||
if (req.has('X-Authenticated-User')) {
|
if (req.has('X-Authenticated-User')) {
|
||||||
req.locals.originatingUser = req.get('X-Authenticated-User');
|
req.locals.originatingUser = req.get('X-Authenticated-User');
|
||||||
|
let clientSettings;
|
||||||
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
|
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
|
||||||
if (arr) {
|
if (arr) {
|
||||||
[clientDb] = await lookupClientByAccountAndUsername(account_sid, arr[1]);
|
[clientSettings] = await lookupClientByAccountAndUsername(account_sid, arr[1]);
|
||||||
}
|
}
|
||||||
|
clientDb = await registrar.query(req.locals.originatingUser);
|
||||||
|
clientDb = {
|
||||||
|
...clientDb,
|
||||||
|
...clientSettings,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for call to application
|
// check for call to application
|
||||||
if (uri.user?.startsWith('app-') && req.locals.originatingUser && clientDb.allow_direct_app_calling) {
|
if (uri.user?.startsWith('app-') && req.locals.originatingUser && clientDb?.allow_direct_app_calling) {
|
||||||
const application_sid = uri.user.match(/app-(.*)/)[1];
|
const application_sid = uri.user.match(/app-(.*)/)[1];
|
||||||
logger.debug(`got application from Request URI header: ${application_sid}`);
|
logger.debug(`got application from Request URI header: ${application_sid}`);
|
||||||
req.locals.application_sid = application_sid;
|
req.locals.application_sid = application_sid;
|
||||||
@@ -69,13 +75,19 @@ module.exports = function(srf, logger) {
|
|||||||
req.locals.application_sid = application_sid;
|
req.locals.application_sid = application_sid;
|
||||||
}
|
}
|
||||||
// check for call to queue
|
// check for call to queue
|
||||||
if (uri.user?.startsWith('queue-') && req.locals.originatingUser && clientDb.allow_direct_queue_calling) {
|
else if (uri.user?.startsWith('queue-') && req.locals.originatingUser && clientDb?.allow_direct_queue_calling) {
|
||||||
const queue_name = uri.user.match(/queue-(.*)/)[1];
|
const queue_name = uri.user.match(/queue-(.*)/)[1];
|
||||||
logger.debug(`got Queue from Request URI header: ${queue_name}`);
|
logger.debug(`got Queue from Request URI header: ${queue_name}`);
|
||||||
req.locals.queue_name = queue_name;
|
req.locals.queue_name = queue_name;
|
||||||
}
|
}
|
||||||
|
// check for call to conference
|
||||||
|
else if (uri.user?.startsWith('conference-') && req.locals.originatingUser && clientDb?.allow_direct_app_calling) {
|
||||||
|
const conference_id = uri.user.match(/conference-(.*)/)[1];
|
||||||
|
logger.debug(`got Conference from Request URI header: ${conference_id}`);
|
||||||
|
req.locals.conference_id = conference_id;
|
||||||
|
}
|
||||||
// check for call to registered user
|
// check for call to registered user
|
||||||
if (!JAMBONES_DISABLE_DIRECT_P2P_CALL && req.locals.originatingUser && clientDb.allow_direct_user_calling) {
|
else if (!JAMBONES_DISABLE_DIRECT_P2P_CALL && req.locals.originatingUser && clientDb?.allow_direct_user_calling) {
|
||||||
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
|
const arr = /^(.*)@(.*)/.exec(req.locals.originatingUser);
|
||||||
if (arr) {
|
if (arr) {
|
||||||
const sipRealm = arr[2];
|
const sipRealm = arr[2];
|
||||||
@@ -91,7 +103,7 @@ module.exports = function(srf, logger) {
|
|||||||
if (req.has('X-MS-Teams-Tenant-FQDN')) req.locals.msTeamsTenant = req.get('X-MS-Teams-Tenant-FQDN');
|
if (req.has('X-MS-Teams-Tenant-FQDN')) req.locals.msTeamsTenant = req.get('X-MS-Teams-Tenant-FQDN');
|
||||||
if (req.has('X-Cisco-Recording-Participant')) {
|
if (req.has('X-Cisco-Recording-Participant')) {
|
||||||
const ciscoParticipants = req.get('X-Cisco-Recording-Participant');
|
const ciscoParticipants = req.get('X-Cisco-Recording-Participant');
|
||||||
const regex = /sip:[\d]+@[\d]+\.[\d]+\.[\d]+\.[\d]+/g;
|
const regex = /sip:[a-zA-Z0-9]+@[a-zA-Z0-9.-_]+/g;
|
||||||
const sipURIs = ciscoParticipants.match(regex);
|
const sipURIs = ciscoParticipants.match(regex);
|
||||||
logger.info(`X-Cisco-Recording-Participant : ${sipURIs} `);
|
logger.info(`X-Cisco-Recording-Participant : ${sipURIs} `);
|
||||||
if (sipURIs && sipURIs.length > 0) {
|
if (sipURIs && sipURIs.length > 0) {
|
||||||
@@ -160,7 +172,7 @@ module.exports = function(srf, logger) {
|
|||||||
};
|
};
|
||||||
logger.info({callId, metadata, sdp}, 'successfully parsed SIPREC payload');
|
logger.info({callId, metadata, sdp}, 'successfully parsed SIPREC payload');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.info({callId}, 'Error parsing multipart payload');
|
logger.info({err, callId}, 'Error parsing multipart payload');
|
||||||
return res.send(503);
|
return res.send(503);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -231,6 +243,9 @@ module.exports = function(srf, logger) {
|
|||||||
logger.debug(`calling to registered user ${req.locals.called_user}, generating dial app`);
|
logger.debug(`calling to registered user ${req.locals.called_user}, generating dial app`);
|
||||||
app = createJambonzApp('user',
|
app = createJambonzApp('user',
|
||||||
{account_sid, name: req.locals.called_user, caller_id: req.locals.callingNumber});
|
{account_sid, name: req.locals.called_user, caller_id: req.locals.callingNumber});
|
||||||
|
} else if (req.locals.conference_id) {
|
||||||
|
logger.debug(`calling to conference ${req.locals.conference_id}, generating conference app`);
|
||||||
|
app = createJambonzApp('conference', {account_sid, name: req.locals.conference_id});
|
||||||
} else if (req.locals.application_sid) {
|
} else if (req.locals.application_sid) {
|
||||||
app = await lookupAppBySid(req.locals.application_sid);
|
app = await lookupAppBySid(req.locals.application_sid);
|
||||||
} else if (req.locals.originatingUser) {
|
} else if (req.locals.originatingUser) {
|
||||||
@@ -376,7 +391,7 @@ module.exports = function(srf, logger) {
|
|||||||
},
|
},
|
||||||
recognizer: {
|
recognizer: {
|
||||||
vendor: app.speech_recognizer_vendor,
|
vendor: app.speech_recognizer_vendor,
|
||||||
...(app.speech_synthesis_label && {label: app.speech_synthesis_label}),
|
...(app.speech_recognizer_label && {label: app.speech_recognizer_label}),
|
||||||
language: app.speech_recognizer_language,
|
language: app.speech_recognizer_language,
|
||||||
...(app.fallback_speech_recognizer_vendor && {fallback_vendor: app.fallback_speech_recognizer_vendor}),
|
...(app.fallback_speech_recognizer_vendor && {fallback_vendor: app.fallback_speech_recognizer_vendor}),
|
||||||
...(app.fallback_speech_recognizer_label && {fallback_label: app.fallback_speech_recognizer_label}),
|
...(app.fallback_speech_recognizer_label && {fallback_label: app.fallback_speech_recognizer_label}),
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
const CallSession = require('./call-session');
|
const CallSession = require('./call-session');
|
||||||
|
const {CallStatus} = require('../utils/constants');
|
||||||
|
const moment = require('moment');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @classdesc Subclass of CallSession. Represents a CallSession
|
* @classdesc Subclass of CallSession. Represents a CallSession
|
||||||
@@ -19,12 +21,14 @@ class AdultingCallSession extends CallSession {
|
|||||||
rootSpan
|
rootSpan
|
||||||
});
|
});
|
||||||
this.sd = singleDialer;
|
this.sd = singleDialer;
|
||||||
|
this.req = callInfo.req;
|
||||||
|
|
||||||
this.sd.dlg.on('destroy', () => {
|
this.sd.dlg.on('destroy', () => {
|
||||||
this.logger.info('AdultingCallSession: called party hung up');
|
this.logger.info('AdultingCallSession: called party hung up');
|
||||||
this._callReleased();
|
this._callReleased();
|
||||||
});
|
});
|
||||||
this.sd.emit('adulting');
|
this.sd.emit('adulting');
|
||||||
|
this.on('callStatusChange', this._notifyCallStatusChange.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
get dlg() {
|
get dlg() {
|
||||||
@@ -49,6 +53,26 @@ class AdultingCallSession extends CallSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_callerHungup() {
|
_callerHungup() {
|
||||||
|
this._hangup('caller');
|
||||||
|
}
|
||||||
|
|
||||||
|
_jambonzHangup() {
|
||||||
|
this._hangup();
|
||||||
|
}
|
||||||
|
|
||||||
|
_hangup(terminatedBy = 'jambonz') {
|
||||||
|
if (this.dlg.connectTime) {
|
||||||
|
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
||||||
|
this.rootSpan.setAttributes({'call.termination': `hangup by ${terminatedBy}`});
|
||||||
|
this.callInfo.callTerminationBy = terminatedBy;
|
||||||
|
this.emit('callStatusChange', {
|
||||||
|
callStatus: CallStatus.Completed,
|
||||||
|
duration
|
||||||
|
});
|
||||||
|
}
|
||||||
|
this.logger.info(`InboundCallSession: ${terminatedBy} hung up`);
|
||||||
|
this._callReleased();
|
||||||
|
this.req.removeAllListeners('cancel');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -34,6 +34,9 @@ class ConfirmCallSession extends CallSession {
|
|||||||
_callerHungup() {
|
_callerHungup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_jambonzHangup() {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -67,15 +67,27 @@ class InboundCallSession extends CallSession {
|
|||||||
* This is invoked when the caller hangs up, in order to calculate the call duration.
|
* This is invoked when the caller hangs up, in order to calculate the call duration.
|
||||||
*/
|
*/
|
||||||
_callerHungup() {
|
_callerHungup() {
|
||||||
|
this._hangup('caller');
|
||||||
|
}
|
||||||
|
|
||||||
|
_jambonzHangup() {
|
||||||
|
this._hangup();
|
||||||
|
}
|
||||||
|
|
||||||
|
_hangup(terminatedBy = 'jambonz') {
|
||||||
|
if (this.dlg === null) {
|
||||||
|
this.logger.info('InboundCallSession:_hangup - race condition, dlg cleared by app hangup');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.logger.info(`InboundCallSession: ${terminatedBy} hung up`);
|
||||||
assert(this.dlg.connectTime);
|
assert(this.dlg.connectTime);
|
||||||
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
||||||
this.rootSpan.setAttributes({'call.termination': 'hangup by caller'});
|
this.rootSpan.setAttributes({'call.termination': `hangup by ${terminatedBy}`});
|
||||||
this.callInfo.callTerminationBy = 'caller';
|
this.callInfo.callTerminationBy = terminatedBy;
|
||||||
this.emit('callStatusChange', {
|
this.emit('callStatusChange', {
|
||||||
callStatus: CallStatus.Completed,
|
callStatus: CallStatus.Completed,
|
||||||
duration
|
duration
|
||||||
});
|
});
|
||||||
this.logger.info('InboundCallSession: caller hung up');
|
|
||||||
this._callReleased();
|
this._callReleased();
|
||||||
this.req.removeAllListeners('cancel');
|
this.req.removeAllListeners('cancel');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,13 +49,21 @@ class RestCallSession extends CallSession {
|
|||||||
* This is invoked when the called party hangs up, in order to calculate the call duration.
|
* This is invoked when the called party hangs up, in order to calculate the call duration.
|
||||||
*/
|
*/
|
||||||
_callerHungup() {
|
_callerHungup() {
|
||||||
|
this._hangup('caller');
|
||||||
|
}
|
||||||
|
|
||||||
|
_jambonzHangup() {
|
||||||
|
this._hangup();
|
||||||
|
}
|
||||||
|
|
||||||
|
_hangup(terminatedBy = 'jamboz') {
|
||||||
if (this.restDialTask) {
|
if (this.restDialTask) {
|
||||||
this.restDialTask.turnOffAmd();
|
this.restDialTask.turnOffAmd();
|
||||||
}
|
}
|
||||||
this.callInfo.callTerminationBy = 'caller';
|
this.callInfo.callTerminationBy = terminatedBy;
|
||||||
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
||||||
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration});
|
this.emit('callStatusChange', {callStatus: CallStatus.Completed, duration});
|
||||||
this.logger.debug('RestCallSession: called party hung up');
|
this.logger.debug(`RestCallSession: called party hung up by ${terminatedBy}`);
|
||||||
this._callReleased();
|
this._callReleased();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
22
lib/tasks/answer.js
Normal file
22
lib/tasks/answer.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const Task = require('./task');
|
||||||
|
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Answer the call.
|
||||||
|
* Note: This is rarely used, as the call is typically answered automatically when required by the app,
|
||||||
|
* but it can be useful to force an answer before a pause in some cases
|
||||||
|
*/
|
||||||
|
class TaskAnswer extends Task {
|
||||||
|
constructor(logger, opts) {
|
||||||
|
super(logger, opts);
|
||||||
|
this.preconditions = TaskPreconditions.Endpoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() { return TaskName.Answer; }
|
||||||
|
|
||||||
|
async exec(cs) {
|
||||||
|
super.exec(cs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TaskAnswer;
|
||||||
@@ -60,6 +60,8 @@ class Conference extends Task {
|
|||||||
|
|
||||||
this.emitter = new Emitter();
|
this.emitter = new Emitter();
|
||||||
this.results = {};
|
this.results = {};
|
||||||
|
this.coaching = [];
|
||||||
|
this.speakOnlyTo = this.data.speakOnlyTo;
|
||||||
|
|
||||||
// transferred from another server in order to bridge to a local caller?
|
// transferred from another server in order to bridge to a local caller?
|
||||||
if (this.data._ && this.data._.connectTime) {
|
if (this.data._ && this.data._.connectTime) {
|
||||||
@@ -348,16 +350,27 @@ class Conference extends Task {
|
|||||||
Object.assign(opts, {flags: {
|
Object.assign(opts, {flags: {
|
||||||
...(this.endConferenceOnExit && {endconf: true}),
|
...(this.endConferenceOnExit && {endconf: true}),
|
||||||
...(this.startConferenceOnEnter && {moderator: true}),
|
...(this.startConferenceOnEnter && {moderator: true}),
|
||||||
...(this.joinMuted && {joinMuted: true}),
|
...((this.joinMuted || this.speakOnlyTo) && {joinMuted: true}),
|
||||||
}});
|
}});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Note on the above: if we are joining in "coaching" mode (ie only going to heard by a subset of participants)
|
||||||
|
* then we join muted temporarily, and then unmute ourselves once we have identified the subset of participants
|
||||||
|
* to whom we will be speaking.
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const {memberId, confUuid} = await this.ep.join(this.confName, opts);
|
const {memberId, confUuid} = await this.ep.join(this.confName, opts);
|
||||||
this.logger.debug({memberId, confUuid}, `Conference:_joinConference: successfully joined ${this.confName}`);
|
this.logger.debug({memberId, confUuid}, `Conference:_joinConference: successfully joined ${this.confName}`);
|
||||||
this.memberId = memberId;
|
this.memberId = parseInt(memberId, 10);
|
||||||
this.confUuid = confUuid;
|
this.confUuid = confUuid;
|
||||||
|
|
||||||
|
// set a tag for this member, if provided
|
||||||
|
if (this.data.memberTag) {
|
||||||
|
this.setMemberTag(this.data.memberTag);
|
||||||
|
}
|
||||||
|
|
||||||
cs.setConferenceDetails(memberId, this.confName, confUuid);
|
cs.setConferenceDetails(memberId, this.confName, confUuid);
|
||||||
const response = await this.ep.api('conference', [this.confName, 'get', 'count']);
|
const response = await this.ep.api('conference', [this.confName, 'get', 'count']);
|
||||||
if (response.body && /\d+/.test(response.body)) this.participantCount = parseInt(response.body);
|
if (response.body && /\d+/.test(response.body)) this.participantCount = parseInt(response.body);
|
||||||
@@ -384,6 +397,9 @@ class Conference extends Task {
|
|||||||
.catch((err) => {});
|
.catch((err) => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.speakOnlyTo) {
|
||||||
|
this.setCoachMode(this.speakOnlyTo);
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err, `Failed to join conference ${this.confName}`);
|
this.logger.error(err, `Failed to join conference ${this.confName}`);
|
||||||
throw err;
|
throw err;
|
||||||
@@ -428,7 +444,15 @@ class Conference extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async doConferenceHold(cs, opts) {
|
doConferenceMute(cs, opts) {
|
||||||
|
assert (cs.isInConference);
|
||||||
|
|
||||||
|
const mute = opts.conf_mute_status === 'mute';
|
||||||
|
this.ep.api(`conference ${this.confName} ${mute ? 'mute' : 'unmute'} ${this.memberId}`)
|
||||||
|
.catch((err) => this.logger.info({err}, 'Error muting or unmuting participant'));
|
||||||
|
}
|
||||||
|
|
||||||
|
doConferenceHold(cs, opts) {
|
||||||
assert (cs.isInConference);
|
assert (cs.isInConference);
|
||||||
|
|
||||||
const {conf_hold_status, wait_hook} = opts;
|
const {conf_hold_status, wait_hook} = opts;
|
||||||
@@ -465,6 +489,40 @@ class Conference extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async doConferenceParticipantAction(cs, opts) {
|
||||||
|
const {action, tag} = opts;
|
||||||
|
|
||||||
|
switch (action) {
|
||||||
|
case 'tag':
|
||||||
|
await this.setMemberTag(tag);
|
||||||
|
break;
|
||||||
|
case 'untag':
|
||||||
|
await this.clearMemberTag();
|
||||||
|
break;
|
||||||
|
case 'coach':
|
||||||
|
await this.setCoachMode(tag);
|
||||||
|
break;
|
||||||
|
case 'uncoach':
|
||||||
|
await this.clearCoachMode();
|
||||||
|
break;
|
||||||
|
case 'hold':
|
||||||
|
this.doConferenceHold(cs, {conf_hold_status: 'hold'});
|
||||||
|
break;
|
||||||
|
case 'unhold':
|
||||||
|
this.doConferenceHold(cs, {conf_hold_status: 'unhold'});
|
||||||
|
break;
|
||||||
|
case 'mute':
|
||||||
|
this.doConferenceMute(cs, {conf_mute_status: 'mute'});
|
||||||
|
break;
|
||||||
|
case 'unmute':
|
||||||
|
this.doConferenceMute(cs, {conf_mute_status: 'unmute'});
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
this.logger.info(`Conference:doConferenceParticipantAction - unhandled action ${action}`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async _doWaitHookWhileOnHold(cs, dlg, wait_hook) {
|
async _doWaitHookWhileOnHold(cs, dlg, wait_hook) {
|
||||||
do {
|
do {
|
||||||
try {
|
try {
|
||||||
@@ -530,7 +588,7 @@ class Conference extends Task {
|
|||||||
const response = await this.ep.api('conference', [this.confName, 'get', 'count']);
|
const response = await this.ep.api('conference', [this.confName, 'get', 'count']);
|
||||||
if (response.body && confNoMatch(response.body)) this.participantCount = 0;
|
if (response.body && confNoMatch(response.body)) this.participantCount = 0;
|
||||||
else if (response.body && /^\d+$/.test(response.body)) this.participantCount = parseInt(response.body) - 1;
|
else if (response.body && /^\d+$/.test(response.body)) this.participantCount = parseInt(response.body) - 1;
|
||||||
this.logger.debug({response}, `Conference:_doFinalMemberCheck conference count ${this.participantCount}`);
|
this.logger.debug(`Conference:_doFinalMemberCheck conference count ${this.participantCount}`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info({err}, 'Conference:_doFinalMemberCheck error retrieving count (we were probably kicked');
|
this.logger.info({err}, 'Conference:_doFinalMemberCheck error retrieving count (we were probably kicked');
|
||||||
}
|
}
|
||||||
@@ -642,11 +700,19 @@ class Conference extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// conference event handlers
|
// conference event handlers
|
||||||
|
_onAddMember(logger, cs, evt) {
|
||||||
|
const memberId = parseInt(evt.getHeader('Member-ID')) ;
|
||||||
|
if (this.speakOnlyTo) {
|
||||||
|
logger.debug(`Conference:_onAddMember - member ${memberId} added to ${this.confName}, updating coaching mode`);
|
||||||
|
this.setCoachMode(this.speakOnlyTo).catch(() => {});
|
||||||
|
}
|
||||||
|
else logger.debug(`Conference:_onAddMember - member ${memberId} added to conference ${this.confName}`);
|
||||||
|
}
|
||||||
_onDelMember(logger, cs, evt) {
|
_onDelMember(logger, cs, evt) {
|
||||||
const memberId = parseInt(evt.getHeader('Member-ID')) ;
|
const memberId = parseInt(evt.getHeader('Member-ID')) ;
|
||||||
this.participantCount = parseInt(evt.getHeader('Conference-Size'));
|
this.participantCount = parseInt(evt.getHeader('Conference-Size'));
|
||||||
if (memberId === this.memberId) {
|
if (memberId === this.memberId) {
|
||||||
this.logger.info(`Conference:_onDelMember - I was dropped from conference ${this.confName}, task is complete`);
|
logger.info(`Conference:_onDelMember - I was dropped from conference ${this.confName}, task is complete`);
|
||||||
this.replaceEndpointAndEnd(cs);
|
this.replaceEndpointAndEnd(cs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -675,6 +741,89 @@ class Conference extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onTag(logger, cs, evt) {
|
||||||
|
const memberId = parseInt(evt.getHeader('Member-ID')) ;
|
||||||
|
const tag = evt.getHeader('Tag') || '';
|
||||||
|
if (memberId !== this.memberId && this.speakOnlyTo) {
|
||||||
|
logger.info(`Conference:_onTag - member ${memberId} set tag to '${tag }'; updating coach mode accordingly`);
|
||||||
|
this.setCoachMode(this.speakOnlyTo).catch(() => {});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the conference to "coaching" mode, where the audio of the participant is only heard
|
||||||
|
* by a subset of the participants in the conference.
|
||||||
|
* We do this by first getting all of the members who do *not* have this tag, and then
|
||||||
|
* we configure this members audio to not be sent to them.
|
||||||
|
* @param {string} speakOnlyTo - tag of the members who should receive our audio
|
||||||
|
*
|
||||||
|
* N.B.: this feature requires jambonz patches to freeswitch mod_conference
|
||||||
|
*/
|
||||||
|
async setCoachMode(speakOnlyTo) {
|
||||||
|
this.speakOnlyTo = speakOnlyTo;
|
||||||
|
if (!this.memberId) {
|
||||||
|
this.logger.info('Conference:_setCoachMode: no member id yet');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const members = (await this.ep.getNonMatchingConfParticipants(this.confName, speakOnlyTo))
|
||||||
|
.filter((m) => m !== this.memberId);
|
||||||
|
if (members.length === 0) {
|
||||||
|
this.logger.info({members}, 'Conference:_setCoachMode: all participants have the tag, so all will hear me');
|
||||||
|
if (this.coaching.length) {
|
||||||
|
await this.ep.api('conference', [this.confName, 'relate', this.memberId, this.coaching.join(','), 'clear']);
|
||||||
|
this.coaching = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const memberList = members.join(',');
|
||||||
|
this.logger.info(`Conference:_setCoachMode: my audio will NOT be sent to ${memberList}`);
|
||||||
|
await this.ep.api('conference', [this.confName, 'relate', this.memberId, memberList, 'nospeak']);
|
||||||
|
this.coaching = members;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({err, speakOnlyTo}, '_setCoachMode: Error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async clearCoachMode() {
|
||||||
|
if (!this.memberId) return;
|
||||||
|
try {
|
||||||
|
if (this.coaching.length === 0) {
|
||||||
|
this.logger.info('Conference:_clearCoachMode: no coaching mode to clear');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const memberList = this.coaching.join(',');
|
||||||
|
this.logger.info(`Conference:_clearCoachMode: now sending my audio to all, including ${memberList}`);
|
||||||
|
await this.ep.api('conference', [this.confName, 'relate', this.memberId, memberList, 'clear']);
|
||||||
|
}
|
||||||
|
this.speakOnlyTo = null;
|
||||||
|
this.coaching = [];
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({err}, '_clearCoachMode: Error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async setMemberTag(tag) {
|
||||||
|
try {
|
||||||
|
await this.ep.api('conference', [this.confName, 'tag', this.memberId, tag]);
|
||||||
|
this.logger.info(`Conference:setMemberTag: set tag for ${this.memberId} to ${tag}`);
|
||||||
|
this.memberTag = tag;
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({err}, `Error setting tag for ${this.memberId} to ${tag}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async clearMemberTag() {
|
||||||
|
try {
|
||||||
|
await this.ep.api('conference', [this.confName, 'tag', this.memberId]);
|
||||||
|
this.logger.info(`Conference:setMemberTag: clearing tag for ${this.memberId}`);
|
||||||
|
this.memberTag = null;
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error({err}, `Error clearing tag for ${this.memberId}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Conference;
|
module.exports = Conference;
|
||||||
|
|||||||
@@ -1,15 +1,22 @@
|
|||||||
const Task = require('./task');
|
const Task = require('./task');
|
||||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||||
|
const parseDecibels = require('../utils/parse-decibels');
|
||||||
|
|
||||||
class TaskConfig extends Task {
|
class TaskConfig extends Task {
|
||||||
constructor(logger, opts) {
|
constructor(logger, opts) {
|
||||||
super(logger, opts);
|
super(logger, opts);
|
||||||
|
|
||||||
[
|
[
|
||||||
'synthesizer',
|
'synthesizer',
|
||||||
'recognizer',
|
'recognizer',
|
||||||
'bargeIn',
|
'bargeIn',
|
||||||
'record',
|
'record',
|
||||||
'listen'
|
'listen',
|
||||||
|
'transcribe',
|
||||||
|
'fillerNoise',
|
||||||
|
'actionHookDelayAction',
|
||||||
|
'boostAudioSignal',
|
||||||
|
'vad'
|
||||||
].forEach((k) => this[k] = this.data[k] || {});
|
].forEach((k) => this[k] = this.data[k] || {});
|
||||||
|
|
||||||
if ('notifyEvents' in this.data) {
|
if ('notifyEvents' in this.data) {
|
||||||
@@ -30,6 +37,13 @@ class TaskConfig extends Task {
|
|||||||
if (this.bargeIn[k]) this.gatherOpts[k] = this.bargeIn[k];
|
if (this.bargeIn[k]) this.gatherOpts[k] = this.bargeIn[k];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (this.transcribe?.enable) {
|
||||||
|
this.transcribeOpts = {
|
||||||
|
verb: 'transcribe',
|
||||||
|
...this.transcribe
|
||||||
|
};
|
||||||
|
delete this.transcribeOpts.enable;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.data.reset) {
|
if (this.data.reset) {
|
||||||
if (typeof this.data.reset === 'string') this.data.reset = [this.data.reset];
|
if (typeof this.data.reset === 'string') this.data.reset = [this.data.reset];
|
||||||
@@ -37,7 +51,12 @@ class TaskConfig extends Task {
|
|||||||
else this.data.reset = [];
|
else this.data.reset = [];
|
||||||
|
|
||||||
if (this.bargeIn.sticky) this.autoEnable = true;
|
if (this.bargeIn.sticky) this.autoEnable = true;
|
||||||
this.preconditions = (this.bargeIn.enable || this.record?.action || this.listen?.url || this.data.amd) ?
|
this.preconditions = (this.bargeIn.enable ||
|
||||||
|
this.record?.action ||
|
||||||
|
this.listen?.url ||
|
||||||
|
this.data.amd ||
|
||||||
|
'boostAudioSignal' in this.data ||
|
||||||
|
this.transcribe?.enable) ?
|
||||||
TaskPreconditions.Endpoint :
|
TaskPreconditions.Endpoint :
|
||||||
TaskPreconditions.None;
|
TaskPreconditions.None;
|
||||||
|
|
||||||
@@ -50,6 +69,10 @@ class TaskConfig extends Task {
|
|||||||
get hasRecognizer() { return Object.keys(this.recognizer).length; }
|
get hasRecognizer() { return Object.keys(this.recognizer).length; }
|
||||||
get hasRecording() { return Object.keys(this.record).length; }
|
get hasRecording() { return Object.keys(this.record).length; }
|
||||||
get hasListen() { return Object.keys(this.listen).length; }
|
get hasListen() { return Object.keys(this.listen).length; }
|
||||||
|
get hasTranscribe() { return Object.keys(this.transcribe).length; }
|
||||||
|
get hasDub() { return Object.keys(this.dub).length; }
|
||||||
|
get hasVad() { return Object.keys(this.vad).length; }
|
||||||
|
get hasFillerNoise() { return Object.keys(this.fillerNoise).length; }
|
||||||
|
|
||||||
get summary() {
|
get summary() {
|
||||||
const phrase = [];
|
const phrase = [];
|
||||||
@@ -72,9 +95,14 @@ class TaskConfig extends Task {
|
|||||||
if (this.hasListen) {
|
if (this.hasListen) {
|
||||||
phrase.push(this.listen.enable ? `listen ${this.listen.url}` : 'stop listen');
|
phrase.push(this.listen.enable ? `listen ${this.listen.url}` : 'stop listen');
|
||||||
}
|
}
|
||||||
|
if (this.hasTranscribe) {
|
||||||
|
phrase.push(this.transcribe.enable ? `transcribe ${this.transcribe.transcriptionHook}` : 'stop transcribe');
|
||||||
|
}
|
||||||
|
if (this.hasFillerNoise) phrase.push(`fillerNoise ${this.fillerNoise.enable ? 'on' : 'off'}`);
|
||||||
if (this.data.amd) phrase.push('enable amd');
|
if (this.data.amd) phrase.push('enable amd');
|
||||||
if (this.notifyEvents) phrase.push(`event notification ${this.notifyEvents ? 'on' : 'off'}`);
|
if (this.notifyEvents) phrase.push(`event notification ${this.notifyEvents ? 'on' : 'off'}`);
|
||||||
if (this.onHoldMusic) phrase.push(`onHoldMusic: ${this.onHoldMusic}`);
|
if (this.onHoldMusic) phrase.push(`onHoldMusic: ${this.onHoldMusic}`);
|
||||||
|
if ('boostAudioSignal' in this.data) phrase.push(`setGain ${this.data.boostAudioSignal}`);
|
||||||
return `${this.name}{${phrase.join(',')}}`;
|
return `${this.name}{${phrase.join(',')}}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +137,7 @@ class TaskConfig extends Task {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (this.hasSynthesizer) {
|
if (this.hasSynthesizer) {
|
||||||
|
cs.synthesizer = this.synthesizer;
|
||||||
cs.speechSynthesisVendor = this.synthesizer.vendor !== 'default'
|
cs.speechSynthesisVendor = this.synthesizer.vendor !== 'default'
|
||||||
? this.synthesizer.vendor
|
? this.synthesizer.vendor
|
||||||
: cs.speechSynthesisVendor;
|
: cs.speechSynthesisVendor;
|
||||||
@@ -138,6 +167,7 @@ class TaskConfig extends Task {
|
|||||||
this.logger.info({synthesizer: this.synthesizer}, 'Config: updated synthesizer');
|
this.logger.info({synthesizer: this.synthesizer}, 'Config: updated synthesizer');
|
||||||
}
|
}
|
||||||
if (this.hasRecognizer) {
|
if (this.hasRecognizer) {
|
||||||
|
cs.recognizer = this.recognizer;
|
||||||
cs.speechRecognizerVendor = this.recognizer.vendor !== 'default'
|
cs.speechRecognizerVendor = this.recognizer.vendor !== 'default'
|
||||||
? this.recognizer.vendor
|
? this.recognizer.vendor
|
||||||
: cs.speechRecognizerVendor;
|
: cs.speechRecognizerVendor;
|
||||||
@@ -210,15 +240,65 @@ class TaskConfig extends Task {
|
|||||||
const {enable, ...opts} = this.listen;
|
const {enable, ...opts} = this.listen;
|
||||||
if (enable) {
|
if (enable) {
|
||||||
this.logger.debug({opts}, 'Config: enabling listen');
|
this.logger.debug({opts}, 'Config: enabling listen');
|
||||||
cs.startBackgroundListen({verb: 'listen', ...opts});
|
cs.startBackgroundTask('listen', {verb: 'listen', ...opts});
|
||||||
} else {
|
} else {
|
||||||
this.logger.info('Config: disabling listen');
|
this.logger.info('Config: disabling listen');
|
||||||
cs.stopBackgroundListen();
|
cs.stopBackgroundTask('listen');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (this.hasTranscribe) {
|
||||||
|
if (this.transcribe.enable) {
|
||||||
|
this.transcribeOpts.recognizer = this.hasRecognizer ?
|
||||||
|
this.recognizer :
|
||||||
|
{
|
||||||
|
vendor: cs.speechRecognizerVendor,
|
||||||
|
language: cs.speechRecognizerLanguage
|
||||||
|
};
|
||||||
|
this.logger.debug(this.transcribeOpts, 'Config: enabling transcribe');
|
||||||
|
cs.startBackgroundTask('transcribe', this.transcribeOpts);
|
||||||
|
} else {
|
||||||
|
this.logger.info('Config: disabling transcribe');
|
||||||
|
cs.stopBackgroundTask('transcribe');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (Object.keys(this.actionHookDelayAction).length !== 0) {
|
||||||
|
cs.actionHookDelayEnabled = this.actionHookDelayAction.enabled || false;
|
||||||
|
cs.actionHookNoResponseTimeout = this.actionHookDelayAction.noResponseTimeout || 0;
|
||||||
|
cs.actionHookNoResponseGiveUpTimeout = this.actionHookDelayAction.noResponseGiveUpTimeout || 0;
|
||||||
|
cs.actionHookDelayRetries = this.actionHookDelayAction.retries || 1;
|
||||||
|
cs.actionHookDelayActions = this.actionHookDelayAction.actions || [];
|
||||||
|
}
|
||||||
if (this.data.sipRequestWithinDialogHook) {
|
if (this.data.sipRequestWithinDialogHook) {
|
||||||
cs.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
cs.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('boostAudioSignal' in this.data) {
|
||||||
|
const db = parseDecibels(this.data.boostAudioSignal);
|
||||||
|
this.logger.info(`Config: boosting audio signal by ${db} dB`);
|
||||||
|
const args = [ep.uuid, 'setGain', db];
|
||||||
|
ep.api('uuid_dub', args).catch((err) => {
|
||||||
|
this.logger.error(err, 'Error boosting audio signal');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hasFillerNoise) {
|
||||||
|
const {enable, ...opts} = this.fillerNoise;
|
||||||
|
this.logger.info({fillerNoise: this.fillerNoise}, 'Config: fillerNoise');
|
||||||
|
if (!enable) cs.disableFillerNoise();
|
||||||
|
else {
|
||||||
|
cs.enableFillerNoise(opts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hasVad) {
|
||||||
|
cs.vad = {
|
||||||
|
enable: this.vad.enable || false,
|
||||||
|
voiceMs: this.vad.voiceMs || 250,
|
||||||
|
silenceMs: this.vad.silenceMs || 150,
|
||||||
|
strategy: this.vad.strategy || 'one-shot',
|
||||||
|
mode: this.vad.mod || 2
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async kill(cs) {
|
async kill(cs) {
|
||||||
|
|||||||
@@ -73,7 +73,8 @@ class TaskDequeue extends Task {
|
|||||||
try {
|
try {
|
||||||
let url;
|
let url;
|
||||||
if (this.callSid) {
|
if (this.callSid) {
|
||||||
url = await retrieveByPatternSortedSet(this.queueName, `*${this.callSid}`);
|
const r = await retrieveByPatternSortedSet(this.queueName, `*${this.callSid}`);
|
||||||
|
url = r[0];
|
||||||
} else {
|
} else {
|
||||||
url = await retrieveFromSortedSet(this.queueName);
|
url = await retrieveFromSortedSet(this.queueName);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,10 +14,11 @@ const sessionTracker = require('../session/session-tracker');
|
|||||||
const DtmfCollector = require('../utils/dtmf-collector');
|
const DtmfCollector = require('../utils/dtmf-collector');
|
||||||
const ConfirmCallSession = require('../session/confirm-call-session');
|
const ConfirmCallSession = require('../session/confirm-call-session');
|
||||||
const dbUtils = require('../utils/db-utils');
|
const dbUtils = require('../utils/db-utils');
|
||||||
|
const parseDecibels = require('../utils/parse-decibels');
|
||||||
const debug = require('debug')('jambonz:feature-server');
|
const debug = require('debug')('jambonz:feature-server');
|
||||||
const {parseUri} = require('drachtio-srf');
|
const {parseUri} = require('drachtio-srf');
|
||||||
const {ANCHOR_MEDIA_ALWAYS, JAMBONZ_DISABLE_DIAL_PAI_HEADER} = require('../config');
|
const {ANCHOR_MEDIA_ALWAYS, JAMBONZ_DISABLE_DIAL_PAI_HEADER} = require('../config');
|
||||||
const { isOnhold } = require('../utils/sdp-utils');
|
const { isOnhold, isOpusFirst } = require('../utils/sdp-utils');
|
||||||
const { normalizeJambones } = require('@jambonz/verb-specifications');
|
const { normalizeJambones } = require('@jambonz/verb-specifications');
|
||||||
|
|
||||||
function parseDtmfOptions(logger, dtmfCapture) {
|
function parseDtmfOptions(logger, dtmfCapture) {
|
||||||
@@ -100,6 +101,8 @@ class TaskDial extends Task {
|
|||||||
this.referHook = this.data.referHook;
|
this.referHook = this.data.referHook;
|
||||||
this.dtmfHook = this.data.dtmfHook;
|
this.dtmfHook = this.data.dtmfHook;
|
||||||
this.proxy = this.data.proxy;
|
this.proxy = this.data.proxy;
|
||||||
|
this.tag = this.data.tag;
|
||||||
|
this.boostAudioSignal = this.data.boostAudioSignal;
|
||||||
|
|
||||||
if (this.dtmfHook) {
|
if (this.dtmfHook) {
|
||||||
const {parentDtmfCollector, childDtmfCollector} = parseDtmfOptions(logger, this.data.dtmfCapture || {});
|
const {parentDtmfCollector, childDtmfCollector} = parseDtmfOptions(logger, this.data.dtmfCapture || {});
|
||||||
@@ -117,6 +120,9 @@ class TaskDial extends Task {
|
|||||||
if (this.data.transcribe) {
|
if (this.data.transcribe) {
|
||||||
this.transcribeTask = makeTask(logger, {'transcribe' : this.data.transcribe}, this);
|
this.transcribeTask = makeTask(logger, {'transcribe' : this.data.transcribe}, this);
|
||||||
}
|
}
|
||||||
|
if (this.data.dub && Array.isArray(this.data.dub) && this.data.dub.length > 0) {
|
||||||
|
this.dubTasks = this.data.dub.map((d) => makeTask(logger, {'dub': d}, this));
|
||||||
|
}
|
||||||
|
|
||||||
this.results = {};
|
this.results = {};
|
||||||
this.bridged = false;
|
this.bridged = false;
|
||||||
@@ -138,15 +144,17 @@ class TaskDial extends Task {
|
|||||||
|
|
||||||
get name() { return TaskName.Dial; }
|
get name() { return TaskName.Dial; }
|
||||||
|
|
||||||
get isOnHold() {
|
get isOnHoldEnabled() {
|
||||||
return this.isIncomingLegHold || this.isOutgoingLegHold;
|
return !!this.data.onHoldHook;
|
||||||
}
|
}
|
||||||
|
|
||||||
get canReleaseMedia() {
|
get canReleaseMedia() {
|
||||||
const keepAnchor = this.data.anchorMedia ||
|
const keepAnchor = this.data.anchorMedia ||
|
||||||
this.cs.isBackGroundListen ||
|
this.cs.isBackGroundListen ||
|
||||||
|
this.cs.onHoldMusic ||
|
||||||
ANCHOR_MEDIA_ALWAYS ||
|
ANCHOR_MEDIA_ALWAYS ||
|
||||||
this.listenTask ||
|
this.listenTask ||
|
||||||
|
this.dubTasks ||
|
||||||
this.transcribeTask ||
|
this.transcribeTask ||
|
||||||
this.startAmd;
|
this.startAmd;
|
||||||
|
|
||||||
@@ -323,7 +331,7 @@ class TaskDial extends Task {
|
|||||||
const by = parseUri(req.getParsedHeader('Referred-By').uri);
|
const by = parseUri(req.getParsedHeader('Referred-By').uri);
|
||||||
this.logger.info({to}, 'refer to parsed');
|
this.logger.info({to}, 'refer to parsed');
|
||||||
const json = await cs.requestor.request('verb:hook', this.referHook, {
|
const json = await cs.requestor.request('verb:hook', this.referHook, {
|
||||||
...callInfo,
|
...(callInfo.toJSON()),
|
||||||
refer_details: {
|
refer_details: {
|
||||||
sip_refer_to: req.get('Refer-To'),
|
sip_refer_to: req.get('Refer-To'),
|
||||||
sip_referred_by: req.get('Referred-By'),
|
sip_referred_by: req.get('Referred-By'),
|
||||||
@@ -488,7 +496,8 @@ class TaskDial extends Task {
|
|||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
proxy: `sip:${sbcAddress}`,
|
proxy: `sip:${sbcAddress}`,
|
||||||
callingNumber: this.callerId || req.callingNumber,
|
callingNumber: this.callerId || req.callingNumber,
|
||||||
...(this.callerName && {callingName: this.callerName})
|
...(this.callerName && {callingName: this.callerName}),
|
||||||
|
opusFirst: isOpusFirst(this.cs.ep.remote.sdp)
|
||||||
};
|
};
|
||||||
|
|
||||||
const t = this.target.find((t) => t.type === 'teams');
|
const t = this.target.find((t) => t.type === 'teams');
|
||||||
@@ -548,9 +557,9 @@ class TaskDial extends Task {
|
|||||||
const str = this.callerId || req.callingNumber || '';
|
const str = this.callerId || req.callingNumber || '';
|
||||||
const callingNumber = str.startsWith('+') ? str.substring(1) : str;
|
const callingNumber = str.startsWith('+') ? str.substring(1) : str;
|
||||||
const voip_carrier_sid = await lookupCarrierByPhoneNumber(cs.accountSid, callingNumber);
|
const voip_carrier_sid = await lookupCarrierByPhoneNumber(cs.accountSid, callingNumber);
|
||||||
this.logger.info(
|
|
||||||
`Dial:_attemptCalls: selected ${voip_carrier_sid} for requested phone number: ${callingNumber}`);
|
|
||||||
if (voip_carrier_sid) {
|
if (voip_carrier_sid) {
|
||||||
|
this.logger.info(
|
||||||
|
`Dial:_attemptCalls: selected voip_carrier_sid ${voip_carrier_sid} for callingNumber: ${callingNumber}`);
|
||||||
opts.headers['X-Requested-Carrier-Sid'] = voip_carrier_sid;
|
opts.headers['X-Requested-Carrier-Sid'] = voip_carrier_sid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -569,7 +578,8 @@ class TaskDial extends Task {
|
|||||||
accountInfo: cs.accountInfo,
|
accountInfo: cs.accountInfo,
|
||||||
rootSpan: cs.rootSpan,
|
rootSpan: cs.rootSpan,
|
||||||
startSpan: this.startSpan.bind(this),
|
startSpan: this.startSpan.bind(this),
|
||||||
dialTask: this
|
dialTask: this,
|
||||||
|
onHoldMusic: this.cs.onHoldMusic
|
||||||
});
|
});
|
||||||
this.dials.set(sd.callSid, sd);
|
this.dials.set(sd.callSid, sd);
|
||||||
|
|
||||||
@@ -626,6 +636,8 @@ class TaskDial extends Task {
|
|||||||
await this._connectSingleDial(cs, sd);
|
await this._connectSingleDial(cs, sd);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info({err}, 'Dial:_attemptCalls - Error calling _connectSingleDial ');
|
this.logger.info({err}, 'Dial:_attemptCalls - Error calling _connectSingleDial ');
|
||||||
|
sd.removeAllListeners();
|
||||||
|
this.kill(cs);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.on('decline', () => {
|
.on('decline', () => {
|
||||||
@@ -678,22 +690,43 @@ class TaskDial extends Task {
|
|||||||
async _onReinvite(req, res) {
|
async _onReinvite(req, res) {
|
||||||
try {
|
try {
|
||||||
let isHandled = false;
|
let isHandled = false;
|
||||||
if (this.cs.onHoldMusic) {
|
if (this.isOnHoldEnabled) {
|
||||||
if (isOnhold(req.body) && !this.epOther && !this.ep) {
|
if (isOnhold(req.body)) {
|
||||||
await this.cs.handleReinviteAfterMediaReleased(req, res);
|
this.logger.debug('Dial: _onReinvite receive hold Request');
|
||||||
// Onhold but media is already released
|
if (!this.epOther && !this.ep) {
|
||||||
// reconnect A Leg and Response B leg
|
this.logger.debug(`Dial: _onReinvite receive hold Request,
|
||||||
await this.reAnchorMedia(this.cs, this.sd);
|
media already released, reconnect media server`);
|
||||||
this.isOutgoingLegHold = true;
|
// update caller leg for new SDP from callee.
|
||||||
|
await this.cs.handleReinviteAfterMediaReleased(req, res);
|
||||||
|
// Freeswitch media is released, reconnect
|
||||||
|
await this.reAnchorMedia(this.cs, this.sd);
|
||||||
|
this.isOutgoingLegHold = true;
|
||||||
|
} else {
|
||||||
|
this.logger.debug('Dial: _onReinvite receive hold Request, update SDP');
|
||||||
|
const newSdp = await this.ep.modify(req.body);
|
||||||
|
res.send(200, {body: newSdp});
|
||||||
|
}
|
||||||
isHandled = true;
|
isHandled = true;
|
||||||
this._onHoldHook();
|
// Media already connected, ask for onHoldHook
|
||||||
} else if (!isOnhold(req.body) && this.epOther && this.ep && this.isOutgoingLegHold && this.canReleaseMedia) {
|
this._onHoldHook(req);
|
||||||
// Offhold, time to release media
|
} else if (!isOnhold(req.body)) {
|
||||||
const newSdp = await this.ep.modify(req.body);
|
this.logger.debug('Dial: _onReinvite receive unhold Request');
|
||||||
await res.send(200, {body: newSdp});
|
if (this.epOther && this.ep && this.isOutgoingLegHold && this.canReleaseMedia) {
|
||||||
await this._releaseMedia(this.cs, this.sd);
|
this.logger.debug('Dial: _onReinvite receive unhold Request, release media');
|
||||||
|
// Offhold, time to release media
|
||||||
|
const newSdp = await this.ep.modify(req.body);
|
||||||
|
await res.send(200, {body: newSdp});
|
||||||
|
await this._releaseMedia(this.cs, this.sd);
|
||||||
|
this.isOutgoingLegHold = false;
|
||||||
|
} else {
|
||||||
|
this.logger.debug('Dial: _onReinvite receive unhold Request, update media server');
|
||||||
|
const newSdp = await this.ep.modify(req.body);
|
||||||
|
res.send(200, {body: newSdp});
|
||||||
|
}
|
||||||
|
if (this._onHoldSession) {
|
||||||
|
this._onHoldSession.kill();
|
||||||
|
}
|
||||||
isHandled = true;
|
isHandled = true;
|
||||||
this.isOutgoingLegHold = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isHandled) {
|
if (!isHandled) {
|
||||||
@@ -754,6 +787,17 @@ class TaskDial extends Task {
|
|||||||
dialCallSid: sd.callSid,
|
dialCallSid: sd.callSid,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (this.dubTasks) {
|
||||||
|
for (const dub of this.dubTasks) {
|
||||||
|
try {
|
||||||
|
await dub.exec(cs, {ep: sd.ep});
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
this.logger.error({err}, 'Dial:_selectSingleDial - error executing dubTask');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.parentDtmfCollector) this._installDtmfDetection(cs, cs.dlg);
|
if (this.parentDtmfCollector) this._installDtmfDetection(cs, cs.dlg);
|
||||||
if (this.childDtmfCollector) this._installDtmfDetection(cs, this.dlg);
|
if (this.childDtmfCollector) this._installDtmfDetection(cs, this.dlg);
|
||||||
if (cs.sipRequestWithinDialogHook) this._initSipIndialogRequestListener(cs, this.dlg);
|
if (cs.sipRequestWithinDialogHook) this._initSipIndialogRequestListener(cs, this.dlg);
|
||||||
@@ -768,6 +812,18 @@ class TaskDial extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* boost audio signal if requested */
|
||||||
|
if (this.boostAudioSignal) {
|
||||||
|
try {
|
||||||
|
const db = parseDecibels(this.boostAudioSignal);
|
||||||
|
this.logger.info(`Dial: boosting audio signal by ${db} dB`);
|
||||||
|
const args = [this.ep.uuid, 'setGain', db];
|
||||||
|
await this.ep.api('uuid_dub', args);
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info({err}, 'Dial:_selectSingleDial - Error boosting audio signal');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* if we can release the media back to the SBC, do so now */
|
/* if we can release the media back to the SBC, do so now */
|
||||||
if (this.canReleaseMedia) setTimeout(this._releaseMedia.bind(this, cs, sd), 200);
|
if (this.canReleaseMedia) setTimeout(this._releaseMedia.bind(this, cs, sd), 200);
|
||||||
}
|
}
|
||||||
@@ -790,9 +846,11 @@ class TaskDial extends Task {
|
|||||||
assert(cs.ep && sd.ep);
|
assert(cs.ep && sd.ep);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Wait until we got new SDP from B leg to ofter to A Leg
|
||||||
const aLegSdp = cs.ep.remote.sdp;
|
const aLegSdp = cs.ep.remote.sdp;
|
||||||
|
await sd.releaseMediaToSBC(aLegSdp, cs.ep.local.sdp);
|
||||||
const bLegSdp = sd.dlg.remote.sdp;
|
const bLegSdp = sd.dlg.remote.sdp;
|
||||||
await Promise.all[sd.releaseMediaToSBC(aLegSdp, cs.ep.local.sdp), cs.releaseMediaToSBC(bLegSdp)];
|
await cs.releaseMediaToSBC(bLegSdp);
|
||||||
this.epOther = null;
|
this.epOther = null;
|
||||||
this.logger.info('Dial:_releaseMedia - successfully released media from freewitch');
|
this.logger.info('Dial:_releaseMedia - successfully released media from freewitch');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -808,23 +866,34 @@ class TaskDial extends Task {
|
|||||||
this.epOther = cs.ep;
|
this.epOther = cs.ep;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle RE-INVITE hold from caller leg.
|
||||||
async handleReinviteAfterMediaReleased(req, res) {
|
async handleReinviteAfterMediaReleased(req, res) {
|
||||||
let isHandled = false;
|
let isHandled = false;
|
||||||
if (isOnhold(req.body) && !this.epOther && !this.ep) {
|
if (this.isOnHoldEnabled) {
|
||||||
const sdp = await this.dlg.modify(req.body);
|
if (isOnhold(req.body)) {
|
||||||
res.send(200, {body: sdp});
|
if (!this.epOther && !this.ep) {
|
||||||
// Onhold but media is already released
|
// update callee leg for new SDP from caller.
|
||||||
await this.reAnchorMedia(this.cs, this.sd);
|
const sdp = await this.dlg.modify(req.body);
|
||||||
isHandled = true;
|
res.send(200, {body: sdp});
|
||||||
this.isIncomingLegHold = true;
|
// Onhold but media is already released, reconnect
|
||||||
this._onHoldHook();
|
await this.reAnchorMedia(this.cs, this.sd);
|
||||||
} else if (!isOnhold(req.body) && this.epOther && this.ep && this.isIncomingLegHold && this.canReleaseMedia) {
|
isHandled = true;
|
||||||
// Offhold, time to release media
|
this.isIncomingLegHold = true;
|
||||||
const newSdp = await this.epOther.modify(req.body);
|
}
|
||||||
await res.send(200, {body: newSdp});
|
this._onHoldHook(req);
|
||||||
await this._releaseMedia(this.cs, this.sd);
|
} else if (!isOnhold(req.body)) {
|
||||||
isHandled = true;
|
if (this.epOther && this.ep && this.isIncomingLegHold && this.canReleaseMedia) {
|
||||||
this.isIncomingLegHold = false;
|
// Offhold, time to release media
|
||||||
|
const newSdp = await this.epOther.modify(req.body);
|
||||||
|
await res.send(200, {body: newSdp});
|
||||||
|
await this._releaseMedia(this.cs, this.sd);
|
||||||
|
isHandled = true;
|
||||||
|
}
|
||||||
|
this.isIncomingLegHold = false;
|
||||||
|
if (this._onHoldSession) {
|
||||||
|
this._onHoldSession.kill();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isHandled) {
|
if (!isHandled) {
|
||||||
@@ -843,7 +912,7 @@ class TaskDial extends Task {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async _onHoldHook(allowed = [TaskName.Play, TaskName.Say, TaskName.Pause]) {
|
async _onHoldHook(req, allowed = [TaskName.Play, TaskName.Say, TaskName.Pause]) {
|
||||||
if (this.data.onHoldHook) {
|
if (this.data.onHoldHook) {
|
||||||
// send silence for keep Voice quality
|
// send silence for keep Voice quality
|
||||||
await this.epOther.play('silence_stream://500');
|
await this.epOther.play('silence_stream://500');
|
||||||
@@ -853,7 +922,13 @@ class TaskDial extends Task {
|
|||||||
const b3 = this.getTracingPropagation();
|
const b3 = this.getTracingPropagation();
|
||||||
const httpHeaders = b3 && {b3};
|
const httpHeaders = b3 && {b3};
|
||||||
const json = await this.cs.application.requestor.
|
const json = await this.cs.application.requestor.
|
||||||
request('verb:hook', this.data.onHoldHook, this.cs.callInfo.toJSON(), httpHeaders);
|
request('verb:hook', this.data.onHoldHook, {
|
||||||
|
...this.cs.callInfo.toJSON(),
|
||||||
|
hold_detail: {
|
||||||
|
from: req.get('From'),
|
||||||
|
to: req.get('To')
|
||||||
|
}
|
||||||
|
}, httpHeaders);
|
||||||
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
||||||
allowedTasks = tasks.filter((t) => allowed.includes(t.name));
|
allowedTasks = tasks.filter((t) => allowed.includes(t.name));
|
||||||
if (tasks.length !== allowedTasks.length) {
|
if (tasks.length !== allowedTasks.length) {
|
||||||
@@ -862,7 +937,7 @@ class TaskDial extends Task {
|
|||||||
}
|
}
|
||||||
this.logger.debug(`DialTask:_onHoldHook: executing ${tasks.length} tasks`);
|
this.logger.debug(`DialTask:_onHoldHook: executing ${tasks.length} tasks`);
|
||||||
if (tasks.length) {
|
if (tasks.length) {
|
||||||
this._playSession = new ConfirmCallSession({
|
this._onHoldSession = new ConfirmCallSession({
|
||||||
logger: this.logger,
|
logger: this.logger,
|
||||||
application: this.cs.application,
|
application: this.cs.application,
|
||||||
dlg: this.isIncomingLegHold ? this.dlg : this.cs.dlg,
|
dlg: this.isIncomingLegHold ? this.dlg : this.cs.dlg,
|
||||||
@@ -872,12 +947,12 @@ class TaskDial extends Task {
|
|||||||
tasks,
|
tasks,
|
||||||
rootSpan: this.cs.rootSpan
|
rootSpan: this.cs.rootSpan
|
||||||
});
|
});
|
||||||
await this._playSession.exec();
|
await this._onHoldSession.exec();
|
||||||
this._playSession = null;
|
this._onHoldSession = null;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.info(error, 'DialTask:_onHoldHook: failed retrieving waitHook');
|
this.logger.info(error, 'DialTask:_onHoldHook: failed retrieving waitHook');
|
||||||
this._playSession = null;
|
this._onHoldSession = null;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} while (allowedTasks && allowedTasks.length > 0 && !this.killed && this.isOnHold);
|
} while (allowedTasks && allowedTasks.length > 0 && !this.killed && this.isOnHold);
|
||||||
|
|||||||
144
lib/tasks/dub.js
Normal file
144
lib/tasks/dub.js
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
const {TaskName} = require('../utils/constants');
|
||||||
|
const TtsTask = require('./tts-task');
|
||||||
|
const assert = require('assert');
|
||||||
|
const parseDecibels = require('../utils/parse-decibels');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dub task: add or remove additional audio tracks into the call
|
||||||
|
*/
|
||||||
|
class TaskDub extends TtsTask {
|
||||||
|
constructor(logger, opts, parentTask) {
|
||||||
|
super(logger, opts, parentTask);
|
||||||
|
|
||||||
|
this.logger.debug({opts: this.data}, 'TaskDub constructor');
|
||||||
|
['action', 'track', 'play', 'say', 'loop'].forEach((prop) => {
|
||||||
|
this[prop] = this.data[prop];
|
||||||
|
});
|
||||||
|
this.gain = parseDecibels(this.data.gain);
|
||||||
|
|
||||||
|
assert.ok(this.action, 'TaskDub: action is required');
|
||||||
|
assert.ok(this.track, 'TaskDub: track is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
get name() { return TaskName.Dub; }
|
||||||
|
|
||||||
|
async exec(cs, {ep}) {
|
||||||
|
super.exec(cs);
|
||||||
|
|
||||||
|
try {
|
||||||
|
switch (this.action) {
|
||||||
|
case 'addTrack':
|
||||||
|
await this._addTrack(cs, ep);
|
||||||
|
break;
|
||||||
|
case 'removeTrack':
|
||||||
|
await this._removeTrack(cs, ep);
|
||||||
|
break;
|
||||||
|
case 'silenceTrack':
|
||||||
|
await this._silenceTrack(cs, ep);
|
||||||
|
break;
|
||||||
|
case 'playOnTrack':
|
||||||
|
await this._playOnTrack(cs, ep);
|
||||||
|
break;
|
||||||
|
case 'sayOnTrack':
|
||||||
|
await this._sayOnTrack(cs, ep);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new Error(`TaskDub: unsupported action ${this.action}`);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.error(err, 'Error executing dub task');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async _addTrack(cs, ep) {
|
||||||
|
this.logger.info(`adding track: ${this.track}`);
|
||||||
|
await ep.dub({
|
||||||
|
action: 'addTrack',
|
||||||
|
track: this.track
|
||||||
|
});
|
||||||
|
|
||||||
|
if (this.play) await this._playOnTrack(cs, ep);
|
||||||
|
else if (this.say) await this._sayOnTrack(cs, ep);
|
||||||
|
}
|
||||||
|
|
||||||
|
async _removeTrack(_cs, ep) {
|
||||||
|
this.logger.info(`removing track: ${this.track}`);
|
||||||
|
await ep.dub({
|
||||||
|
action: 'removeTrack',
|
||||||
|
track: this.track
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async _silenceTrack(_cs, ep) {
|
||||||
|
this.logger.info(`silencing track: ${this.track}`);
|
||||||
|
await ep.dub({
|
||||||
|
action: 'silenceTrack',
|
||||||
|
track: this.track
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async _playOnTrack(_cs, ep) {
|
||||||
|
this.logger.info(`playing on track: ${this.track}`);
|
||||||
|
await ep.dub({
|
||||||
|
action: 'playOnTrack',
|
||||||
|
track: this.track,
|
||||||
|
play: this.play,
|
||||||
|
loop: this.loop ? 'loop' : 'once',
|
||||||
|
gain: this.gain
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async _sayOnTrack(cs, ep) {
|
||||||
|
const text = this.say.text || this.say;
|
||||||
|
this.synthesizer = this.say.synthesizer || {};
|
||||||
|
|
||||||
|
if (Object.keys(this.synthesizer).length) {
|
||||||
|
this.logger.info({synthesizer: this.synthesizer},
|
||||||
|
`saying on track ${this.track}: ${text} with synthesizer options`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.logger.info(`saying on track ${this.track}: ${text}`);
|
||||||
|
}
|
||||||
|
this.synthesizer = this.synthesizer || {};
|
||||||
|
|
||||||
|
this.text = [text];
|
||||||
|
|
||||||
|
const vendor = this.synthesizer.vendor && this.synthesizer.vendor !== 'default' ?
|
||||||
|
this.synthesizer.vendor :
|
||||||
|
cs.speechSynthesisVendor;
|
||||||
|
const language = this.synthesizer.language && this.synthesizer.language !== 'default' ?
|
||||||
|
this.synthesizer.language :
|
||||||
|
cs.speechSynthesisLanguage ;
|
||||||
|
const voice = this.synthesizer.voice && this.synthesizer.voice !== 'default' ?
|
||||||
|
this.synthesizer.voice :
|
||||||
|
cs.speechSynthesisVoice;
|
||||||
|
const label = this.synthesizer.label && this.synthesizer.label !== 'default' ?
|
||||||
|
this.synthesizer.label :
|
||||||
|
cs.speechSynthesisLabel;
|
||||||
|
|
||||||
|
const disableTtsStreaming = false;
|
||||||
|
const filepath = await this._synthesizeWithSpecificVendor(cs, ep, {
|
||||||
|
vendor, language, voice, label, disableTtsStreaming
|
||||||
|
});
|
||||||
|
assert.ok(filepath.length === 1, 'TaskDub: no filepath returned from synthesizer');
|
||||||
|
|
||||||
|
const path = filepath[0];
|
||||||
|
if (!path.startsWith('say:{')) {
|
||||||
|
/* we have a local file of mp3 or r8 of synthesized speech audio to play */
|
||||||
|
this.logger.info(`playing synthesized speech from file on track ${this.track}: ${path}`);
|
||||||
|
this.play = path;
|
||||||
|
await this._playOnTrack(cs, ep);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.logger.info(`doing actual text to speech file on track ${this.track}: ${path}`);
|
||||||
|
await ep.dub({
|
||||||
|
action: 'sayOnTrack',
|
||||||
|
track: this.track,
|
||||||
|
say: path,
|
||||||
|
gain: this.gain
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TaskDub;
|
||||||
@@ -338,6 +338,7 @@ class TaskEnqueue extends Task {
|
|||||||
this.logger.error({err}, `TaskEnqueue:_playHook error retrieving list info for queue ${this.queueName}`);
|
this.logger.error({err}, `TaskEnqueue:_playHook error retrieving list info for queue ${this.queueName}`);
|
||||||
}
|
}
|
||||||
const json = await cs.application.requestor.request('verb:hook', hook, params, httpHeaders);
|
const json = await cs.application.requestor.request('verb:hook', hook, params, httpHeaders);
|
||||||
|
this.logger.debug({json}, 'TaskEnqueue:_playHook: received response from waitHook');
|
||||||
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
||||||
|
|
||||||
const allowedTasks = tasks.filter((t) => allowed.includes(t.name));
|
const allowedTasks = tasks.filter((t) => allowed.includes(t.name));
|
||||||
|
|||||||
@@ -10,7 +10,9 @@ const {
|
|||||||
IbmTranscriptionEvents,
|
IbmTranscriptionEvents,
|
||||||
NvidiaTranscriptionEvents,
|
NvidiaTranscriptionEvents,
|
||||||
JambonzTranscriptionEvents,
|
JambonzTranscriptionEvents,
|
||||||
AssemblyAiTranscriptionEvents
|
AssemblyAiTranscriptionEvents,
|
||||||
|
VadDetection,
|
||||||
|
VerbioTranscriptionEvents
|
||||||
} = require('../utils/constants.json');
|
} = require('../utils/constants.json');
|
||||||
const {
|
const {
|
||||||
JAMBONES_GATHER_EARLY_HINTS_MATCH,
|
JAMBONES_GATHER_EARLY_HINTS_MATCH,
|
||||||
@@ -27,9 +29,13 @@ class TaskGather extends SttTask {
|
|||||||
[
|
[
|
||||||
'finishOnKey', 'input', 'numDigits', 'minDigits', 'maxDigits',
|
'finishOnKey', 'input', 'numDigits', 'minDigits', 'maxDigits',
|
||||||
'interDigitTimeout', 'partialResultHook', 'bargein', 'dtmfBargein',
|
'interDigitTimeout', 'partialResultHook', 'bargein', 'dtmfBargein',
|
||||||
'speechTimeout', 'timeout', 'say', 'play'
|
'speechTimeout', 'timeout', 'say', 'play', 'actionHookDelayAction', 'fillerNoise', 'vad'
|
||||||
].forEach((k) => this[k] = this.data[k]);
|
].forEach((k) => this[k] = this.data[k]);
|
||||||
|
|
||||||
|
// gather default input is digits
|
||||||
|
if (!this.input) {
|
||||||
|
this.input = ['digits'];
|
||||||
|
}
|
||||||
/* when collecting dtmf, bargein on dtmf is true unless explicitly set to false */
|
/* when collecting dtmf, bargein on dtmf is true unless explicitly set to false */
|
||||||
if (this.dtmfBargein !== false && this.input.includes('digits')) this.dtmfBargein = true;
|
if (this.dtmfBargein !== false && this.input.includes('digits')) this.dtmfBargein = true;
|
||||||
|
|
||||||
@@ -37,7 +43,8 @@ class TaskGather extends SttTask {
|
|||||||
this.timeout = this.timeout === 0 ? 0 : (this.timeout || 15) * 1000;
|
this.timeout = this.timeout === 0 ? 0 : (this.timeout || 15) * 1000;
|
||||||
this.interim = !!this.partialResultHook || this.bargein || (this.timeout > 0);
|
this.interim = !!this.partialResultHook || this.bargein || (this.timeout > 0);
|
||||||
this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true;
|
this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true;
|
||||||
this.minBargeinWordCount = this.data.minBargeinWordCount || 1;
|
this.minBargeinWordCount = this.data.minBargeinWordCount !== undefined ? this.data.minBargeinWordCount : 1;
|
||||||
|
this._vadEnabled = this.minBargeinWordCount === 0;
|
||||||
if (this.data.recognizer) {
|
if (this.data.recognizer) {
|
||||||
/* continuous ASR (i.e. compile transcripts until a special timeout or dtmf key) */
|
/* continuous ASR (i.e. compile transcripts until a special timeout or dtmf key) */
|
||||||
this.asrTimeout = typeof this.data.recognizer.asrTimeout === 'number' ?
|
this.asrTimeout = typeof this.data.recognizer.asrTimeout === 'number' ?
|
||||||
@@ -71,6 +78,7 @@ class TaskGather extends SttTask {
|
|||||||
/* buffer speech for continuous asr */
|
/* buffer speech for continuous asr */
|
||||||
this._bufferedTranscripts = [];
|
this._bufferedTranscripts = [];
|
||||||
this.partialTranscriptsCount = 0;
|
this.partialTranscriptsCount = 0;
|
||||||
|
this.bugname_prefix = 'gather_';
|
||||||
}
|
}
|
||||||
|
|
||||||
get name() { return TaskName.Gather; }
|
get name() { return TaskName.Gather; }
|
||||||
@@ -86,6 +94,18 @@ class TaskGather extends SttTask {
|
|||||||
(this.playTask && this.playTask.earlyMedia);
|
(this.playTask && this.playTask.earlyMedia);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get hasFillerNoise() {
|
||||||
|
return Object.keys(this.fillerNoise).length > 0 && this.fillerNoise.enabled !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
get fillerNoiseUrl() {
|
||||||
|
return this.fillerNoise.url;
|
||||||
|
}
|
||||||
|
|
||||||
|
get fillerNoiseStartDelaySecs() {
|
||||||
|
return this.fillerNoise.startDelaySecs;
|
||||||
|
}
|
||||||
|
|
||||||
get summary() {
|
get summary() {
|
||||||
let s = `${this.name}{`;
|
let s = `${this.name}{`;
|
||||||
if (this.input.length === 2) s += 'inputs=[speech,digits],';
|
if (this.input.length === 2) s += 'inputs=[speech,digits],';
|
||||||
@@ -103,9 +123,19 @@ class TaskGather extends SttTask {
|
|||||||
|
|
||||||
async exec(cs, {ep}) {
|
async exec(cs, {ep}) {
|
||||||
this.logger.debug({options: this.data}, 'Gather:exec');
|
this.logger.debug({options: this.data}, 'Gather:exec');
|
||||||
await super.exec(cs);
|
await super.exec(cs, {ep});
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||||
|
|
||||||
|
this.fillerNoise = {
|
||||||
|
...(cs.fillerNoise || {}),
|
||||||
|
...(this.fillerNoise || {})
|
||||||
|
};
|
||||||
|
|
||||||
|
this.vad = {
|
||||||
|
...(cs.vad || {}),
|
||||||
|
...(this.vad || {})
|
||||||
|
};
|
||||||
|
|
||||||
if (cs.hasGlobalSttHints && !this.maskGlobalSttHints) {
|
if (cs.hasGlobalSttHints && !this.maskGlobalSttHints) {
|
||||||
const {hints, hintsBoost} = cs.globalSttHints;
|
const {hints, hintsBoost} = cs.globalSttHints;
|
||||||
const setOfHints = new Set((this.data.recognizer.hints || [])
|
const setOfHints = new Set((this.data.recognizer.hints || [])
|
||||||
@@ -116,14 +146,6 @@ class TaskGather extends SttTask {
|
|||||||
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
||||||
'Gather:exec - applying global sttHints');
|
'Gather:exec - applying global sttHints');
|
||||||
}
|
}
|
||||||
if (cs.hasAltLanguages) {
|
|
||||||
this.data.recognizer.altLanguages = this.data.recognizer.altLanguages.concat(cs.altLanguages);
|
|
||||||
this.logger.debug({altLanguages: this.data.recognizer?.altLanguages},
|
|
||||||
'Gather:exec - applying altLanguages');
|
|
||||||
}
|
|
||||||
if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) {
|
|
||||||
this.data.recognizer.punctuation = cs.globalSttPunctuation;
|
|
||||||
}
|
|
||||||
if (!this.isContinuousAsr && cs.isContinuousAsr) {
|
if (!this.isContinuousAsr && cs.isContinuousAsr) {
|
||||||
this.isContinuousAsr = true;
|
this.isContinuousAsr = true;
|
||||||
this.asrTimeout = cs.asrTimeout * 1000;
|
this.asrTimeout = cs.asrTimeout * 1000;
|
||||||
@@ -141,58 +163,30 @@ class TaskGather extends SttTask {
|
|||||||
this.interim = true;
|
this.interim = true;
|
||||||
this.logger.debug('Gather:exec - early hints match enabled');
|
this.logger.debug('Gather:exec - early hints match enabled');
|
||||||
}
|
}
|
||||||
|
// actionHook delay
|
||||||
|
this._hookDelayEn = cs.actionHookDelayEnabled || !!this.actionHookDelayAction;
|
||||||
|
|
||||||
this.ep = ep;
|
this._hookDelayActions = this.actionHookDelayAction?.actions || cs.actionHookDelayActions || [];
|
||||||
if ('default' === this.vendor || !this.vendor) {
|
|
||||||
this.vendor = cs.speechRecognizerVendor;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.vendor = this.vendor;
|
|
||||||
}
|
|
||||||
if ('default' === this.language || !this.language) {
|
|
||||||
this.language = cs.speechRecognizerLanguage;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.language = this.language;
|
|
||||||
}
|
|
||||||
if ('default' === this.label || !this.label) {
|
|
||||||
this.label = cs.speechRecognizerLabel;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.label = this.label;
|
|
||||||
}
|
|
||||||
// Fallback options
|
|
||||||
if ('default' === this.fallbackVendor || !this.fallbackVendor) {
|
|
||||||
this.fallbackVendor = cs.fallbackSpeechRecognizerVendor;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.fallbackVendor = this.fallbackVendor;
|
|
||||||
}
|
|
||||||
if ('default' === this.fallbackLanguage || !this.fallbackLanguage) {
|
|
||||||
this.fallbackLanguage = cs.fallbackSpeechRecognizerLanguage;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.fallbackLanguage = this.fallbackLanguage;
|
|
||||||
}
|
|
||||||
if ('default' === this.fallbackLabel || !this.fallbackLabel) {
|
|
||||||
this.fallbackLabel = cs.fallbackSpeechRecognizerLabel;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.fallbackLabel = this.fallbackLabel;
|
|
||||||
}
|
|
||||||
if (!this.data.recognizer.vendor) {
|
|
||||||
this.data.recognizer.vendor = this.vendor;
|
|
||||||
}
|
|
||||||
if (this.vendor === 'cobalt' && !this.data.recognizer.model) {
|
|
||||||
// By default, application saves cobalt model in language
|
|
||||||
this.data.recognizer.model = cs.speechRecognizerLanguage;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.needsStt && !this.sttCredentials) {
|
// Only enable NoResponseTimeout if there is _hookDelayActions
|
||||||
try {
|
this._hookNoResponseTimeout = (this._hookDelayActions?.length ?
|
||||||
this.sttCredentials = await this._initSpeechCredentials(cs, this.vendor, this.label);
|
(this.actionHookDelayAction?.noResponseTimeout || cs.actionHookNoResponseTimeout || 0)
|
||||||
} catch (error) {
|
: 0) * 1000;
|
||||||
if (this.fallbackVendor && this.isHandledByPrimaryProvider) {
|
|
||||||
await this._fallback();
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* when using cobalt model is required */
|
this._hookNoResponseGiveUpTimeout = (this.actionHookDelayAction?.noResponseGiveUpTimeout ||
|
||||||
if (this.vendor === 'cobalt' && !this.data.recognizer.model) {
|
cs.actionHookNoResponseGiveUpTimeout || 0) * 1000;
|
||||||
this.notifyError({ msg: 'ASR error', details:'Cobalt requires a model to be specified'});
|
|
||||||
throw new Error('Cobalt requires a model to be specified');
|
this._hookDelayRetries = this.actionHookDelayAction?.retries || cs.actionHookDelayRetries || 1;
|
||||||
}
|
this._hookDelayRetryCount = 0;
|
||||||
|
this.hookDelayActionOpts = {
|
||||||
|
enabled: this._hookDelayEn,
|
||||||
|
actions: this._hookDelayActions,
|
||||||
|
noResponseTimeoutMs: this._hookNoResponseTimeout,
|
||||||
|
noResponseGiveUpTimeoutMs: this._hookNoResponseGiveUpTimeout,
|
||||||
|
retries: this._hookDelayRetries
|
||||||
|
};
|
||||||
|
|
||||||
|
this._startVad();
|
||||||
|
|
||||||
const startListening = async(cs, ep) => {
|
const startListening = async(cs, ep) => {
|
||||||
this._startTimer();
|
this._startTimer();
|
||||||
@@ -207,12 +201,7 @@ class TaskGather extends SttTask {
|
|||||||
this._startTranscribing(ep);
|
this._startTranscribing(ep);
|
||||||
return updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
|
return updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (this.fallbackVendor && this.isHandledByPrimaryProvider) {
|
await this._startFallback(cs, ep, {error: e});
|
||||||
await this._fallback();
|
|
||||||
startListening(cs, ep);
|
|
||||||
} else {
|
|
||||||
this.logger.error({error: e}, 'error in initSpeech');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -220,13 +209,9 @@ class TaskGather extends SttTask {
|
|||||||
try {
|
try {
|
||||||
if (this.sayTask) {
|
if (this.sayTask) {
|
||||||
const {span, ctx} = this.startChildSpan(`nested:${this.sayTask.summary}`);
|
const {span, ctx} = this.startChildSpan(`nested:${this.sayTask.summary}`);
|
||||||
this.sayTask.span = span;
|
const process = () => {
|
||||||
this.sayTask.ctx = ctx;
|
|
||||||
this.sayTask.exec(cs, {ep}); // kicked off, _not_ waiting for it to complete
|
|
||||||
this.sayTask.on('playDone', (err) => {
|
|
||||||
span.end();
|
|
||||||
if (err) this.logger.error({err}, 'Gather:exec Error playing tts');
|
|
||||||
this.logger.debug('Gather: nested say task completed');
|
this.logger.debug('Gather: nested say task completed');
|
||||||
|
this._stopVad();
|
||||||
if (!this.killed) {
|
if (!this.killed) {
|
||||||
startListening(cs, ep);
|
startListening(cs, ep);
|
||||||
if (this.input.includes('speech') && this.vendor === 'nuance' && this.listenDuringPrompt) {
|
if (this.input.includes('speech') && this.vendor === 'nuance' && this.listenDuringPrompt) {
|
||||||
@@ -236,17 +221,24 @@ class TaskGather extends SttTask {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
this.sayTask.span = span;
|
||||||
|
this.sayTask.ctx = ctx;
|
||||||
|
this.sayTask.exec(cs, {ep}) // kicked off, _not_ waiting for it to complete
|
||||||
|
.catch((err) => {
|
||||||
|
process();
|
||||||
|
});
|
||||||
|
this.sayTask.on('playDone', (err) => {
|
||||||
|
span.end();
|
||||||
|
if (err) this.logger.error({err}, 'Gather:exec Error playing tts');
|
||||||
|
process();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (this.playTask) {
|
else if (this.playTask) {
|
||||||
const {span, ctx} = this.startChildSpan(`nested:${this.playTask.summary}`);
|
const {span, ctx} = this.startChildSpan(`nested:${this.playTask.summary}`);
|
||||||
this.playTask.span = span;
|
const process = () => {
|
||||||
this.playTask.ctx = ctx;
|
|
||||||
this.playTask.exec(cs, {ep}); // kicked off, _not_ waiting for it to complete
|
|
||||||
this.playTask.on('playDone', (err) => {
|
|
||||||
span.end();
|
|
||||||
if (err) this.logger.error({err}, 'Gather:exec Error playing url');
|
|
||||||
this.logger.debug('Gather: nested play task completed');
|
this.logger.debug('Gather: nested play task completed');
|
||||||
|
this._stopVad();
|
||||||
if (!this.killed) {
|
if (!this.killed) {
|
||||||
startListening(cs, ep);
|
startListening(cs, ep);
|
||||||
if (this.input.includes('speech') && this.vendor === 'nuance' && this.listenDuringPrompt) {
|
if (this.input.includes('speech') && this.vendor === 'nuance' && this.listenDuringPrompt) {
|
||||||
@@ -256,6 +248,17 @@ class TaskGather extends SttTask {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
this.playTask.span = span;
|
||||||
|
this.playTask.ctx = ctx;
|
||||||
|
this.playTask.exec(cs, {ep}) // kicked off, _not_ waiting for it to complete
|
||||||
|
.catch((err) => {
|
||||||
|
process();
|
||||||
|
});
|
||||||
|
this.playTask.on('playDone', (err) => {
|
||||||
|
span.end();
|
||||||
|
if (err) this.logger.error({err}, 'Gather:exec Error playing url');
|
||||||
|
process();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -268,9 +271,14 @@ class TaskGather extends SttTask {
|
|||||||
|
|
||||||
if (this.input.includes('speech') && this.listenDuringPrompt) {
|
if (this.input.includes('speech') && this.listenDuringPrompt) {
|
||||||
await this._setSpeechHandlers(cs, ep);
|
await this._setSpeechHandlers(cs, ep);
|
||||||
this._startTranscribing(ep);
|
if (!this.resolved && !this.killed) {
|
||||||
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid)
|
this._startTranscribing(ep);
|
||||||
.catch(() => {/*already logged error */});
|
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid)
|
||||||
|
.catch(() => {/*already logged error */});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.logger.info('Gather:exec - task was killed or resolved quickly, not starting transcription');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) {
|
if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) {
|
||||||
@@ -278,20 +286,24 @@ class TaskGather extends SttTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.awaitTaskDone();
|
await this.awaitTaskDone();
|
||||||
|
this._killAudio(cs);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err, 'TaskGather:exec error');
|
this.logger.error(err, 'TaskGather:exec error');
|
||||||
}
|
}
|
||||||
this.removeSpeechListeners(ep);
|
this.removeCustomEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
kill(cs) {
|
kill(cs) {
|
||||||
super.kill(cs);
|
super.kill(cs);
|
||||||
this._killAudio(cs);
|
this._killAudio(cs);
|
||||||
|
this._killActionHookDelayAction();
|
||||||
|
this._clearFillerNoiseTimer();
|
||||||
this.ep.removeAllListeners('dtmf');
|
this.ep.removeAllListeners('dtmf');
|
||||||
clearTimeout(this.interDigitTimer);
|
clearTimeout(this.interDigitTimer);
|
||||||
this._clearAsrTimer();
|
this._clearAsrTimer();
|
||||||
this.playTask?.span.end();
|
this.playTask?.span.end();
|
||||||
this.sayTask?.span.end();
|
this.sayTask?.span.end();
|
||||||
|
this._stopVad();
|
||||||
this._resolve('killed');
|
this._resolve('killed');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,6 +331,16 @@ class TaskGather extends SttTask {
|
|||||||
this._resolve('dtmf-terminator-key');
|
this._resolve('dtmf-terminator-key');
|
||||||
}
|
}
|
||||||
else if (this.input.includes('digits')) {
|
else if (this.input.includes('digits')) {
|
||||||
|
if (this.digitBuffer.length === 0 && this.needsStt) {
|
||||||
|
// DTMF is higher priority than STT.
|
||||||
|
this.removeCustomEventListeners();
|
||||||
|
ep.stopTranscription({
|
||||||
|
vendor: this.vendor,
|
||||||
|
bugname: this.bugname,
|
||||||
|
})
|
||||||
|
.catch((err) => this.logger.error({err},
|
||||||
|
` Received DTMF, Error stopping transcription for vendor ${this.vendor}`));
|
||||||
|
}
|
||||||
this.digitBuffer += evt.dtmf;
|
this.digitBuffer += evt.dtmf;
|
||||||
const len = this.digitBuffer.length;
|
const len = this.digitBuffer.length;
|
||||||
if (len === this.numDigits || len === this.maxDigits) {
|
if (len === this.numDigits || len === this.maxDigits) {
|
||||||
@@ -351,38 +373,36 @@ class TaskGather extends SttTask {
|
|||||||
if (this.data.recognizer?.deepgramOptions?.shortUtterance) this.shortUtterance = true;
|
if (this.data.recognizer?.deepgramOptions?.shortUtterance) this.shortUtterance = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
const opts = this.setChannelVarsForStt(this, this.sttCredentials, this.data.recognizer);
|
const opts = this.setChannelVarsForStt(this, this.sttCredentials, this.language, this.data.recognizer);
|
||||||
switch (this.vendor) {
|
switch (this.vendor) {
|
||||||
case 'google':
|
case 'google':
|
||||||
this.bugname = 'google_transcribe';
|
this.bugname = `${this.bugname_prefix}google_transcribe`;
|
||||||
ep.addCustomEventListener(GoogleTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
ep.addCustomEventListener(GoogleTranscriptionEvents.EndOfUtterance, this._onEndOfUtterance.bind(this, cs, ep));
|
ep, GoogleTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(GoogleTranscriptionEvents.VadDetected, this._onVadDetected.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
|
ep, GoogleTranscriptionEvents.EndOfUtterance, this._onEndOfUtterance.bind(this, cs, ep));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'aws':
|
case 'aws':
|
||||||
case 'polly':
|
case 'polly':
|
||||||
this.bugname = 'aws_transcribe';
|
this.bugname = `${this.bugname_prefix}aws_transcribe`;
|
||||||
ep.addCustomEventListener(AwsTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(ep, AwsTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(AwsTranscriptionEvents.VadDetected, this._onVadDetected.bind(this, cs, ep));
|
|
||||||
break;
|
break;
|
||||||
case 'microsoft':
|
case 'microsoft':
|
||||||
this.bugname = 'azure_transcribe';
|
this.bugname = `${this.bugname_prefix}azure_transcribe`;
|
||||||
ep.addCustomEventListener(AzureTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
ep.addCustomEventListener(AzureTranscriptionEvents.NoSpeechDetected,
|
ep, AzureTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
this._onNoSpeechDetected.bind(this, cs, ep));
|
//this.addCustomEventListener(ep, AzureTranscriptionEvents.NoSpeechDetected,
|
||||||
ep.addCustomEventListener(AzureTranscriptionEvents.VadDetected, this._onVadDetected.bind(this, cs, ep));
|
//this._onNoSpeechDetected.bind(this, cs, ep));
|
||||||
break;
|
break;
|
||||||
case 'nuance':
|
case 'nuance':
|
||||||
this.bugname = 'nuance_transcribe';
|
this.bugname = `${this.bugname_prefix}nuance_transcribe`;
|
||||||
ep.addCustomEventListener(NuanceTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, NuanceTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep));
|
this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(NuanceTranscriptionEvents.StartOfSpeech,
|
this.addCustomEventListener(ep, NuanceTranscriptionEvents.StartOfSpeech,
|
||||||
this._onStartOfSpeech.bind(this, cs, ep));
|
this._onStartOfSpeech.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(NuanceTranscriptionEvents.TranscriptionComplete,
|
this.addCustomEventListener(ep, NuanceTranscriptionEvents.TranscriptionComplete,
|
||||||
this._onTranscriptionComplete.bind(this, cs, ep));
|
this._onTranscriptionComplete.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(NuanceTranscriptionEvents.VadDetected,
|
|
||||||
this._onVadDetected.bind(this, cs, ep));
|
|
||||||
|
|
||||||
/* stall timers until prompt finishes playing */
|
/* stall timers until prompt finishes playing */
|
||||||
if ((this.sayTask || this.playTask) && this.listenDuringPrompt) {
|
if ((this.sayTask || this.playTask) && this.listenDuringPrompt) {
|
||||||
@@ -391,24 +411,30 @@ class TaskGather extends SttTask {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'deepgram':
|
case 'deepgram':
|
||||||
this.bugname = 'deepgram_transcribe';
|
this.bugname = `${this.bugname_prefix}deepgram_transcribe`;
|
||||||
ep.addCustomEventListener(DeepgramTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
ep.addCustomEventListener(DeepgramTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
ep, DeepgramTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(DeepgramTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||||
|
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.ConnectFailure,
|
||||||
this._onVendorConnectFailure.bind(this, cs, ep));
|
this._onVendorConnectFailure.bind(this, cs, ep));
|
||||||
|
|
||||||
/* if app sets deepgramOptions.utteranceEndMs they essentially want continuous asr */
|
|
||||||
if (opts.DEEPGRAM_SPEECH_UTTERANCE_END_MS) this.isContinuousAsr = true;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'soniox':
|
case 'soniox':
|
||||||
this.bugname = 'soniox_transcribe';
|
this.bugname = `${this.bugname_prefix}soniox_transcribe`;
|
||||||
ep.addCustomEventListener(SonioxTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
|
ep, SonioxTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'verbio':
|
||||||
|
this.bugname = `${this.bugname_prefix}verbio_transcribe`;
|
||||||
|
this.addCustomEventListener(
|
||||||
|
ep, VerbioTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'cobalt':
|
case 'cobalt':
|
||||||
this.bugname = 'cobalt_transcribe';
|
this.bugname = `${this.bugname_prefix}cobalt_transcribe`;
|
||||||
ep.addCustomEventListener(CobaltTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
|
ep, CobaltTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
|
|
||||||
/* cobalt doesnt have language, it has model, which is required */
|
/* cobalt doesnt have language, it has model, which is required */
|
||||||
if (!this.data.recognizer.model) {
|
if (!this.data.recognizer.model) {
|
||||||
@@ -437,23 +463,21 @@ class TaskGather extends SttTask {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ibm':
|
case 'ibm':
|
||||||
this.bugname = 'ibm_transcribe';
|
this.bugname = `${this.bugname_prefix}ibm_transcribe`;
|
||||||
ep.addCustomEventListener(IbmTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(ep, IbmTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(IbmTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
this.addCustomEventListener(ep, IbmTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(IbmTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, IbmTranscriptionEvents.ConnectFailure,
|
||||||
this._onVendorConnectFailure.bind(this, cs, ep));
|
this._onVendorConnectFailure.bind(this, cs, ep));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'nvidia':
|
case 'nvidia':
|
||||||
this.bugname = 'nvidia_transcribe';
|
this.bugname = `${this.bugname_prefix}nvidia_transcribe`;
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, NvidiaTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep));
|
this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.StartOfSpeech,
|
this.addCustomEventListener(ep, NvidiaTranscriptionEvents.StartOfSpeech,
|
||||||
this._onStartOfSpeech.bind(this, cs, ep));
|
this._onStartOfSpeech.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.TranscriptionComplete,
|
this.addCustomEventListener(ep, NvidiaTranscriptionEvents.TranscriptionComplete,
|
||||||
this._onTranscriptionComplete.bind(this, cs, ep));
|
this._onTranscriptionComplete.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.VadDetected,
|
|
||||||
this._onVadDetected.bind(this, cs, ep));
|
|
||||||
|
|
||||||
/* I think nvidia has this (??) - stall timers until prompt finishes playing */
|
/* I think nvidia has this (??) - stall timers until prompt finishes playing */
|
||||||
if ((this.sayTask || this.playTask) && this.listenDuringPrompt) {
|
if ((this.sayTask || this.playTask) && this.listenDuringPrompt) {
|
||||||
@@ -462,20 +486,22 @@ class TaskGather extends SttTask {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'assemblyai':
|
case 'assemblyai':
|
||||||
this.bugname = 'assemblyai_transcribe';
|
this.bugname = `${this.bugname_prefix}assemblyai_transcribe`;
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep));
|
this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
|
ep, AssemblyAiTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
|
||||||
|
this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.ConnectFailure,
|
||||||
this._onVendorConnectFailure.bind(this, cs, ep));
|
this._onVendorConnectFailure.bind(this, cs, ep));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (this.vendor.startsWith('custom:')) {
|
if (this.vendor.startsWith('custom:')) {
|
||||||
this.bugname = `${this.vendor}_transcribe`;
|
this.bugname = `${this.bugname_prefix}${this.vendor}_transcribe`;
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
this.addCustomEventListener(
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
ep, JambonzTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||||
|
this.addCustomEventListener(ep, JambonzTranscriptionEvents.ConnectFailure,
|
||||||
this._onVendorConnectFailure.bind(this, cs, ep));
|
this._onVendorConnectFailure.bind(this, cs, ep));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -487,7 +513,7 @@ class TaskGather extends SttTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* common handler for all stt engine errors */
|
/* common handler for all stt engine errors */
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.Error, this._onJambonzError.bind(this, cs, ep));
|
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Error, this._onJambonzError.bind(this, cs, ep));
|
||||||
await ep.set(opts)
|
await ep.set(opts)
|
||||||
.catch((err) => this.logger.info(err, 'Error setting channel variables'));
|
.catch((err) => this.logger.info(err, 'Error setting channel variables'));
|
||||||
}
|
}
|
||||||
@@ -528,7 +554,10 @@ class TaskGather extends SttTask {
|
|||||||
this._clearTimer();
|
this._clearTimer();
|
||||||
this._timeoutTimer = setTimeout(() => {
|
this._timeoutTimer = setTimeout(() => {
|
||||||
if (this.isContinuousAsr) this._startAsrTimer();
|
if (this.isContinuousAsr) this._startAsrTimer();
|
||||||
else this._resolve(this.digitBuffer.length >= this.minDigits ? 'dtmf-num-digits' : 'timeout');
|
if (this.interDigitTimer) return; // let the inter-digit timer complete
|
||||||
|
else {
|
||||||
|
this._resolve(this.digitBuffer.length >= this.minDigits ? 'dtmf-num-digits' : 'timeout');
|
||||||
|
}
|
||||||
}, this.timeout);
|
}, this.timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,7 +565,9 @@ class TaskGather extends SttTask {
|
|||||||
if (this._timeoutTimer) {
|
if (this._timeoutTimer) {
|
||||||
clearTimeout(this._timeoutTimer);
|
clearTimeout(this._timeoutTimer);
|
||||||
this._timeoutTimer = null;
|
this._timeoutTimer = null;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
_startAsrTimer() {
|
_startAsrTimer() {
|
||||||
@@ -545,7 +576,7 @@ class TaskGather extends SttTask {
|
|||||||
this._clearAsrTimer();
|
this._clearAsrTimer();
|
||||||
this._asrTimer = setTimeout(() => {
|
this._asrTimer = setTimeout(() => {
|
||||||
this.logger.debug('_startAsrTimer - asr timer went off');
|
this.logger.debug('_startAsrTimer - asr timer went off');
|
||||||
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language);
|
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
|
||||||
this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
|
this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
|
||||||
}, this.asrTimeout);
|
}, this.asrTimeout);
|
||||||
this.logger.debug(`_startAsrTimer: set for ${this.asrTimeout}ms`);
|
this.logger.debug(`_startAsrTimer: set for ${this.asrTimeout}ms`);
|
||||||
@@ -556,6 +587,103 @@ class TaskGather extends SttTask {
|
|||||||
this._asrTimer = null;
|
this._asrTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_hangupCall() {
|
||||||
|
this.logger.debug('_hangupCall');
|
||||||
|
this.cs.hangup();
|
||||||
|
}
|
||||||
|
|
||||||
|
_actionHookDelaySayAction(verb) {
|
||||||
|
delete verb.verb;
|
||||||
|
this.logger.debug(`_actionHookDelaySayAction ${verb}`);
|
||||||
|
this._actionHookDelaySayTask = makeTask(this.logger, {say: verb}, this);
|
||||||
|
const {span, ctx} = this.startChildSpan(`actionHookDelayAction:${this._actionHookDelaySayTask.summary}`);
|
||||||
|
this._actionHookDelaySayTask.span = span;
|
||||||
|
this._actionHookDelaySayTask.ctx = ctx;
|
||||||
|
this._actionHookDelaySayTask.exec(this.cs, {ep: this.ep});
|
||||||
|
this._actionHookDelaySayTask.on('playDone', (err) => {
|
||||||
|
this._actionHookDelaySayTask = null;
|
||||||
|
span.end();
|
||||||
|
if (err) this.logger.error({err}, 'Gather:actionHookDelay Error playing tts');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_killActionHookDelayAction() {
|
||||||
|
if (this._actionHookDelaySayTask && !this._actionHookDelaySayTask.killed) {
|
||||||
|
this._actionHookDelaySayTask.removeAllListeners('playDone');
|
||||||
|
this._actionHookDelaySayTask.kill(this.cs);
|
||||||
|
this._actionHookDelaySayTask.span.end();
|
||||||
|
this._actionHookDelaySayTask = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._actionHookDelayPlayTask && !this._actionHookDelayPlayTask.killed) {
|
||||||
|
this._actionHookDelayPlayTask.removeAllListeners('playDone');
|
||||||
|
this._actionHookDelayPlayTask.kill(this.cs);
|
||||||
|
this._actionHookDelayPlayTask.span.end();
|
||||||
|
this._actionHookDelayPlayTask = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_actionHookDelayPlayAction(verb) {
|
||||||
|
delete verb.verb;
|
||||||
|
this.logger.debug(`_actionHookDelayPlayAction ${verb}`);
|
||||||
|
this._actionHookDelayPlayTask = makeTask(this.logger, {play: verb}, this);
|
||||||
|
const {span, ctx} = this.startChildSpan(`actionHookDelayAction:${this._actionHookDelayPlayTask.summary}`);
|
||||||
|
this._actionHookDelayPlayTask.span = span;
|
||||||
|
this._actionHookDelayPlayTask.ctx = ctx;
|
||||||
|
this._actionHookDelayPlayTask.exec(this.cs, {ep: this.ep});
|
||||||
|
this._actionHookDelayPlayTask.on('playDone', (err) => {
|
||||||
|
this._actionHookDelayPlayTask = null;
|
||||||
|
span.end();
|
||||||
|
if (err) this.logger.error({err}, 'Gather:actionHookDelay Error playing tts');
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_startActionHookNoResponseTimer() {
|
||||||
|
assert(this._hookNoResponseTimeout > 0);
|
||||||
|
this._clearActionHookNoResponseTimer();
|
||||||
|
this.logger.debug('startActionHookNoResponseTimer');
|
||||||
|
this._actionHookNoResponseTimer = setTimeout(() => {
|
||||||
|
if (this._hookDelayRetryCount >= this._hookDelayRetries) {
|
||||||
|
this._hangupCall();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const verb = this._hookDelayActions[this._hookDelayRetryCount % this._hookDelayActions.length];
|
||||||
|
if (verb.verb === 'say') {
|
||||||
|
this._actionHookDelaySayAction(verb);
|
||||||
|
} else if (verb.verb === 'play') {
|
||||||
|
this._actionHookDelayPlayAction(verb);
|
||||||
|
}
|
||||||
|
this._hookDelayRetryCount++;
|
||||||
|
this._startActionHookNoResponseTimer();
|
||||||
|
|
||||||
|
}, this._hookNoResponseTimeout);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
_clearActionHookNoResponseTimer() {
|
||||||
|
if (this._actionHookNoResponseTimer) {
|
||||||
|
clearTimeout(this._actionHookNoResponseTimer);
|
||||||
|
}
|
||||||
|
this._actionHookNoResponseTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_startActionHookNoResponseGiveUpTimer() {
|
||||||
|
assert(this._hookNoResponseGiveUpTimeout > 0);
|
||||||
|
this._clearActionHookNoResponseGiveUpTimer();
|
||||||
|
this.logger.debug('startActionHookNoResponseGiveUpTimer');
|
||||||
|
this._actionHookNoResponseGiveUpTimer = setTimeout(() => {
|
||||||
|
this._hangupCall();
|
||||||
|
}, this._hookNoResponseGiveUpTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
_clearActionHookNoResponseGiveUpTimer() {
|
||||||
|
if (this._actionHookNoResponseGiveUpTimer) {
|
||||||
|
clearTimeout(this._actionHookNoResponseGiveUpTimer);
|
||||||
|
}
|
||||||
|
this._actionHookNoResponseGiveUpTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
_startFastRecognitionTimer(evt) {
|
_startFastRecognitionTimer(evt) {
|
||||||
assert(this.fastRecognitionTimeout > 0);
|
assert(this.fastRecognitionTimeout > 0);
|
||||||
this._clearFastRecognitionTimer();
|
this._clearFastRecognitionTimer();
|
||||||
@@ -576,7 +704,7 @@ class TaskGather extends SttTask {
|
|||||||
this._clearFinalAsrTimer();
|
this._clearFinalAsrTimer();
|
||||||
this._finalAsrTimer = setTimeout(() => {
|
this._finalAsrTimer = setTimeout(() => {
|
||||||
this.logger.debug('_startFinalAsrTimer - final asr timer went off');
|
this.logger.debug('_startFinalAsrTimer - final asr timer went off');
|
||||||
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language);
|
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
|
||||||
this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
|
this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
|
||||||
}, 1000);
|
}, 1000);
|
||||||
this.logger.debug('_startFinalAsrTimer: set for 1 second');
|
this.logger.debug('_startFinalAsrTimer: set for 1 second');
|
||||||
@@ -587,11 +715,65 @@ class TaskGather extends SttTask {
|
|||||||
this._finalAsrTimer = null;
|
this._finalAsrTimer = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
_startVad() {
|
||||||
|
if (!this._vadStarted && this._vadEnabled) {
|
||||||
|
this.logger.debug('_startVad');
|
||||||
|
this.addCustomEventListener(this.ep, VadDetection.Detection, this._onVadDetected.bind(this, this.cs, this.ep));
|
||||||
|
this.ep?.startVadDetection(this.vad);
|
||||||
|
this._vadStarted = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_stopVad() {
|
||||||
|
if (this._vadStarted) {
|
||||||
|
this.logger.debug('_stopVad');
|
||||||
|
this.ep?.stopVadDetection(this.vad);
|
||||||
|
this.ep?.removeCustomEventListener(VadDetection.Detection, this._onVadDetected);
|
||||||
|
this._vadStarted = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_startFillerNoise() {
|
||||||
|
this.logger.debug('Gather:_startFillerNoise - playing filler noise');
|
||||||
|
this.ep?.play(this.fillerNoise.url);
|
||||||
|
this._fillerNoiseOn = true;
|
||||||
|
this.ep.once('playback-start', (evt) => {
|
||||||
|
if (evt.file === this.fillerNoise.url && !this._fillerNoiseOn) {
|
||||||
|
this.logger.info({evt}, 'Gather:_startFillerNoise - race condition - kill filler noise here');
|
||||||
|
this.ep.api('uuid_break', this.ep.uuid)
|
||||||
|
.catch((err) => this.logger.info(err, 'Error killing filler noise'));
|
||||||
|
return;
|
||||||
|
} else this.logger.debug({evt}, 'Gather:_startFillerNoise - playback started');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_startFillerNoiseTimer() {
|
||||||
|
this._clearFillerNoiseTimer();
|
||||||
|
this._fillerNoiseTimer = setTimeout(() => {
|
||||||
|
this.logger.debug('Gather:_startFillerNoiseTimer - playing filler noise');
|
||||||
|
this._startFillerNoise();
|
||||||
|
}, this.fillerNoise.startDelaySecs * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
_clearFillerNoiseTimer() {
|
||||||
|
if (this._fillerNoiseTimer) clearTimeout(this._fillerNoiseTimer);
|
||||||
|
this._fillerNoiseTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_killFillerNoise() {
|
||||||
|
if (this._fillerNoiseTimer) {
|
||||||
|
this.logger.debug('Gather:_killFillerNoise');
|
||||||
|
this.ep?.api('uuid_break', this.ep.uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_killAudio(cs) {
|
_killAudio(cs) {
|
||||||
if (!this.sayTask && !this.playTask && this.bargein) {
|
if (this.hasFillerNoise || (!this.sayTask && !this.playTask && this.bargein)) {
|
||||||
if (this.ep?.connected && !this.playComplete) {
|
if (this.ep?.connected && (!this.playComplete || this.hasFillerNoise)) {
|
||||||
this.logger.debug('Gather:_killAudio: killing playback of any audio');
|
this.logger.debug('Gather:_killAudio: killing playback of any audio');
|
||||||
this.playComplete = true;
|
this.playComplete = true;
|
||||||
|
this._fillerNoiseOn = false; // in a race, if we just started audio it may sneak through here
|
||||||
this.ep.api('uuid_break', this.ep.uuid)
|
this.ep.api('uuid_break', this.ep.uuid)
|
||||||
.catch((err) => this.logger.info(err, 'Error killing audio'));
|
.catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||||
}
|
}
|
||||||
@@ -613,11 +795,11 @@ class TaskGather extends SttTask {
|
|||||||
// make sure this is not a transcript from answering machine detection
|
// make sure this is not a transcript from answering machine detection
|
||||||
const bugname = fsEvent.getHeader('media-bugname');
|
const bugname = fsEvent.getHeader('media-bugname');
|
||||||
const finished = fsEvent.getHeader('transcription-session-finished');
|
const finished = fsEvent.getHeader('transcription-session-finished');
|
||||||
this.logger.debug({evt, bugname, finished}, `Gather:_onTranscription for vendor ${this.vendor}`);
|
this.logger.debug({evt, bugname, finished, vendor: this.vendor}, 'Gather:_onTranscription raw transcript');
|
||||||
if (bugname && this.bugname !== bugname) return;
|
if (bugname && this.bugname !== bugname) return;
|
||||||
|
if (finished === 'true') return;
|
||||||
|
|
||||||
if (this.vendor === 'ibm' && evt?.state === 'listening') return;
|
if (this.vendor === 'ibm' && evt?.state === 'listening') return;
|
||||||
|
|
||||||
if (this.vendor === 'deepgram' && evt.type === 'UtteranceEnd') {
|
if (this.vendor === 'deepgram' && evt.type === 'UtteranceEnd') {
|
||||||
/* we will only get this when we have set utterance_end_ms */
|
/* we will only get this when we have set utterance_end_ms */
|
||||||
if (this._bufferedTranscripts.length === 0) {
|
if (this._bufferedTranscripts.length === 0) {
|
||||||
@@ -625,14 +807,21 @@ class TaskGather extends SttTask {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript');
|
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript');
|
||||||
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language);
|
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
|
||||||
this._bufferedTranscripts = [];
|
this._bufferedTranscripts = [];
|
||||||
this._resolve('speech', evt);
|
this._resolve('speech', evt);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.vendor === 'deepgram' && evt.type === 'Metadata') {
|
||||||
|
this.logger.debug('Gather:_onTranscription - discarding Metadata event from deepgram');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
evt = this.normalizeTranscription(evt, this.vendor, 1, this.language,
|
||||||
|
this.shortUtterance, this.data.recognizer.punctuation);
|
||||||
|
//this.logger.debug({evt, bugname, finished, vendor: this.vendor}, 'Gather:_onTranscription normalized transcript');
|
||||||
|
|
||||||
evt = this.normalizeTranscription(evt, this.vendor, 1, this.language, this.shortUtterance);
|
|
||||||
if (evt.alternatives.length === 0) {
|
if (evt.alternatives.length === 0) {
|
||||||
this.logger.info({evt}, 'TaskGather:_onTranscription - got empty transcript, continue listening');
|
this.logger.info({evt}, 'TaskGather:_onTranscription - got empty transcript, continue listening');
|
||||||
return;
|
return;
|
||||||
@@ -658,7 +847,9 @@ class TaskGather extends SttTask {
|
|||||||
if (evt.is_final) {
|
if (evt.is_final) {
|
||||||
if (evt.alternatives[0].transcript === '' && !this.callSession.callGone && !this.killed) {
|
if (evt.alternatives[0].transcript === '' && !this.callSession.callGone && !this.killed) {
|
||||||
emptyTranscript = true;
|
emptyTranscript = true;
|
||||||
if (finished === 'true' && ['microsoft', 'deepgram'].includes(this.vendor)) {
|
if (finished === 'true' &&
|
||||||
|
['microsoft', 'deepgram'].includes(this.vendor) &&
|
||||||
|
this._bufferedTranscripts.length === 0) {
|
||||||
this.logger.debug({evt}, 'TaskGather:_onTranscription - got empty transcript from old gather, disregarding');
|
this.logger.debug({evt}, 'TaskGather:_onTranscription - got empty transcript from old gather, disregarding');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -692,7 +883,7 @@ class TaskGather extends SttTask {
|
|||||||
this._clearTimer();
|
this._clearTimer();
|
||||||
if (this._finalAsrTimer) {
|
if (this._finalAsrTimer) {
|
||||||
this._clearFinalAsrTimer();
|
this._clearFinalAsrTimer();
|
||||||
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language);
|
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
|
||||||
return this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
|
return this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
|
||||||
}
|
}
|
||||||
this._startAsrTimer();
|
this._startAsrTimer();
|
||||||
@@ -704,8 +895,8 @@ class TaskGather extends SttTask {
|
|||||||
if (this.bargein && (words + bufferedWords) < this.minBargeinWordCount) {
|
if (this.bargein && (words + bufferedWords) < this.minBargeinWordCount) {
|
||||||
this.logger.debug({evt, words, bufferedWords},
|
this.logger.debug({evt, words, bufferedWords},
|
||||||
'TaskGather:_onTranscription - final transcript but < min barge words');
|
'TaskGather:_onTranscription - final transcript but < min barge words');
|
||||||
this._bufferedTranscripts.push(evt);
|
if (!emptyTranscript) this._bufferedTranscripts.push(evt);
|
||||||
this._startTranscribing(ep);
|
if (!['soniox', 'aws', 'microsoft', 'deepgram'].includes(this.vendor)) this._startTranscribing(ep);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -718,14 +909,11 @@ class TaskGather extends SttTask {
|
|||||||
else if (this.vendor === 'deepgram') {
|
else if (this.vendor === 'deepgram') {
|
||||||
/* compile transcripts into one */
|
/* compile transcripts into one */
|
||||||
if (!emptyTranscript) this._bufferedTranscripts.push(evt);
|
if (!emptyTranscript) this._bufferedTranscripts.push(evt);
|
||||||
if (this.data.recognizer?.deepgramOptions?.utteranceEndMs) {
|
|
||||||
this.logger.debug('TaskGather:_onTranscription - got speech_final waiting for UtteranceEnd event');
|
/* deepgram can send an empty and final transcript; only if we have any buffered should we resolve */
|
||||||
return;
|
if (this._bufferedTranscripts.length === 0) return;
|
||||||
}
|
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
|
||||||
this.logger.debug({evt}, 'TaskGather:_onTranscription - compiling deepgram transcripts');
|
|
||||||
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language);
|
|
||||||
this._bufferedTranscripts = [];
|
this._bufferedTranscripts = [];
|
||||||
this.logger.debug({evt}, 'TaskGather:_onTranscription - compiled deepgram transcripts');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* here is where we return a final transcript */
|
/* here is where we return a final transcript */
|
||||||
@@ -734,14 +922,26 @@ class TaskGather extends SttTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this._clearTimer();
|
/* deepgram can send a non-final transcript but with words that are final, so we need to buffer */
|
||||||
this._startTimer();
|
let emptyTranscript = false;
|
||||||
if (this.bargein && (words + bufferedWords) >= this.minBargeinWordCount) {
|
if (this.vendor === 'deepgram') {
|
||||||
if (!this.playComplete) {
|
const originalEvent = evt.vendor.evt;
|
||||||
this.logger.debug({transcript: evt.alternatives[0].transcript}, 'killing audio due to speech');
|
if (originalEvent.is_final && evt.alternatives[0].transcript !== '') {
|
||||||
this.emit('vad');
|
this.logger.debug({evt}, 'Gather:_onTranscription - buffering a completed (partial) deepgram transcript');
|
||||||
|
this._bufferedTranscripts.push(evt);
|
||||||
|
}
|
||||||
|
if (evt.alternatives[0].transcript === '') emptyTranscript = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!emptyTranscript) {
|
||||||
|
if (this._clearTimer()) this._startTimer();
|
||||||
|
if (this.bargein && (words + bufferedWords) >= this.minBargeinWordCount) {
|
||||||
|
if (!this.playComplete) {
|
||||||
|
this.logger.debug({transcript: evt.alternatives[0].transcript}, 'killing audio due to speech');
|
||||||
|
this.emit('vad');
|
||||||
|
}
|
||||||
|
this._killAudio(cs);
|
||||||
}
|
}
|
||||||
this._killAudio(cs);
|
|
||||||
}
|
}
|
||||||
if (this.fastRecognitionTimeout) {
|
if (this.fastRecognitionTimeout) {
|
||||||
this._startFastRecognitionTimer(evt);
|
this._startFastRecognitionTimer(evt);
|
||||||
@@ -759,14 +959,9 @@ class TaskGather extends SttTask {
|
|||||||
this._sonioxTranscripts.push(evt.vendor.finalWords);
|
this._sonioxTranscripts.push(evt.vendor.finalWords);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* deepgram can send a non-final transcript but with words that are final, so we need to buffer */
|
|
||||||
if (this.vendor === 'deepgram') {
|
/* restart asr timer if we get a partial transcript */
|
||||||
const originalEvent = evt.vendor.evt;
|
if (this.isContinuousAsr) this._startAsrTimer();
|
||||||
if (originalEvent.is_final && evt.alternatives[0].transcript !== '') {
|
|
||||||
this.logger.debug({evt}, 'Gather:_onTranscription - buffering a completed (partial) deepgram transcript');
|
|
||||||
this._bufferedTranscripts.push(evt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_onEndOfUtterance(cs, ep) {
|
_onEndOfUtterance(cs, ep) {
|
||||||
@@ -798,24 +993,45 @@ class TaskGather extends SttTask {
|
|||||||
_onTranscriptionComplete(cs, ep) {
|
_onTranscriptionComplete(cs, ep) {
|
||||||
this.logger.debug('TaskGather:_onTranscriptionComplete');
|
this.logger.debug('TaskGather:_onTranscriptionComplete');
|
||||||
}
|
}
|
||||||
async _onJambonzError(cs, ep, evt) {
|
|
||||||
this.logger.info({evt}, 'TaskGather:_onJambonzError');
|
async _startFallback(cs, ep, evt) {
|
||||||
if (this.isHandledByPrimaryProvider && this.fallbackVendor) {
|
if (this.canFallback) {
|
||||||
ep.stopTranscription({vendor: this.vendor})
|
ep.stopTranscription({
|
||||||
|
vendor: this.vendor,
|
||||||
|
bugname: this.bugname
|
||||||
|
})
|
||||||
.catch((err) => this.logger.error({err}, `Error stopping transcription for primary vendor ${this.vendor}`));
|
.catch((err) => this.logger.error({err}, `Error stopping transcription for primary vendor ${this.vendor}`));
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||||
try {
|
try {
|
||||||
await this._fallback();
|
this.logger.debug('gather:_startFallback');
|
||||||
await this._initSpeech(cs, ep);
|
this.notifyError({ msg: 'ASR error',
|
||||||
|
details:`STT Vendor ${this.vendor} error: ${evt.error || evt.reason}`, failover: 'in progress'});
|
||||||
|
await this._initFallback();
|
||||||
|
this._speechHandlersSet = false;
|
||||||
|
await this._setSpeechHandlers(cs, ep);
|
||||||
this._startTranscribing(ep);
|
this._startTranscribing(ep);
|
||||||
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
|
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
|
||||||
return;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.logger.info({error}, `There is error while falling back to ${this.fallbackVendor}`);
|
this.logger.info({error}, `There is error while falling back to ${this.fallbackVendor}`);
|
||||||
|
this.notifyError({ msg: 'ASR error',
|
||||||
|
details:`STT Vendor ${this.vendor} error: ${evt.error || evt.reason}`, failover: 'not available'});
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.logger.debug('gather:_startFallback no condition for falling back');
|
||||||
|
this.notifyError({ msg: 'ASR error',
|
||||||
|
details:`STT Vendor ${this.vendor} error: ${evt.error || evt.reason}`, failover: 'not available'});
|
||||||
}
|
}
|
||||||
const {writeAlerts, AlertType} = cs.srf.locals;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
async _onJambonzError(cs, ep, evt) {
|
||||||
|
if (this.vendor === 'google' && evt.error_code === 0) {
|
||||||
|
this.logger.info({evt}, 'TaskTranscribe:_onJambonzError - ignoring google error code 0');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.logger.info({evt}, 'TaskGather:_onJambonzError');
|
||||||
|
const {writeAlerts, AlertType} = cs.srf.locals;
|
||||||
if (this.vendor === 'nuance') {
|
if (this.vendor === 'nuance') {
|
||||||
const {code, error} = evt;
|
const {code, error} = evt;
|
||||||
if (code === 404 && error === 'No speech') return this._resolve('timeout');
|
if (code === 404 && error === 'No speech') return this._resolve('timeout');
|
||||||
@@ -828,17 +1044,23 @@ class TaskGather extends SttTask {
|
|||||||
message: `Custom speech vendor ${this.vendor} error: ${evt.error}`,
|
message: `Custom speech vendor ${this.vendor} error: ${evt.error}`,
|
||||||
vendor: this.vendor,
|
vendor: this.vendor,
|
||||||
}).catch((err) => this.logger.info({err}, 'Error generating alert for jambonz custom connection failure'));
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for jambonz custom connection failure'));
|
||||||
this.notifyError({msg: 'ASR error', details:`Custom speech vendor ${this.vendor} error: ${evt.error}`});
|
if (!(await this._startFallback(cs, ep, evt))) {
|
||||||
|
this.notifyTaskDone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVendorConnectFailure(cs, _ep, evt) {
|
async _onVendorConnectFailure(cs, _ep, evt) {
|
||||||
super._onVendorConnectFailure(cs, _ep, evt);
|
super._onVendorConnectFailure(cs, _ep, evt);
|
||||||
this.notifyTaskDone();
|
if (!(await this._startFallback(cs, _ep, evt))) {
|
||||||
|
this.notifyTaskDone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVendorError(cs, _ep, evt) {
|
async _onVendorError(cs, _ep, evt) {
|
||||||
super._onVendorError(cs, _ep, evt);
|
super._onVendorError(cs, _ep, evt);
|
||||||
this._resolve('stt-error', evt);
|
if (!(await this._startFallback(cs, _ep, evt))) {
|
||||||
|
this._resolve('stt-error', evt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVadDetected(cs, ep) {
|
_onVadDetected(cs, ep) {
|
||||||
@@ -847,6 +1069,10 @@ class TaskGather extends SttTask {
|
|||||||
this._killAudio(cs);
|
this._killAudio(cs);
|
||||||
this.emit('vad');
|
this.emit('vad');
|
||||||
}
|
}
|
||||||
|
if (this.vad?.strategy === 'one-shot') {
|
||||||
|
this.ep?.removeCustomEventListener(VadDetection.Detection, this._onVadDetected);
|
||||||
|
this._vadStarted = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onNoSpeechDetected(cs, ep, evt, fsEvent) {
|
_onNoSpeechDetected(cs, ep, evt, fsEvent) {
|
||||||
@@ -865,13 +1091,24 @@ class TaskGather extends SttTask {
|
|||||||
|
|
||||||
async _resolve(reason, evt) {
|
async _resolve(reason, evt) {
|
||||||
this.logger.debug(`TaskGather:resolve with reason ${reason}`);
|
this.logger.debug(`TaskGather:resolve with reason ${reason}`);
|
||||||
|
if (this.needsStt && this.ep && this.ep.connected) {
|
||||||
|
this.ep.stopTranscription({
|
||||||
|
vendor: this.vendor,
|
||||||
|
bugname: this.bugname
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
if (this.resolved) return;
|
||||||
|
this.logger.error({err}, 'Error stopping transcription');
|
||||||
|
});
|
||||||
|
}
|
||||||
if (this.resolved) return;
|
if (this.resolved) return;
|
||||||
|
|
||||||
this.resolved = true;
|
this.resolved = true;
|
||||||
// Clear dtmf event
|
// If bargin is false and ws application return ack to verb:hook
|
||||||
if (this.dtmfBargein) {
|
// the gather should not play any audio
|
||||||
this.ep.removeAllListeners('dtmf');
|
this._killAudio(this.cs);
|
||||||
}
|
// Clear dtmf events, to avoid any case can leak the listener, just clean it
|
||||||
|
this.ep.removeAllListeners('dtmf');
|
||||||
clearTimeout(this.interDigitTimer);
|
clearTimeout(this.interDigitTimer);
|
||||||
this._clearTimer();
|
this._clearTimer();
|
||||||
this._clearFastRecognitionTimer();
|
this._clearFastRecognitionTimer();
|
||||||
@@ -881,10 +1118,6 @@ class TaskGather extends SttTask {
|
|||||||
'stt.resolve': reason,
|
'stt.resolve': reason,
|
||||||
'stt.result': JSON.stringify(evt)
|
'stt.result': JSON.stringify(evt)
|
||||||
});
|
});
|
||||||
if (this.needsStt && this.ep && this.ep.connected) {
|
|
||||||
this.ep.stopTranscription({vendor: this.vendor})
|
|
||||||
.catch((err) => this.logger.error({err}, 'Error stopping transcription'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.callSession && this.callSession.callGone) {
|
if (this.callSession && this.callSession.callGone) {
|
||||||
this.logger.debug('TaskGather:_resolve - call is gone, not invoking web callback');
|
this.logger.debug('TaskGather:_resolve - call is gone, not invoking web callback');
|
||||||
@@ -892,6 +1125,25 @@ class TaskGather extends SttTask {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enabled action Hook delay timer to applied actions
|
||||||
|
if (this._hookNoResponseTimeout > 0) {
|
||||||
|
this._startActionHookNoResponseTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this._hookNoResponseGiveUpTimeout > 0) {
|
||||||
|
this._startActionHookNoResponseGiveUpTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hasFillerNoise && (reason.startsWith('dtmf') || reason.startsWith('speech'))) {
|
||||||
|
if (this.fillerNoiseStartDelaySecs > 0) {
|
||||||
|
this._startFillerNoiseTimer();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.logger.debug(`TaskGather:_resolve - playing filler noise: ${this.fillerNoiseUrl}`);
|
||||||
|
this._startFillerNoise();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (reason.startsWith('dtmf')) {
|
if (reason.startsWith('dtmf')) {
|
||||||
if (this.parentTask) this.parentTask.emit('dtmf', evt);
|
if (this.parentTask) this.parentTask.emit('dtmf', evt);
|
||||||
@@ -922,6 +1174,12 @@ class TaskGather extends SttTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) { /*already logged error*/ }
|
} catch (err) { /*already logged error*/ }
|
||||||
|
|
||||||
|
// Gather got response from hook, cancel all delay timers if there is any
|
||||||
|
this._clearActionHookNoResponseTimer();
|
||||||
|
this._clearActionHookNoResponseGiveUpTimer();
|
||||||
|
this._clearFillerNoiseTimer();
|
||||||
|
|
||||||
this.notifyTaskDone();
|
this.notifyTaskDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,10 @@ const DTMF_SPAN_NAME = 'dtmf';
|
|||||||
class TaskListen extends Task {
|
class TaskListen extends Task {
|
||||||
constructor(logger, opts, parentTask) {
|
constructor(logger, opts, parentTask) {
|
||||||
super(logger, opts);
|
super(logger, opts);
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* use bidirectionalAudio.enabled
|
||||||
|
*/
|
||||||
this.disableBidirectionalAudio = opts.disableBidirectionalAudio;
|
this.disableBidirectionalAudio = opts.disableBidirectionalAudio;
|
||||||
this.preconditions = TaskPreconditions.Endpoint;
|
this.preconditions = TaskPreconditions.Endpoint;
|
||||||
|
|
||||||
@@ -25,6 +29,15 @@ class TaskListen extends Task {
|
|||||||
this.results = {};
|
this.results = {};
|
||||||
this.playAudioQueue = [];
|
this.playAudioQueue = [];
|
||||||
this.isPlayingAudioFromQueue = false;
|
this.isPlayingAudioFromQueue = false;
|
||||||
|
this.bidirectionalAudio = {
|
||||||
|
enabled: this.disableBidirectionalAudio === true ? false : true,
|
||||||
|
...(this.data['bidirectionalAudio']),
|
||||||
|
};
|
||||||
|
|
||||||
|
// From drachtio-version 3.0.40, forkAudioStart will send empty bugname, metadata together with
|
||||||
|
// bidirectionalAudio params that cause old version of freeswitch missunderstand between bugname and
|
||||||
|
// bidirectionalAudio params
|
||||||
|
this._bugname = 'audio_fork';
|
||||||
|
|
||||||
if (this.transcribe) this.transcribeTask = makeTask(logger, {'transcribe': opts.transcribe}, this);
|
if (this.transcribe) this.transcribeTask = makeTask(logger, {'transcribe': opts.transcribe}, this);
|
||||||
}
|
}
|
||||||
@@ -123,8 +136,6 @@ class TaskListen extends Task {
|
|||||||
ci,
|
ci,
|
||||||
this.metadata);
|
this.metadata);
|
||||||
if (this.hook.auth) {
|
if (this.hook.auth) {
|
||||||
this.logger.debug({username: this.hook.auth.username, password: this.hook.auth.password},
|
|
||||||
'TaskListen:_startListening basic auth');
|
|
||||||
await this.ep.set({
|
await this.ep.set({
|
||||||
'MOD_AUDIO_BASIC_AUTH_USERNAME': this.hook.auth.username,
|
'MOD_AUDIO_BASIC_AUTH_USERNAME': this.hook.auth.username,
|
||||||
'MOD_AUDIO_BASIC_AUTH_PASSWORD': this.hook.auth.password
|
'MOD_AUDIO_BASIC_AUTH_PASSWORD': this.hook.auth.password
|
||||||
@@ -135,7 +146,8 @@ class TaskListen extends Task {
|
|||||||
mixType: this.mixType,
|
mixType: this.mixType,
|
||||||
sampling: this.sampleRate,
|
sampling: this.sampleRate,
|
||||||
...(this._bugname && {bugname: this._bugname}),
|
...(this._bugname && {bugname: this._bugname}),
|
||||||
metadata
|
metadata,
|
||||||
|
bidirectionalAudio: this.bidirectionalAudio || {}
|
||||||
});
|
});
|
||||||
this.recordStartTime = moment();
|
this.recordStartTime = moment();
|
||||||
if (this.maxLength) {
|
if (this.maxLength) {
|
||||||
@@ -155,7 +167,7 @@ class TaskListen extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* support bi-directional audio */
|
/* support bi-directional audio */
|
||||||
if (!this.disableBidirectionalAudio) {
|
if (this.bidirectionalAudio.enabled) {
|
||||||
ep.addCustomEventListener(ListenEvents.PlayAudio, this._onPlayAudio.bind(this, ep));
|
ep.addCustomEventListener(ListenEvents.PlayAudio, this._onPlayAudio.bind(this, ep));
|
||||||
}
|
}
|
||||||
ep.addCustomEventListener(ListenEvents.KillAudio, this._onKillAudio.bind(this, ep));
|
ep.addCustomEventListener(ListenEvents.KillAudio, this._onKillAudio.bind(this, ep));
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ function makeTask(logger, obj, parent) {
|
|||||||
}
|
}
|
||||||
validateVerb(name, data, logger);
|
validateVerb(name, data, logger);
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
case TaskName.Answer:
|
||||||
|
const TaskAnswer = require('./answer');
|
||||||
|
return new TaskAnswer(logger, data, parent);
|
||||||
case TaskName.SipDecline:
|
case TaskName.SipDecline:
|
||||||
const TaskSipDecline = require('./sip_decline');
|
const TaskSipDecline = require('./sip_decline');
|
||||||
return new TaskSipDecline(logger, data, parent);
|
return new TaskSipDecline(logger, data, parent);
|
||||||
@@ -41,6 +44,9 @@ function makeTask(logger, obj, parent) {
|
|||||||
case TaskName.Dtmf:
|
case TaskName.Dtmf:
|
||||||
const TaskDtmf = require('./dtmf');
|
const TaskDtmf = require('./dtmf');
|
||||||
return new TaskDtmf(logger, data, parent);
|
return new TaskDtmf(logger, data, parent);
|
||||||
|
case TaskName.Dub:
|
||||||
|
const TaskDub = require('./dub');
|
||||||
|
return new TaskDub(logger, data, parent);
|
||||||
case TaskName.Enqueue:
|
case TaskName.Enqueue:
|
||||||
const TaskEnqueue = require('./enqueue');
|
const TaskEnqueue = require('./enqueue');
|
||||||
return new TaskEnqueue(logger, data, parent);
|
return new TaskEnqueue(logger, data, parent);
|
||||||
|
|||||||
288
lib/tasks/say.js
288
lib/tasks/say.js
@@ -1,4 +1,4 @@
|
|||||||
const Task = require('./task');
|
const TtsTask = require('./tts-task');
|
||||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||||
const pollySSMLSplit = require('polly-ssml-split');
|
const pollySSMLSplit = require('polly-ssml-split');
|
||||||
|
|
||||||
@@ -23,9 +23,15 @@ const breakLengthyTextIfNeeded = (logger, text) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class TaskSay extends Task {
|
const parseTextFromSayString = (text) => {
|
||||||
|
const closingBraceIndex = text.indexOf('}');
|
||||||
|
if (closingBraceIndex === -1) return text;
|
||||||
|
return text.slice(closingBraceIndex + 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
class TaskSay extends TtsTask {
|
||||||
constructor(logger, opts, parentTask) {
|
constructor(logger, opts, parentTask) {
|
||||||
super(logger, opts);
|
super(logger, opts, parentTask);
|
||||||
this.preconditions = TaskPreconditions.Endpoint;
|
this.preconditions = TaskPreconditions.Endpoint;
|
||||||
|
|
||||||
this.text = (Array.isArray(this.data.text) ? this.data.text : [this.data.text])
|
this.text = (Array.isArray(this.data.text) ? this.data.text : [this.data.text])
|
||||||
@@ -33,10 +39,6 @@ class TaskSay extends Task {
|
|||||||
.flat();
|
.flat();
|
||||||
|
|
||||||
this.loop = this.data.loop || 1;
|
this.loop = this.data.loop || 1;
|
||||||
this.earlyMedia = this.data.earlyMedia === true || (parentTask && parentTask.earlyMedia);
|
|
||||||
this.synthesizer = this.data.synthesizer || {};
|
|
||||||
this.disableTtsCache = this.data.disableTtsCache;
|
|
||||||
this.options = this.synthesizer.options || {};
|
|
||||||
this.isHandledByPrimaryProvider = true;
|
this.isHandledByPrimaryProvider = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +61,8 @@ class TaskSay extends Task {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label}) {
|
async _synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label, preCache = false}) {
|
||||||
const {srf} = cs;
|
const {srf, accountSid:account_sid} = cs;
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, srf);
|
||||||
const {writeAlerts, AlertType, stats} = srf.locals;
|
const {writeAlerts, AlertType, stats} = srf.locals;
|
||||||
const {synthAudio} = srf.locals.dbHelpers;
|
const {synthAudio} = srf.locals.dbHelpers;
|
||||||
@@ -76,6 +78,8 @@ class TaskSay extends Task {
|
|||||||
voice = arr[1];
|
voice = arr[1];
|
||||||
model = arr[2];
|
model = arr[2];
|
||||||
}
|
}
|
||||||
|
} else if (vendor === 'deepgram') {
|
||||||
|
model = voice;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allow for microsoft custom region voice and api_key to be specified as an override */
|
/* allow for microsoft custom region voice and api_key to be specified as an override */
|
||||||
@@ -86,20 +90,32 @@ class TaskSay extends Task {
|
|||||||
credentials.api_key = this.options.apiKey || credentials.apiKey;
|
credentials.api_key = this.options.apiKey || credentials.apiKey;
|
||||||
credentials.region = this.options.region || credentials.region;
|
credentials.region = this.options.region || credentials.region;
|
||||||
voice = this.options.voice || voice;
|
voice = this.options.voice || voice;
|
||||||
|
} else if (vendor === 'elevenlabs') {
|
||||||
|
credentials = credentials || {};
|
||||||
|
credentials.model_id = this.options.model_id || credentials.model_id;
|
||||||
|
credentials.voice_settings = this.options.voice_settings || {};
|
||||||
|
credentials.optimize_streaming_latency = this.options.optimize_streaming_latency
|
||||||
|
|| credentials.optimize_streaming_latency;
|
||||||
|
voice = this.options.voice_id || voice;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.logger.info({vendor, language, voice, model}, 'TaskSay:exec');
|
ep.set({
|
||||||
|
tts_engine: vendor.startsWith('custom:') ? 'custom' : vendor,
|
||||||
|
tts_voice: voice,
|
||||||
|
cache_speech_handles: !cs.currentTtsVendor || cs.currentTtsVendor === vendor ? 1 : 0,
|
||||||
|
}).catch((err) => this.logger.info({err}, 'Error setting tts_engine on endpoint'));
|
||||||
|
// set the current vendor on the call session
|
||||||
|
// If vendor is changed from the previous one, then reset the cache_speech_handles flag
|
||||||
|
cs.currentTtsVendor = vendor;
|
||||||
|
|
||||||
|
if (!preCache) this.logger.info({vendor, language, voice, model}, 'TaskSay:exec');
|
||||||
try {
|
try {
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
writeAlerts({
|
writeAlerts({
|
||||||
account_sid: cs.accountSid,
|
account_sid,
|
||||||
alert_type: AlertType.TTS_NOT_PROVISIONED,
|
alert_type: AlertType.TTS_NOT_PROVISIONED,
|
||||||
vendor
|
vendor
|
||||||
}).catch((err) => this.logger.info({err}, 'Error generating alert for no tts'));
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for no tts'));
|
||||||
this.notifyError({
|
|
||||||
msg: 'TTS error',
|
|
||||||
details:`No speech credentials provisioned for selected vendor ${vendor}`
|
|
||||||
});
|
|
||||||
throw new Error('no provisioned speech credentials for TTS');
|
throw new Error('no provisioned speech credentials for TTS');
|
||||||
}
|
}
|
||||||
// synthesize all of the text elements
|
// synthesize all of the text elements
|
||||||
@@ -111,14 +127,17 @@ class TaskSay extends Task {
|
|||||||
if (text.startsWith('silence_stream://')) return text;
|
if (text.startsWith('silence_stream://')) return text;
|
||||||
|
|
||||||
/* otel: trace time for tts */
|
/* otel: trace time for tts */
|
||||||
const {span} = this.startChildSpan('tts-generation', {
|
if (!preCache) {
|
||||||
'tts.vendor': vendor,
|
const {span} = this.startChildSpan('tts-generation', {
|
||||||
'tts.language': language,
|
'tts.vendor': vendor,
|
||||||
'tts.voice': voice
|
'tts.language': language,
|
||||||
});
|
'tts.voice': voice
|
||||||
|
});
|
||||||
|
this.otelSpan = span;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const {filePath, servedFromCache, rtt} = await synthAudio(stats, {
|
const {filePath, servedFromCache, rtt} = await synthAudio(stats, {
|
||||||
account_sid: cs.accountSid,
|
account_sid,
|
||||||
text,
|
text,
|
||||||
vendor,
|
vendor,
|
||||||
language,
|
language,
|
||||||
@@ -127,37 +146,47 @@ class TaskSay extends Task {
|
|||||||
model,
|
model,
|
||||||
salt,
|
salt,
|
||||||
credentials,
|
credentials,
|
||||||
disableTtsCache : this.disableTtsCache
|
options: this.options,
|
||||||
|
disableTtsCache : this.disableTtsCache,
|
||||||
|
preCache
|
||||||
});
|
});
|
||||||
this.logger.debug(`file ${filePath}, served from cache ${servedFromCache}`);
|
if (!filePath.startsWith('say:')) {
|
||||||
if (filePath) cs.trackTmpFile(filePath);
|
this.logger.debug(`file ${filePath}, served from cache ${servedFromCache}`);
|
||||||
if (!servedFromCache && !lastUpdated) {
|
if (filePath) cs.trackTmpFile(filePath);
|
||||||
lastUpdated = true;
|
if (this.otelSpan) {
|
||||||
updateSpeechCredentialLastUsed(credentials.speech_credential_sid)
|
this.otelSpan.setAttributes({'tts.cached': servedFromCache});
|
||||||
.catch(() => {/*already logged error */});
|
this.otelSpan.end();
|
||||||
|
this.otelSpan = null;
|
||||||
|
}
|
||||||
|
if (!servedFromCache && !lastUpdated) {
|
||||||
|
lastUpdated = true;
|
||||||
|
updateSpeechCredentialLastUsed(credentials.speech_credential_sid).catch(() => {/* logged error */});
|
||||||
|
}
|
||||||
|
if (!servedFromCache && rtt && !preCache) {
|
||||||
|
this.notifyStatus({
|
||||||
|
event: 'synthesized-audio',
|
||||||
|
vendor,
|
||||||
|
language,
|
||||||
|
characters: text.length,
|
||||||
|
elapsedTime: rtt
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
span.setAttributes({'tts.cached': servedFromCache});
|
else {
|
||||||
span.end();
|
this.logger.debug('a streaming tts api will be used');
|
||||||
if (!servedFromCache && rtt) {
|
const modifiedPath = filePath.replace('say:{', `say:{session-uuid=${ep.uuid},`);
|
||||||
this.notifyStatus({
|
return modifiedPath;
|
||||||
event: 'synthesized-audio',
|
|
||||||
vendor,
|
|
||||||
language,
|
|
||||||
characters: text.length,
|
|
||||||
elapsedTime: rtt
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return filePath;
|
return filePath;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info({err}, 'Error synthesizing tts');
|
this.logger.info({err}, 'Error synthesizing tts');
|
||||||
span.end();
|
if (this.otelSpan) this.otelSpan.end();
|
||||||
writeAlerts({
|
writeAlerts({
|
||||||
account_sid: cs.accountSid,
|
account_sid: cs.accountSid,
|
||||||
alert_type: AlertType.TTS_FAILURE,
|
alert_type: AlertType.TTS_FAILURE,
|
||||||
vendor,
|
vendor,
|
||||||
detail: err.message
|
detail: err.message
|
||||||
}).catch((err) => this.logger.info({err}, 'Error generating alert for tts failure'));
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for tts failure'));
|
||||||
this.notifyError({msg: 'TTS error', details: err.message || err});
|
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -172,19 +201,24 @@ class TaskSay extends Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async exec(cs, {ep}) {
|
async exec(cs, {ep}) {
|
||||||
|
const {srf, accountSid:account_sid} = cs;
|
||||||
|
const {writeAlerts, AlertType} = srf.locals;
|
||||||
|
const {addFileToCache} = srf.locals.dbHelpers;
|
||||||
|
const engine = this.synthesizer.engine || 'standard';
|
||||||
|
|
||||||
await super.exec(cs);
|
await super.exec(cs);
|
||||||
this.ep = ep;
|
this.ep = ep;
|
||||||
|
|
||||||
const vendor = this.synthesizer.vendor && this.synthesizer.vendor !== 'default' ?
|
let vendor = this.synthesizer.vendor && this.synthesizer.vendor !== 'default' ?
|
||||||
this.synthesizer.vendor :
|
this.synthesizer.vendor :
|
||||||
cs.speechSynthesisVendor;
|
cs.speechSynthesisVendor;
|
||||||
const language = this.synthesizer.language && this.synthesizer.language !== 'default' ?
|
let language = this.synthesizer.language && this.synthesizer.language !== 'default' ?
|
||||||
this.synthesizer.language :
|
this.synthesizer.language :
|
||||||
cs.speechSynthesisLanguage ;
|
cs.speechSynthesisLanguage ;
|
||||||
const voice = this.synthesizer.voice && this.synthesizer.voice !== 'default' ?
|
let voice = this.synthesizer.voice && this.synthesizer.voice !== 'default' ?
|
||||||
this.synthesizer.voice :
|
this.synthesizer.voice :
|
||||||
cs.speechSynthesisVoice;
|
cs.speechSynthesisVoice;
|
||||||
const label = this.synthesizer.label && this.synthesizer.label !== 'default' ?
|
let label = this.synthesizer.label && this.synthesizer.label !== 'default' ?
|
||||||
this.synthesizer.label :
|
this.synthesizer.label :
|
||||||
cs.speechSynthesisLabel;
|
cs.speechSynthesisLabel;
|
||||||
|
|
||||||
@@ -201,12 +235,19 @@ class TaskSay extends Task {
|
|||||||
this.synthesizer.fallbackLabel :
|
this.synthesizer.fallbackLabel :
|
||||||
cs.fallbackSpeechSynthesisLabel;
|
cs.fallbackSpeechSynthesisLabel;
|
||||||
|
|
||||||
let filepath;
|
if (cs.hasFallbackTts) {
|
||||||
try {
|
vendor = fallbackVendor;
|
||||||
filepath = await this._synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label});
|
language = fallbackLanguage;
|
||||||
} catch (error) {
|
voice = fallbackVoice;
|
||||||
if (fallbackVendor && this.isHandledByPrimaryProvider) {
|
label = fallbackLabel;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startFallback = async(error) => {
|
||||||
|
if (fallbackVendor && this.isHandledByPrimaryProvider && !cs.hasFallbackTts) {
|
||||||
|
this.notifyError(
|
||||||
|
{ msg: 'TTS error', details:`TTS vendor ${vendor} error: ${error}`, failover: 'in progress'});
|
||||||
this.isHandledByPrimaryProvider = false;
|
this.isHandledByPrimaryProvider = false;
|
||||||
|
cs.hasFallbackTts = true;
|
||||||
this.logger.info(`Synthesize error, fallback to ${fallbackVendor}`);
|
this.logger.info(`Synthesize error, fallback to ${fallbackVendor}`);
|
||||||
filepath = await this._synthesizeWithSpecificVendor(cs, ep,
|
filepath = await this._synthesizeWithSpecificVendor(cs, ep,
|
||||||
{
|
{
|
||||||
@@ -216,22 +257,94 @@ class TaskSay extends Task {
|
|||||||
label: fallbackLabel
|
label: fallbackLabel
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
this.notifyError(
|
||||||
|
{ msg: 'TTS error', details:`TTS vendor ${vendor} error: ${error}`, failover: 'not available'});
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
let filepath;
|
||||||
|
try {
|
||||||
|
filepath = await this._synthesizeWithSpecificVendor(cs, ep, {vendor, language, voice, label});
|
||||||
|
} catch (error) {
|
||||||
|
await startFallback(error);
|
||||||
}
|
}
|
||||||
this.notifyStatus({event: 'start-playback'});
|
this.notifyStatus({event: 'start-playback'});
|
||||||
|
|
||||||
while (!this.killed && (this.loop === 'forever' || this.loop--) && this.ep?.connected) {
|
while (!this.killed && (this.loop === 'forever' || this.loop--) && ep?.connected) {
|
||||||
let segment = 0;
|
let segment = 0;
|
||||||
while (!this.killed && segment < filepath.length) {
|
while (!this.killed && segment < filepath.length) {
|
||||||
if (cs.isInConference) {
|
if (cs.isInConference) {
|
||||||
const {memberId, confName, confUuid} = cs;
|
const {memberId, confName, confUuid} = cs;
|
||||||
await this.playToConfMember(this.ep, memberId, confName, confUuid, filepath[segment]);
|
await this.playToConfMember(ep, memberId, confName, confUuid, filepath[segment]);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.debug(`Say:exec sending command to play file ${filepath[segment]}`);
|
if (filepath[segment].startsWith('say:{')) {
|
||||||
|
const arr = /^say:\{.*\}\s*(.*)$/.exec(filepath[segment]);
|
||||||
|
if (arr) this.logger.debug(`Say:exec sending streaming tts request: ${arr[1].substring(0, 64)}..`);
|
||||||
|
}
|
||||||
|
else this.logger.debug(`Say:exec sending ${filepath[segment].substring(0, 64)}`);
|
||||||
|
ep.once('playback-start', (evt) => {
|
||||||
|
this.logger.debug({evt}, 'got playback-start');
|
||||||
|
if (this.otelSpan) {
|
||||||
|
this._addStreamingTtsAttributes(this.otelSpan, evt);
|
||||||
|
this.otelSpan.end();
|
||||||
|
this.otelSpan = null;
|
||||||
|
if (evt.variable_tts_cache_filename) cs.trackTmpFile(evt.variable_tts_cache_filename);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
ep.once('playback-stop', (evt) => {
|
||||||
|
this.logger.debug({evt}, 'got playback-stop');
|
||||||
|
if (evt.variable_tts_error) {
|
||||||
|
writeAlerts({
|
||||||
|
account_sid,
|
||||||
|
alert_type: AlertType.TTS_FAILURE,
|
||||||
|
vendor,
|
||||||
|
detail: evt.variable_tts_error
|
||||||
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for no tts'));
|
||||||
|
}
|
||||||
|
if (evt.variable_tts_cache_filename) {
|
||||||
|
const text = parseTextFromSayString(this.text[segment]);
|
||||||
|
addFileToCache(evt.variable_tts_cache_filename, {
|
||||||
|
account_sid,
|
||||||
|
vendor,
|
||||||
|
language,
|
||||||
|
voice,
|
||||||
|
engine,
|
||||||
|
text
|
||||||
|
}).catch((err) => this.logger.info({err}, 'Error adding file to cache'));
|
||||||
|
}
|
||||||
|
if (this._playResolve) {
|
||||||
|
evt.variable_tts_error ? this._playReject(new Error(evt.variable_tts_error)) : this._playResolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// wait for playback-stop event received to confirm if the playback is successful
|
||||||
|
this._playPromise = new Promise((resolve, reject) => {
|
||||||
|
this._playResolve = resolve;
|
||||||
|
this._playReject = reject;
|
||||||
|
});
|
||||||
await ep.play(filepath[segment]);
|
await ep.play(filepath[segment]);
|
||||||
this.logger.debug(`Say:exec completed play file ${filepath[segment]}`);
|
try {
|
||||||
|
// wait for playback-stop event received to confirm if the playback is successful
|
||||||
|
await this._playPromise;
|
||||||
|
} catch (err) {
|
||||||
|
try {
|
||||||
|
await startFallback(err);
|
||||||
|
continue;
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info({err}, 'Error waiting for playback-stop event');
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
this._playPromise = null;
|
||||||
|
this._playResolve = null;
|
||||||
|
this._playReject = null;
|
||||||
|
}
|
||||||
|
if (filepath[segment].startsWith('say:{')) {
|
||||||
|
const arr = /^say:\{.*\}\s*(.*)$/.exec(filepath[segment]);
|
||||||
|
if (arr) this.logger.debug(`Say:exec complete playing streaming tts request: ${arr[1].substring(0, 64)}..`);
|
||||||
|
} else {
|
||||||
|
// This log will print spech credentials in say command for tts stream mode
|
||||||
|
this.logger.debug(`Say:exec completed play file ${filepath[segment]}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
segment++;
|
segment++;
|
||||||
}
|
}
|
||||||
@@ -241,7 +354,7 @@ class TaskSay extends Task {
|
|||||||
|
|
||||||
async kill(cs) {
|
async kill(cs) {
|
||||||
super.kill(cs);
|
super.kill(cs);
|
||||||
if (this.ep.connected) {
|
if (this.ep?.connected) {
|
||||||
this.logger.debug('TaskSay:kill - killing audio');
|
this.logger.debug('TaskSay:kill - killing audio');
|
||||||
if (cs.isInConference) {
|
if (cs.isInConference) {
|
||||||
const {memberId, confName} = cs;
|
const {memberId, confName} = cs;
|
||||||
@@ -251,8 +364,75 @@ class TaskSay extends Task {
|
|||||||
this.notifyStatus({event: 'kill-playback'});
|
this.notifyStatus({event: 'kill-playback'});
|
||||||
this.ep.api('uuid_break', this.ep.uuid);
|
this.ep.api('uuid_break', this.ep.uuid);
|
||||||
}
|
}
|
||||||
|
this.ep.removeAllListeners('playback-start');
|
||||||
|
this.ep.removeAllListeners('playback-stop');
|
||||||
|
// if we are waiting for playback-stop event, resolve the promise
|
||||||
|
if (this._playResolve) this._playResolve();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_addStreamingTtsAttributes(span, evt) {
|
||||||
|
const attrs = {'tts.cached': false};
|
||||||
|
for (const [key, value] of Object.entries(evt)) {
|
||||||
|
if (key.startsWith('variable_tts_')) {
|
||||||
|
let newKey = key.substring('variable_tts_'.length)
|
||||||
|
.replace('whisper_', 'whisper.')
|
||||||
|
.replace('deepgram_', 'deepgram.')
|
||||||
|
.replace('playht_', 'playht.')
|
||||||
|
.replace('rimelabs_', 'rimelabs.')
|
||||||
|
.replace('verbio_', 'verbio.')
|
||||||
|
.replace('elevenlabs_', 'elevenlabs.');
|
||||||
|
if (spanMapping[newKey]) newKey = spanMapping[newKey];
|
||||||
|
attrs[newKey] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete attrs['cache_filename']; //no value in adding this to the span
|
||||||
|
span.setAttributes(attrs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const spanMapping = {
|
||||||
|
// IMPORTANT!!! JAMBONZ WEBAPP WILL SHOW TEXT PERFECTLY IF THE SPAN NAME IS SMALLER OR EQUAL 25 CHARACTERS.
|
||||||
|
// EX: whisper.ratelim_reqs has length 20 <= 25 which is perfect
|
||||||
|
// Elevenlabs
|
||||||
|
'elevenlabs.reported_latency_ms': 'elevenlabs.latency_ms',
|
||||||
|
'elevenlabs.request_id': 'elevenlabs.req_id',
|
||||||
|
'elevenlabs.history_item_id': 'elevenlabs.item_id',
|
||||||
|
'elevenlabs.optimize_streaming_latency': 'elevenlabs.optimization',
|
||||||
|
'elevenlabs.name_lookup_time_ms': 'name_lookup_ms',
|
||||||
|
'elevenlabs.connect_time_ms': 'connect_ms',
|
||||||
|
'elevenlabs.final_response_time_ms': 'final_response_ms',
|
||||||
|
// Whisper
|
||||||
|
'whisper.reported_latency_ms': 'whisper.latency_ms',
|
||||||
|
'whisper.request_id': 'whisper.req_id',
|
||||||
|
'whisper.reported_organization': 'whisper.organization',
|
||||||
|
'whisper.reported_ratelimit_requests': 'whisper.ratelimit',
|
||||||
|
'whisper.reported_ratelimit_remaining_requests': 'whisper.ratelimit_remain',
|
||||||
|
'whisper.reported_ratelimit_reset_requests': 'whisper.ratelimit_reset',
|
||||||
|
'whisper.name_lookup_time_ms': 'name_lookup_ms',
|
||||||
|
'whisper.connect_time_ms': 'connect_ms',
|
||||||
|
'whisper.final_response_time_ms': 'final_response_ms',
|
||||||
|
// Deepgram
|
||||||
|
'deepgram.request_id': 'deepgram.req_id',
|
||||||
|
'deepgram.reported_model_name': 'deepgram.model_name',
|
||||||
|
'deepgram.reported_model_uuid': 'deepgram.model_uuid',
|
||||||
|
'deepgram.reported_char_count': 'deepgram.char_count',
|
||||||
|
'deepgram.name_lookup_time_ms': 'name_lookup_ms',
|
||||||
|
'deepgram.connect_time_ms': 'connect_ms',
|
||||||
|
'deepgram.final_response_time_ms': 'final_response_ms',
|
||||||
|
// Playht
|
||||||
|
'playht.request_id': 'playht.req_id',
|
||||||
|
'playht.name_lookup_time_ms': 'name_lookup_ms',
|
||||||
|
'playht.connect_time_ms': 'connect_ms',
|
||||||
|
'playht.final_response_time_ms': 'final_response_ms',
|
||||||
|
// Rimelabs
|
||||||
|
'rimelabs.name_lookup_time_ms': 'name_lookup_ms',
|
||||||
|
'rimelabs.connect_time_ms': 'connect_ms',
|
||||||
|
'rimelabs.final_response_time_ms': 'final_response_ms',
|
||||||
|
// verbio
|
||||||
|
'verbio.name_lookup_time_ms': 'name_lookup_ms',
|
||||||
|
'verbio.connect_time_ms': 'connect_ms',
|
||||||
|
'verbio.final_response_time_ms': 'final_response_ms',
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = TaskSay;
|
module.exports = TaskSay;
|
||||||
|
|||||||
@@ -14,17 +14,15 @@ class SttTask extends Task {
|
|||||||
const {
|
const {
|
||||||
setChannelVarsForStt,
|
setChannelVarsForStt,
|
||||||
normalizeTranscription,
|
normalizeTranscription,
|
||||||
removeSpeechListeners,
|
|
||||||
setSpeechCredentialsAtRuntime,
|
setSpeechCredentialsAtRuntime,
|
||||||
compileSonioxTranscripts,
|
compileSonioxTranscripts,
|
||||||
consolidateTranscripts
|
consolidateTranscripts
|
||||||
} = require('../utils/transcription-utils')(logger);
|
} = require('../utils/transcription-utils')(logger);
|
||||||
this.setChannelVarsForStt = setChannelVarsForStt;
|
this.setChannelVarsForStt = setChannelVarsForStt;
|
||||||
this.normalizeTranscription = normalizeTranscription;
|
this.normalizeTranscription = normalizeTranscription;
|
||||||
this.removeSpeechListeners = removeSpeechListeners;
|
|
||||||
this.compileSonioxTranscripts = compileSonioxTranscripts;
|
this.compileSonioxTranscripts = compileSonioxTranscripts;
|
||||||
this.consolidateTranscripts = consolidateTranscripts;
|
this.consolidateTranscripts = consolidateTranscripts;
|
||||||
|
this.eventHandlers = [];
|
||||||
this.isHandledByPrimaryProvider = true;
|
this.isHandledByPrimaryProvider = true;
|
||||||
if (this.data.recognizer) {
|
if (this.data.recognizer) {
|
||||||
const recognizer = this.data.recognizer;
|
const recognizer = this.data.recognizer;
|
||||||
@@ -49,11 +47,126 @@ class SttTask extends Task {
|
|||||||
|
|
||||||
/* buffer for soniox transcripts */
|
/* buffer for soniox transcripts */
|
||||||
this._sonioxTranscripts = [];
|
this._sonioxTranscripts = [];
|
||||||
|
/*bug name prefix */
|
||||||
|
this.bugname_prefix = '';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async exec(cs, {ep, ep2}) {
|
||||||
|
super.exec(cs);
|
||||||
|
this.ep = ep;
|
||||||
|
this.ep2 = ep2;
|
||||||
|
|
||||||
|
// use session preferences if we don't have specific verb-level settings.
|
||||||
|
if (cs.recognizer) {
|
||||||
|
for (const k in cs.recognizer) {
|
||||||
|
const newValue = this.data.recognizer && this.data.recognizer[k] !== undefined ?
|
||||||
|
this.data.recognizer[k] :
|
||||||
|
cs.recognizer[k];
|
||||||
|
|
||||||
|
if (Array.isArray(newValue)) {
|
||||||
|
this.data.recognizer[k] = [...(this.data.recognizer[k] || []), ...cs.recognizer[k]];
|
||||||
|
} else if (typeof newValue === 'object' && newValue !== null) {
|
||||||
|
this.data.recognizer[k] = { ...(this.data.recognizer[k] || {}), ...cs.recognizer[k] };
|
||||||
|
} else {
|
||||||
|
this.data.recognizer[k] = newValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ('default' === this.vendor || !this.vendor) {
|
||||||
|
this.vendor = cs.speechRecognizerVendor;
|
||||||
|
if (this.data.recognizer) this.data.recognizer.vendor = this.vendor;
|
||||||
|
}
|
||||||
|
if ('default' === this.language || !this.language) {
|
||||||
|
this.language = cs.speechRecognizerLanguage;
|
||||||
|
if (this.data.recognizer) this.data.recognizer.language = this.language;
|
||||||
|
}
|
||||||
|
if ('default' === this.label || !this.label) {
|
||||||
|
this.label = cs.speechRecognizerLabel;
|
||||||
|
if (this.data.recognizer) this.data.recognizer.label = this.label;
|
||||||
|
}
|
||||||
|
// Fallback options
|
||||||
|
if ('default' === this.fallbackVendor || !this.fallbackVendor) {
|
||||||
|
this.fallbackVendor = cs.fallbackSpeechRecognizerVendor;
|
||||||
|
if (this.data.recognizer) this.data.recognizer.fallbackVendor = this.fallbackVendor;
|
||||||
|
}
|
||||||
|
if ('default' === this.fallbackLanguage || !this.fallbackLanguage) {
|
||||||
|
this.fallbackLanguage = cs.fallbackSpeechRecognizerLanguage;
|
||||||
|
if (this.data.recognizer) this.data.recognizer.fallbackLanguage = this.fallbackLanguage;
|
||||||
|
}
|
||||||
|
if ('default' === this.fallbackLabel || !this.fallbackLabel) {
|
||||||
|
this.fallbackLabel = cs.fallbackSpeechRecognizerLabel;
|
||||||
|
if (this.data.recognizer) this.data.recognizer.fallbackLabel = this.fallbackLabel;
|
||||||
|
}
|
||||||
|
// If call is already fallback to 2nd ASR vendor
|
||||||
|
// use that.
|
||||||
|
if (cs.hasFallbackAsr) {
|
||||||
|
this.vendor = this.fallbackVendor;
|
||||||
|
this.language = this.fallbackLanguage;
|
||||||
|
this.label = this.fallbackLabel;
|
||||||
|
}
|
||||||
|
if (!this.data.recognizer.vendor) {
|
||||||
|
this.data.recognizer.vendor = this.vendor;
|
||||||
|
}
|
||||||
|
if (this.vendor === 'cobalt' && !this.data.recognizer.model) {
|
||||||
|
// By default, application saves cobalt model in language
|
||||||
|
this.data.recognizer.model = cs.speechRecognizerLanguage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
// not gather task, such as transcribe
|
||||||
|
(!this.input ||
|
||||||
|
// gather task with speech
|
||||||
|
this.input.includes('speech')) &&
|
||||||
|
!this.sttCredentials) {
|
||||||
|
try {
|
||||||
|
this.sttCredentials = await this._initSpeechCredentials(this.cs, this.vendor, this.label);
|
||||||
|
} catch (error) {
|
||||||
|
if (this.canFallback) {
|
||||||
|
this.notifyError(
|
||||||
|
{
|
||||||
|
msg: 'ASR error', details:`Invalid vendor ${this.vendor}, Error: ${error}`,
|
||||||
|
failover: 'in progress'
|
||||||
|
});
|
||||||
|
await this._initFallback();
|
||||||
|
} else {
|
||||||
|
this.notifyError(
|
||||||
|
{
|
||||||
|
msg: 'ASR error', details:`Invalid vendor ${this.vendor}, Error: ${error}`,
|
||||||
|
failover: 'not available'
|
||||||
|
});
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* when using cobalt model is required */
|
||||||
|
if (this.vendor === 'cobalt' && !this.data.recognizer.model) {
|
||||||
|
this.notifyError({ msg: 'ASR error', details:'Cobalt requires a model to be specified'});
|
||||||
|
throw new Error('Cobalt requires a model to be specified');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cs.hasAltLanguages) {
|
||||||
|
this.data.recognizer.altLanguages = this.data.recognizer.altLanguages.concat(cs.altLanguages);
|
||||||
|
this.logger.debug({altLanguages: this.altLanguages},
|
||||||
|
'STT:exec - applying altLanguages');
|
||||||
|
}
|
||||||
|
if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) {
|
||||||
|
this.data.recognizer.punctuation = cs.globalSttPunctuation;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
addCustomEventListener(ep, event, handler) {
|
||||||
|
this.eventHandlers.push({ep, event, handler});
|
||||||
|
ep.addCustomEventListener(event, handler);
|
||||||
|
}
|
||||||
|
|
||||||
|
removeCustomEventListeners() {
|
||||||
|
this.eventHandlers.forEach((h) => h.ep.removeCustomEventListener(h.event, h.handler));
|
||||||
|
}
|
||||||
|
|
||||||
async _initSpeechCredentials(cs, vendor, label) {
|
async _initSpeechCredentials(cs, vendor, label) {
|
||||||
const {getNuanceAccessToken, getIbmAccessToken} = this.cs.srf.locals.dbHelpers;
|
const {getNuanceAccessToken, getIbmAccessToken, getAwsAuthToken, getVerbioAccessToken} = cs.srf.locals.dbHelpers;
|
||||||
let credentials = cs.getSpeechCredentials(vendor, 'stt', label);
|
let credentials = cs.getSpeechCredentials(vendor, 'stt', label);
|
||||||
|
|
||||||
if (!credentials) {
|
if (!credentials) {
|
||||||
@@ -64,11 +177,6 @@ class SttTask extends Task {
|
|||||||
alert_type: AlertType.STT_NOT_PROVISIONED,
|
alert_type: AlertType.STT_NOT_PROVISIONED,
|
||||||
vendor
|
vendor
|
||||||
}).catch((err) => this.logger.info({err}, 'Error generating alert for no stt'));
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for no stt'));
|
||||||
// Notify application that STT vender is wrong.
|
|
||||||
this.notifyError({
|
|
||||||
msg: 'ASR error',
|
|
||||||
details: `No speech-to-text service credentials for ${vendor} have been configured`
|
|
||||||
});
|
|
||||||
this.notifyTaskDone();
|
this.notifyTaskDone();
|
||||||
throw new Error(`No speech-to-text service credentials for ${vendor} have been configured`);
|
throw new Error(`No speech-to-text service credentials for ${vendor} have been configured`);
|
||||||
}
|
}
|
||||||
@@ -86,13 +194,29 @@ class SttTask extends Task {
|
|||||||
const {access_token, servedFromCache} = await getIbmAccessToken(stt_api_key);
|
const {access_token, servedFromCache} = await getIbmAccessToken(stt_api_key);
|
||||||
this.logger.debug({stt_api_key}, `got ibm access token ${servedFromCache ? 'from cache' : ''}`);
|
this.logger.debug({stt_api_key}, `got ibm access token ${servedFromCache ? 'from cache' : ''}`);
|
||||||
credentials = {...credentials, access_token, stt_region};
|
credentials = {...credentials, access_token, stt_region};
|
||||||
|
} else if (['aws', 'polly'].includes(vendor) && credentials.roleArn) {
|
||||||
|
/* get aws access token */
|
||||||
|
const {roleArn} = credentials;
|
||||||
|
const {accessKeyId, secretAccessKey, sessionToken, servedFromCache} = await getAwsAuthToken(roleArn);
|
||||||
|
this.logger.debug({roleArn}, `got aws access token ${servedFromCache ? 'from cache' : ''}`);
|
||||||
|
credentials = {...credentials, accessKeyId, secretAccessKey, sessionToken};
|
||||||
|
} else if (vendor === 'verbio' && credentials.client_id && credentials.client_secret) {
|
||||||
|
const {access_token, servedFromCache} = await getVerbioAccessToken(credentials);
|
||||||
|
this.logger.debug({client_id: credentials.client_id},
|
||||||
|
`got verbio access token ${servedFromCache ? 'from cache' : ''}`);
|
||||||
|
credentials.access_token = access_token;
|
||||||
}
|
}
|
||||||
return credentials;
|
return credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
async _fallback() {
|
get canFallback() {
|
||||||
|
return this.fallbackVendor && this.isHandledByPrimaryProvider && !this.cs.hasFallbackAsr;
|
||||||
|
}
|
||||||
|
|
||||||
|
async _initFallback() {
|
||||||
assert(this.fallbackVendor, 'fallback failed without fallbackVendor configuration');
|
assert(this.fallbackVendor, 'fallback failed without fallbackVendor configuration');
|
||||||
this.isHandledByPrimaryProvider = false;
|
this.isHandledByPrimaryProvider = false;
|
||||||
|
this.cs.hasFallbackAsr = true;
|
||||||
this.logger.info(`Failed to use primary STT provider, fallback to ${this.fallbackVendor}`);
|
this.logger.info(`Failed to use primary STT provider, fallback to ${this.fallbackVendor}`);
|
||||||
this.vendor = this.fallbackVendor;
|
this.vendor = this.fallbackVendor;
|
||||||
this.language = this.fallbackLanguage;
|
this.language = this.fallbackLanguage;
|
||||||
@@ -101,6 +225,8 @@ class SttTask extends Task {
|
|||||||
this.data.recognizer.language = this.language;
|
this.data.recognizer.language = this.language;
|
||||||
this.data.recognizer.label = this.label;
|
this.data.recognizer.label = this.label;
|
||||||
this.sttCredentials = await this._initSpeechCredentials(this.cs, this.vendor, this.label);
|
this.sttCredentials = await this._initSpeechCredentials(this.cs, this.vendor, this.label);
|
||||||
|
// cleanup previous listener from previous vendor
|
||||||
|
this.removeCustomEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
async compileHintsForCobalt(ep, hostport, model, token, hints) {
|
async compileHintsForCobalt(ep, hostport, model, token, hints) {
|
||||||
@@ -144,6 +270,20 @@ class SttTask extends Task {
|
|||||||
_doContinuousAsrWithDeepgram(asrTimeout) {
|
_doContinuousAsrWithDeepgram(asrTimeout) {
|
||||||
/* deepgram has an utterance_end_ms property that simplifies things */
|
/* deepgram has an utterance_end_ms property that simplifies things */
|
||||||
assert(this.vendor === 'deepgram');
|
assert(this.vendor === 'deepgram');
|
||||||
|
if (asrTimeout < 1000) {
|
||||||
|
this.notifyError({
|
||||||
|
msg: 'ASR error',
|
||||||
|
details:`asrTimeout ${asrTimeout} is too short for deepgram; setting it to 1000ms`
|
||||||
|
});
|
||||||
|
asrTimeout = 1000;
|
||||||
|
}
|
||||||
|
else if (asrTimeout > 5000) {
|
||||||
|
this.notifyError({
|
||||||
|
msg: 'ASR error',
|
||||||
|
details:`asrTimeout ${asrTimeout} is too long for deepgram; setting it to 5000ms`
|
||||||
|
});
|
||||||
|
asrTimeout = 5000;
|
||||||
|
}
|
||||||
this.logger.debug(`_doContinuousAsrWithDeepgram - setting utterance_end_ms to ${asrTimeout}`);
|
this.logger.debug(`_doContinuousAsrWithDeepgram - setting utterance_end_ms to ${asrTimeout}`);
|
||||||
const dgOptions = this.data.recognizer.deepgramOptions = this.data.recognizer.deepgramOptions || {};
|
const dgOptions = this.data.recognizer.deepgramOptions = this.data.recognizer.deepgramOptions || {};
|
||||||
dgOptions.utteranceEndMs = dgOptions.utteranceEndMs || asrTimeout;
|
dgOptions.utteranceEndMs = dgOptions.utteranceEndMs || asrTimeout;
|
||||||
@@ -163,7 +303,6 @@ class SttTask extends Task {
|
|||||||
detail: evt.error,
|
detail: evt.error,
|
||||||
vendor: this.vendor,
|
vendor: this.vendor,
|
||||||
}).catch((err) => this.logger.info({err}, `Error generating alert for ${this.vendor} connection failure`));
|
}).catch((err) => this.logger.info({err}, `Error generating alert for ${this.vendor} connection failure`));
|
||||||
this.notifyError({msg: 'ASR error', details:`Failed connecting to speech vendor ${this.vendor}: ${evt.error}`});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVendorConnectFailure(cs, _ep, evt) {
|
_onVendorConnectFailure(cs, _ep, evt) {
|
||||||
@@ -176,7 +315,6 @@ class SttTask extends Task {
|
|||||||
message: `Failed connecting to ${this.vendor} speech recognizer: ${reason}`,
|
message: `Failed connecting to ${this.vendor} speech recognizer: ${reason}`,
|
||||||
vendor: this.vendor,
|
vendor: this.vendor,
|
||||||
}).catch((err) => this.logger.info({err}, `Error generating alert for ${this.vendor} connection failure`));
|
}).catch((err) => this.logger.info({err}, `Error generating alert for ${this.vendor} connection failure`));
|
||||||
this.notifyError({msg: 'ASR error', details:`Failed connecting to speech vendor ${this.vendor}: ${reason}`});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ class TaskTag extends Task {
|
|||||||
async exec(cs) {
|
async exec(cs) {
|
||||||
super.exec(cs);
|
super.exec(cs);
|
||||||
cs.callInfo.customerData = this.data;
|
cs.callInfo.customerData = this.data;
|
||||||
//this.logger.debug({callInfo: cs.callInfo.toJSON()}, 'TaskTag:exec set customer data in callInfo');
|
this.logger.debug({customerData: cs.callInfo.customerData}, 'TaskTag:exec set customer data in callInfo');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -160,14 +160,31 @@ class Task extends Emitter {
|
|||||||
const httpHeaders = b3 && {b3};
|
const httpHeaders = b3 && {b3};
|
||||||
span.setAttributes({'http.body': JSON.stringify(params)});
|
span.setAttributes({'http.body': JSON.stringify(params)});
|
||||||
try {
|
try {
|
||||||
|
if (this.id) params.verb_id = this.id;
|
||||||
const json = await this.cs.requestor.request(type, this.actionHook, params, httpHeaders);
|
const json = await this.cs.requestor.request(type, this.actionHook, params, httpHeaders);
|
||||||
span.setAttributes({'http.statusCode': 200});
|
span.setAttributes({'http.statusCode': 200});
|
||||||
span.end();
|
const isWsConnection = this.cs.requestor instanceof WsRequestor;
|
||||||
|
if (!isWsConnection || (expectResponse && json && Array.isArray(json) && json.length)) {
|
||||||
|
span.end();
|
||||||
|
} else {
|
||||||
|
/** we use this span to measure application response latency,
|
||||||
|
* and with websocket connections we generally get the application's response
|
||||||
|
* in a subsequent message from the far end, so we terminate the span when the
|
||||||
|
* first new set of verbs arrive after sending a transcript
|
||||||
|
* */
|
||||||
|
this.emit('VerbHookSpanWaitForEnd', {span});
|
||||||
|
|
||||||
|
// If actionHook delay action is configured, and ws application have not responded yet any verb for actionHook
|
||||||
|
// We have to transfer the task to call-session to await on next ws command verbs, and also run action Hook
|
||||||
|
// delay actions
|
||||||
|
if (this.hookDelayActionOpts) {
|
||||||
|
this.emit('ActionHookDelayActionOptions', this.hookDelayActionOpts);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (expectResponse && json && Array.isArray(json)) {
|
if (expectResponse && json && Array.isArray(json)) {
|
||||||
const makeTask = require('./make_task');
|
const makeTask = require('./make_task');
|
||||||
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
||||||
if (tasks && tasks.length > 0) {
|
if (tasks && tasks.length > 0) {
|
||||||
this.logger.info({tasks: tasks}, `${this.name} replacing application with ${tasks.length} tasks`);
|
|
||||||
this.callSession.replaceApplication(tasks);
|
this.callSession.replaceApplication(tasks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,21 +31,59 @@ class TaskTranscribe extends SttTask {
|
|||||||
this.separateRecognitionPerChannel = this.data.recognizer.separateRecognitionPerChannel;
|
this.separateRecognitionPerChannel = this.data.recognizer.separateRecognitionPerChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* for nested transcribe in dial, unless the app explicitly says so we want to transcribe both legs */
|
||||||
|
if (this.parentTask?.name === TaskName.Dial) {
|
||||||
|
if (this.data.channel === 1 || this.data.channel === 2) {
|
||||||
|
/* transcribe only the channel specified */
|
||||||
|
this.separateRecognitionPerChannel = false;
|
||||||
|
this.channel = this.data.channel;
|
||||||
|
logger.debug(`TaskTranscribe: transcribing only channel ${this.channel} in the Dial verb`);
|
||||||
|
}
|
||||||
|
else if (this.separateRecognitionPerChannel !== false) {
|
||||||
|
this.separateRecognitionPerChannel = true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.channel = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.channel = 1;
|
||||||
|
}
|
||||||
|
|
||||||
this.childSpan = [null, null];
|
this.childSpan = [null, null];
|
||||||
|
|
||||||
// Continuos asr timeout
|
// Continuous asr timeout
|
||||||
this.asrTimeout = typeof this.data.recognizer.asrTimeout === 'number' ? this.data.recognizer.asrTimeout * 1000 : 0;
|
this.asrTimeout = typeof this.data.recognizer.asrTimeout === 'number' ? this.data.recognizer.asrTimeout * 1000 : 0;
|
||||||
if (this.asrTimeout > 0) {
|
if (this.asrTimeout > 0) {
|
||||||
this.isContinuousAsr = true;
|
this.isContinuousAsr = true;
|
||||||
}
|
}
|
||||||
/* buffer speech for continuous asr */
|
/* buffer speech for continuous asr */
|
||||||
this._bufferedTranscripts = [];
|
this._bufferedTranscripts = [ [], [] ]; // for channel 1 and 2
|
||||||
|
this.bugname_prefix = 'transcribe_';
|
||||||
|
this.paused = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
get name() { return TaskName.Transcribe; }
|
get name() { return TaskName.Transcribe; }
|
||||||
|
|
||||||
|
get transcribing1() {
|
||||||
|
return this.channel === 1 || this.separateRecognitionPerChannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
get transcribing2() {
|
||||||
|
return this.channel === 2 || this.separateRecognitionPerChannel && this.ep2;
|
||||||
|
}
|
||||||
|
|
||||||
async exec(cs, {ep, ep2}) {
|
async exec(cs, {ep, ep2}) {
|
||||||
super.exec(cs);
|
await super.exec(cs, {ep, ep2});
|
||||||
|
|
||||||
|
if (this.data.recognizer.vendor === 'nuance') {
|
||||||
|
this.data.recognizer.nuanceOptions = {
|
||||||
|
// by default, nuance STT will recognize only 1st utterance.
|
||||||
|
// enable multiple allow nuance detact all utterances
|
||||||
|
utteranceDetectionMode: 'multiple',
|
||||||
|
...this.data.recognizer.nuanceOptions
|
||||||
|
};
|
||||||
|
}
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||||
|
|
||||||
if (cs.hasGlobalSttHints) {
|
if (cs.hasGlobalSttHints) {
|
||||||
@@ -55,95 +93,42 @@ class TaskTranscribe extends SttTask {
|
|||||||
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
this.logger.debug({hints: this.data.recognizer.hints, hintsBoost: this.data.recognizer.hintsBoost},
|
||||||
'Transcribe:exec - applying global sttHints');
|
'Transcribe:exec - applying global sttHints');
|
||||||
}
|
}
|
||||||
if (cs.hasAltLanguages) {
|
|
||||||
this.data.recognizer.altLanguages = this.data.recognizer.altLanguages.concat(cs.altLanguages);
|
|
||||||
this.logger.debug({altLanguages: this.altLanguages},
|
|
||||||
'Transcribe:exec - applying altLanguages');
|
|
||||||
}
|
|
||||||
if (cs.hasGlobalSttPunctuation && !this.data.recognizer.punctuation) {
|
|
||||||
this.data.recognizer.punctuation = cs.globalSttPunctuation;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.ep = ep;
|
|
||||||
this.ep2 = ep2;
|
|
||||||
if ('default' === this.vendor || !this.vendor) {
|
|
||||||
this.vendor = cs.speechRecognizerVendor;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.vendor = this.vendor;
|
|
||||||
}
|
|
||||||
if ('default' === this.language || !this.language) {
|
|
||||||
this.language = cs.speechRecognizerLanguage;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.language = this.language;
|
|
||||||
}
|
|
||||||
if ('default' === this.label || !this.label) {
|
|
||||||
this.label = cs.speechRecognizerLabel;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.label = this.label;
|
|
||||||
}
|
|
||||||
// Fallback options
|
|
||||||
if ('default' === this.fallbackVendor || !this.fallbackVendor) {
|
|
||||||
this.fallbackVendor = cs.fallbackSpeechRecognizerVendor;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.fallbackVendor = this.fallbackVendor;
|
|
||||||
}
|
|
||||||
if ('default' === this.fallbackLanguage || !this.fallbackLanguage) {
|
|
||||||
this.fallbackLanguage = cs.fallbackSpeechRecognizerLanguage;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.fallbackLanguage = this.fallbackLanguage;
|
|
||||||
}
|
|
||||||
if ('default' === this.fallbackLabel || !this.fallbackLabel) {
|
|
||||||
this.fallbackLabel = cs.fallbackSpeechRecognizerLabel;
|
|
||||||
if (this.data.recognizer) this.data.recognizer.fallbackLabel = this.fallbackLabel;
|
|
||||||
}
|
|
||||||
if (!this.data.recognizer.vendor) {
|
|
||||||
this.data.recognizer.vendor = this.vendor;
|
|
||||||
}
|
|
||||||
if (this.vendor === 'cobalt' && !this.data.recognizer.model) {
|
|
||||||
// By default, application saves cobalt model in language
|
|
||||||
this.data.recognizer.model = cs.speechRecognizerLanguage;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.sttCredentials) {
|
|
||||||
try {
|
|
||||||
this.sttCredentials = await this._initSpeechCredentials(cs, this.vendor, this.label);
|
|
||||||
} catch (error) {
|
|
||||||
if (this.fallbackVendor && this.isHandledByPrimaryProvider) {
|
|
||||||
await this._fallback();
|
|
||||||
} else {
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* when using cobalt model is required */
|
|
||||||
if (this.vendor === 'cobalt' && !this.data.recognizer.model) {
|
|
||||||
this.notifyError({ msg: 'ASR error', details:'Cobalt requires a model to be specified'});
|
|
||||||
throw new Error('Cobalt requires a model to be specified');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this._startTranscribing(cs, ep, 1);
|
if (this.transcribing1) {
|
||||||
if (this.separateRecognitionPerChannel && ep2) {
|
await this._startTranscribing(cs, ep, 1);
|
||||||
|
}
|
||||||
|
if (this.transcribing2) {
|
||||||
await this._startTranscribing(cs, ep2, 2);
|
await this._startTranscribing(cs, ep2, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid)
|
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid)
|
||||||
.catch(() => {/*already logged error */});
|
.catch(() => {/*already logged error */});
|
||||||
|
|
||||||
await this.awaitTaskDone();
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.info(err, 'TaskTranscribe:exec - error');
|
if (!(await this._startFallback(cs, ep, {error: err}))) {
|
||||||
this.parentTask && this.parentTask.emit('error', err);
|
this.logger.info(err, 'TaskTranscribe:exec - error');
|
||||||
|
this.parentTask && this.parentTask.emit('error', err);
|
||||||
|
this.removeCustomEventListeners();
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.removeSpeechListeners(ep);
|
await this.awaitTaskDone();
|
||||||
|
this.removeCustomEventListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
async _stopTranscription() {
|
async _stopTranscription() {
|
||||||
let stopTranscription = false;
|
let stopTranscription = false;
|
||||||
if (this.ep?.connected) {
|
if (this.transcribing1 && this.ep?.connected) {
|
||||||
stopTranscription = true;
|
stopTranscription = true;
|
||||||
this.ep.stopTranscription({vendor: this.vendor})
|
this.ep.stopTranscription({
|
||||||
|
vendor: this.vendor,
|
||||||
|
bugname: this.bugname
|
||||||
|
})
|
||||||
.catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill'));
|
.catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill'));
|
||||||
}
|
}
|
||||||
if (this.separateRecognitionPerChannel && this.ep2 && this.ep2.connected) {
|
if (this.transcribing2 && this.ep2?.connected) {
|
||||||
stopTranscription = true;
|
stopTranscription = true;
|
||||||
this.ep2.stopTranscription({vendor: this.vendor})
|
this.ep2.stopTranscription({vendor: this.vendor, bugname: this.bugname})
|
||||||
.catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill'));
|
.catch((err) => this.logger.info(err, 'Error TaskTranscribe:kill'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,13 +150,13 @@ class TaskTranscribe extends SttTask {
|
|||||||
this.logger.info(`TaskTranscribe:updateTranscribe status ${status}`);
|
this.logger.info(`TaskTranscribe:updateTranscribe status ${status}`);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case TranscribeStatus.Pause:
|
case TranscribeStatus.Pause:
|
||||||
|
this.paused = true;
|
||||||
await this._stopTranscription();
|
await this._stopTranscription();
|
||||||
break;
|
break;
|
||||||
case TranscribeStatus.Resume:
|
case TranscribeStatus.Resume:
|
||||||
await this._startTranscribing(this.cs, this.ep, 1);
|
this.paused = false;
|
||||||
if (this.separateRecognitionPerChannel && this.ep2) {
|
if (this.transcribing1) await this._startTranscribing(this.cs, this.ep, 1);
|
||||||
await this._startTranscribing(this.cs, this.ep2, 2);
|
if (this.transcribing2) await this._startTranscribing(this.cs, this.ep2, 2);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,51 +171,47 @@ class TaskTranscribe extends SttTask {
|
|||||||
if (this.isContinuousAsr) this._doContinuousAsrWithDeepgram(this.asrTimeout);
|
if (this.isContinuousAsr) this._doContinuousAsrWithDeepgram(this.asrTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
const opts = this.setChannelVarsForStt(this, this.sttCredentials, this.data.recognizer);
|
const opts = this.setChannelVarsForStt(this, this.sttCredentials, this.language, this.data.recognizer);
|
||||||
switch (this.vendor) {
|
switch (this.vendor) {
|
||||||
case 'google':
|
case 'google':
|
||||||
this.bugname = 'google_transcribe';
|
this.bugname = `${this.bugname_prefix}google_transcribe`;
|
||||||
ep.addCustomEventListener(GoogleTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, GoogleTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(GoogleTranscriptionEvents.NoAudioDetected,
|
this.addCustomEventListener(ep, GoogleTranscriptionEvents.NoAudioDetected,
|
||||||
this._onNoAudio.bind(this, cs, ep, channel));
|
this._onNoAudio.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(GoogleTranscriptionEvents.MaxDurationExceeded,
|
this.addCustomEventListener(ep, GoogleTranscriptionEvents.MaxDurationExceeded,
|
||||||
this._onMaxDurationExceeded.bind(this, cs, ep, channel));
|
this._onMaxDurationExceeded.bind(this, cs, ep, channel));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'aws':
|
case 'aws':
|
||||||
case 'polly':
|
case 'polly':
|
||||||
this.bugname = 'aws_transcribe';
|
this.bugname = `${this.bugname_prefix}aws_transcribe`;
|
||||||
ep.addCustomEventListener(AwsTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, AwsTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(AwsTranscriptionEvents.NoAudioDetected,
|
this.addCustomEventListener(ep, AwsTranscriptionEvents.NoAudioDetected,
|
||||||
this._onNoAudio.bind(this, cs, ep, channel));
|
this._onNoAudio.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(AwsTranscriptionEvents.MaxDurationExceeded,
|
this.addCustomEventListener(ep, AwsTranscriptionEvents.MaxDurationExceeded,
|
||||||
this._onMaxDurationExceeded.bind(this, cs, ep, channel));
|
this._onMaxDurationExceeded.bind(this, cs, ep, channel));
|
||||||
break;
|
break;
|
||||||
case 'microsoft':
|
case 'microsoft':
|
||||||
this.bugname = 'azure_transcribe';
|
this.bugname = `${this.bugname_prefix}azure_transcribe`;
|
||||||
ep.addCustomEventListener(AzureTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, AzureTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(AzureTranscriptionEvents.NoSpeechDetected,
|
//this.addCustomEventListener(ep, AzureTranscriptionEvents.NoSpeechDetected,
|
||||||
this._onNoAudio.bind(this, cs, ep, channel));
|
// this._onNoAudio.bind(this, cs, ep, channel));
|
||||||
break;
|
break;
|
||||||
case 'nuance':
|
case 'nuance':
|
||||||
this.bugname = 'nuance_transcribe';
|
this.bugname = `${this.bugname_prefix}nuance_transcribe`;
|
||||||
ep.addCustomEventListener(NuanceTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, NuanceTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(NuanceTranscriptionEvents.StartOfSpeech,
|
|
||||||
this._onStartOfSpeech.bind(this, cs, ep, channel));
|
|
||||||
ep.addCustomEventListener(NuanceTranscriptionEvents.TranscriptionComplete,
|
|
||||||
this._onTranscriptionComplete.bind(this, cs, ep, channel));
|
|
||||||
break;
|
break;
|
||||||
case 'deepgram':
|
case 'deepgram':
|
||||||
this.bugname = 'deepgram_transcribe';
|
this.bugname = `${this.bugname_prefix}deepgram_transcribe`;
|
||||||
ep.addCustomEventListener(DeepgramTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(DeepgramTranscriptionEvents.Connect,
|
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Connect,
|
||||||
this._onVendorConnect.bind(this, cs, ep));
|
this._onVendorConnect.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(DeepgramTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.ConnectFailure,
|
||||||
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
||||||
|
|
||||||
/* if app sets deepgramOptions.utteranceEndMs they essentially want continuous asr */
|
/* if app sets deepgramOptions.utteranceEndMs they essentially want continuous asr */
|
||||||
@@ -238,13 +219,13 @@ class TaskTranscribe extends SttTask {
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
case 'soniox':
|
case 'soniox':
|
||||||
this.bugname = 'soniox_transcribe';
|
this.bugname = `${this.bugname_prefix}soniox_transcribe`;
|
||||||
ep.addCustomEventListener(SonioxTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, SonioxTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
break;
|
break;
|
||||||
case 'cobalt':
|
case 'cobalt':
|
||||||
this.bugname = 'cobalt_transcribe';
|
this.bugname = `${this.bugname_prefix}cobalt_transcribe`;
|
||||||
ep.addCustomEventListener(CobaltTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, CobaltTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
|
|
||||||
/* cobalt doesnt have language, it has model, which is required */
|
/* cobalt doesnt have language, it has model, which is required */
|
||||||
@@ -273,45 +254,40 @@ class TaskTranscribe extends SttTask {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'ibm':
|
case 'ibm':
|
||||||
this.bugname = 'ibm_transcribe';
|
this.bugname = `${this.bugname_prefix}ibm_transcribe`;
|
||||||
ep.addCustomEventListener(IbmTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, IbmTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(IbmTranscriptionEvents.Connect,
|
this.addCustomEventListener(ep, IbmTranscriptionEvents.Connect,
|
||||||
this._onVendorConnect.bind(this, cs, ep));
|
this._onVendorConnect.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(IbmTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, IbmTranscriptionEvents.ConnectFailure,
|
||||||
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'nvidia':
|
case 'nvidia':
|
||||||
this.bugname = 'nvidia_transcribe';
|
this.bugname = `${this.bugname_prefix}nvidia_transcribe`;
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, NvidiaTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.StartOfSpeech,
|
|
||||||
this._onStartOfSpeech.bind(this, cs, ep));
|
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.TranscriptionComplete,
|
|
||||||
this._onTranscriptionComplete.bind(this, cs, ep));
|
|
||||||
ep.addCustomEventListener(NvidiaTranscriptionEvents.VadDetected,
|
|
||||||
this._onVadDetected.bind(this, cs, ep));
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'assemblyai':
|
case 'assemblyai':
|
||||||
this.bugname = 'assemblyai_transcribe';
|
this.bugname = `${this.bugname_prefix}assemblyai_transcribe`;
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
this.addCustomEventListener(ep,
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
|
AssemblyAiTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(AssemblyAiTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
|
||||||
|
this.addCustomEventListener(ep, AssemblyAiTranscriptionEvents.ConnectFailure,
|
||||||
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (this.vendor.startsWith('custom:')) {
|
if (this.vendor.startsWith('custom:')) {
|
||||||
this.bugname = `${this.vendor}_transcribe`;
|
this.bugname = `${this.bugname_prefix}${this.vendor}_transcribe`;
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.Transcription,
|
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Transcription,
|
||||||
this._onTranscription.bind(this, cs, ep, channel));
|
this._onTranscription.bind(this, cs, ep, channel));
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.Connect, this._onJambonzConnect.bind(this, cs, ep));
|
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.ConnectFailure,
|
this.addCustomEventListener(ep, JambonzTranscriptionEvents.ConnectFailure,
|
||||||
this._onJambonzConnectFailure.bind(this, cs, ep));
|
this._onVendorConnectFailure.bind(this, cs, ep));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -322,7 +298,7 @@ class TaskTranscribe extends SttTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* common handler for all stt engine errors */
|
/* common handler for all stt engine errors */
|
||||||
ep.addCustomEventListener(JambonzTranscriptionEvents.Error, this._onJambonzError.bind(this, cs, ep));
|
this.addCustomEventListener(ep, JambonzTranscriptionEvents.Error, this._onJambonzError.bind(this, cs, ep));
|
||||||
await ep.set(opts)
|
await ep.set(opts)
|
||||||
.catch((err) => this.logger.info(err, 'Error setting channel variables'));
|
.catch((err) => this.logger.info(err, 'Error setting channel variables'));
|
||||||
}
|
}
|
||||||
@@ -337,11 +313,13 @@ class TaskTranscribe extends SttTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async _transcribe(ep) {
|
async _transcribe(ep) {
|
||||||
|
this.logger.debug(
|
||||||
|
`TaskTranscribe:_transcribe - starting transcription vendor ${this.vendor} bugname ${this.bugname}`);
|
||||||
await ep.startTranscription({
|
await ep.startTranscription({
|
||||||
vendor: this.vendor,
|
vendor: this.vendor,
|
||||||
interim: this.interim ? true : false,
|
interim: this.interim ? true : false,
|
||||||
locale: this.language,
|
locale: this.language,
|
||||||
channels: /*this.separateRecognitionPerChannel ? 2 : */ 1,
|
channels: 1,
|
||||||
bugname: this.bugname,
|
bugname: this.bugname,
|
||||||
hostport: this.hostport
|
hostport: this.hostport
|
||||||
});
|
});
|
||||||
@@ -350,57 +328,122 @@ class TaskTranscribe extends SttTask {
|
|||||||
async _onTranscription(cs, ep, channel, evt, fsEvent) {
|
async _onTranscription(cs, ep, channel, evt, fsEvent) {
|
||||||
// make sure this is not a transcript from answering machine detection
|
// make sure this is not a transcript from answering machine detection
|
||||||
const bugname = fsEvent.getHeader('media-bugname');
|
const bugname = fsEvent.getHeader('media-bugname');
|
||||||
|
const finished = fsEvent.getHeader('transcription-session-finished');
|
||||||
|
const bufferedTranscripts = this._bufferedTranscripts[channel - 1];
|
||||||
if (bugname && this.bugname !== bugname) return;
|
if (bugname && this.bugname !== bugname) return;
|
||||||
|
if (this.paused) {
|
||||||
|
this.logger.debug({evt}, 'TaskTranscribe:_onTranscription - paused, ignoring transcript');
|
||||||
|
}
|
||||||
|
|
||||||
if (this.vendor === 'ibm' && evt?.state === 'listening') return;
|
if (this.vendor === 'ibm' && evt?.state === 'listening') return;
|
||||||
|
|
||||||
if (this.vendor === 'deepgram' && evt.type === 'UtteranceEnd') {
|
if (this.vendor === 'deepgram' && evt.type === 'UtteranceEnd') {
|
||||||
/* we will only get this when we have set utterance_end_ms */
|
/* we will only get this when we have set utterance_end_ms */
|
||||||
if (this._bufferedTranscripts.length === 0) {
|
if (bufferedTranscripts.length === 0) {
|
||||||
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram but no buffered transcripts');
|
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram but no buffered transcripts');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript');
|
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript');
|
||||||
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language);
|
evt = this.consolidateTranscripts(bufferedTranscripts, channel, this.language, this.vendor);
|
||||||
this._bufferedTranscripts = [];
|
evt.is_final = true;
|
||||||
this._resolve('speech', evt);
|
this._bufferedTranscripts[channel - 1] = [];
|
||||||
|
this._resolve(channel, evt);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.logger.debug({evt}, 'TaskTranscribe:_onTranscription - before normalization');
|
this.logger.debug({evt}, 'TaskTranscribe:_onTranscription - before normalization');
|
||||||
|
|
||||||
evt = this.normalizeTranscription(evt, this.vendor, channel, this.language);
|
evt = this.normalizeTranscription(evt, this.vendor, channel, this.language, undefined,
|
||||||
|
this.data.recognizer.punctuation);
|
||||||
this.logger.debug({evt}, 'TaskTranscribe:_onTranscription');
|
this.logger.debug({evt}, 'TaskTranscribe:_onTranscription');
|
||||||
if (evt.alternatives.length === 0) {
|
if (evt.alternatives.length === 0) {
|
||||||
this.logger.info({evt}, 'TaskTranscribe:_onTranscription - got empty transcript, continue listening');
|
this.logger.info({evt}, 'TaskTranscribe:_onTranscription - got empty transcript, continue listening');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (evt.alternatives[0]?.transcript === '' && !cs.callGone && !this.killed) {
|
let emptyTranscript = false;
|
||||||
if (['microsoft', 'deepgram'].includes(this.vendor)) {
|
if (evt.is_final) {
|
||||||
this.logger.info({evt}, 'TaskTranscribe:_onTranscription - got empty transcript, continue listening');
|
if (evt.alternatives.length === 0 || evt.alternatives[0].transcript === '' && !cs.callGone && !this.killed) {
|
||||||
|
emptyTranscript = true;
|
||||||
|
if (finished === 'true' &&
|
||||||
|
['microsoft', 'deepgram'].includes(this.vendor) &&
|
||||||
|
bufferedTranscripts.length === 0) {
|
||||||
|
this.logger.debug({evt}, 'TaskGather:_onTranscription - got empty transcript from old gather, disregarding');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (this.vendor !== 'deepgram') {
|
||||||
|
this.logger.info({evt}, 'TaskGather:_onTranscription - got empty transcript, continue listening');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (this.isContinuousAsr) {
|
||||||
|
this.logger.info({evt},
|
||||||
|
'TaskGather:_onTranscription - got empty deepgram transcript during continous asr, continue listening');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (this.vendor === 'deepgram' && bufferedTranscripts.length > 0) {
|
||||||
|
this.logger.info({evt},
|
||||||
|
'TaskGather:_onTranscription - got empty transcript from deepgram, return the buffered transcripts');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.isContinuousAsr) {
|
||||||
|
/* append the transcript and start listening again for asrTimeout */
|
||||||
|
const t = evt.alternatives[0].transcript;
|
||||||
|
if (t) {
|
||||||
|
/* remove trailing punctuation */
|
||||||
|
if (/[,;:\.!\?]$/.test(t)) {
|
||||||
|
this.logger.debug('TaskGather:_onTranscription - removing trailing punctuation');
|
||||||
|
evt.alternatives[0].transcript = t.slice(0, -1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.logger.info({evt}, 'TaskGather:_onTranscription - got transcript during continous asr');
|
||||||
|
bufferedTranscripts.push(evt);
|
||||||
|
this._startAsrTimer(channel);
|
||||||
|
|
||||||
|
/* some STT engines will keep listening after a final response, so no need to restart */
|
||||||
|
if (!['soniox', 'aws', 'microsoft', 'deepgram', 'google']
|
||||||
|
.includes(this.vendor)) this._startTranscribing(cs, ep, channel);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.info({evt}, 'TaskTranscribe:_onTranscription - got empty transcript, listen again');
|
if (this.vendor === 'soniox') {
|
||||||
this._transcribe(ep);
|
/* compile transcripts into one */
|
||||||
}
|
this._sonioxTranscripts.push(evt.vendor.finalWords);
|
||||||
return;
|
evt = this.compileSonioxTranscripts(this._sonioxTranscripts, 1, this.language);
|
||||||
}
|
this._sonioxTranscripts = [];
|
||||||
|
}
|
||||||
|
else if (this.vendor === 'deepgram') {
|
||||||
|
/* compile transcripts into one */
|
||||||
|
if (!emptyTranscript) bufferedTranscripts.push(evt);
|
||||||
|
|
||||||
if (this.vendor === 'soniox') {
|
/* deepgram can send an empty and final transcript; only if we have any buffered should we resolve */
|
||||||
/* compile transcripts into one */
|
if (bufferedTranscripts.length === 0) return;
|
||||||
this._sonioxTranscripts.push(evt.vendor.finalWords);
|
evt = this.consolidateTranscripts(bufferedTranscripts, channel, this.language);
|
||||||
if (evt.is_final) {
|
this._bufferedTranscripts[channel - 1] = [];
|
||||||
evt = this.compileSonioxTranscripts(this._sonioxTranscripts, 1, this.language);
|
}
|
||||||
this._sonioxTranscripts = [];
|
|
||||||
|
/* here is where we return a final transcript */
|
||||||
|
this.logger.debug({evt}, 'TaskTranscribe:_onTranscription - sending final transcript');
|
||||||
|
this._resolve(channel, evt);
|
||||||
|
/* some STT engines will keep listening after a final response, so no need to restart */
|
||||||
|
if (!['soniox', 'aws', 'microsoft', 'deepgram', 'google']
|
||||||
|
.includes(this.vendor)) this._startTranscribing(cs, ep, channel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
/* interim transcript */
|
||||||
|
|
||||||
if (this.isContinuousAsr && evt.is_final) {
|
/* deepgram can send a non-final transcript but with words that are final, so we need to buffer */
|
||||||
this._bufferedTranscripts.push(evt);
|
if (this.vendor === 'deepgram') {
|
||||||
this._startAsrTimer(channel);
|
const originalEvent = evt.vendor.evt;
|
||||||
} else {
|
if (originalEvent.is_final && evt.alternatives[0].transcript !== '') {
|
||||||
await this._resolve(channel, evt);
|
this.logger.debug({evt}, 'Gather:_onTranscription - buffering a completed (partial) deepgram transcript');
|
||||||
|
bufferedTranscripts.push(evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.interim) {
|
||||||
|
this.logger.debug({evt}, 'TaskTranscribe:_onTranscription - sending interim transcript');
|
||||||
|
this._resolve(channel, evt);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +496,8 @@ class TaskTranscribe extends SttTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onNoAudio(cs, ep, channel) {
|
_onNoAudio(cs, ep, channel) {
|
||||||
this.logger.debug(`TaskTranscribe:_onNoAudio restarting transcription on channel ${channel}`);
|
this.logger.debug(`TaskTranscribe:_onNoAudio on channel ${channel}`);
|
||||||
|
if (this.paused) return;
|
||||||
if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) {
|
if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) {
|
||||||
this.childSpan[channel - 1].span.setAttributes({
|
this.childSpan[channel - 1].span.setAttributes({
|
||||||
channel,
|
channel,
|
||||||
@@ -469,7 +513,8 @@ class TaskTranscribe extends SttTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_onMaxDurationExceeded(cs, ep, channel) {
|
_onMaxDurationExceeded(cs, ep, channel) {
|
||||||
this.logger.debug(`TaskTranscribe:_onMaxDurationExceeded restarting transcription on channel ${channel}`);
|
this.logger.debug(`TaskTranscribe:_onMaxDurationExceeded on channel ${channel}`);
|
||||||
|
if (this.paused) return;
|
||||||
if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) {
|
if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) {
|
||||||
this.childSpan[channel - 1].span.setAttributes({
|
this.childSpan[channel - 1].span.setAttributes({
|
||||||
channel,
|
channel,
|
||||||
@@ -492,44 +537,66 @@ class TaskTranscribe extends SttTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _onJambonzError(cs, _ep, evt) {
|
async _startFallback(cs, _ep, evt) {
|
||||||
this.logger.info({evt}, 'TaskTranscribe:_onJambonzError');
|
if (this.canFallback) {
|
||||||
if (this.isHandledByPrimaryProvider && this.fallbackVendor) {
|
_ep.stopTranscription({
|
||||||
_ep.stopTranscription({vendor: this.vendor})
|
vendor: this.vendor,
|
||||||
|
bugname: this.bugname
|
||||||
|
})
|
||||||
.catch((err) => this.logger.error({err}, `Error stopping transcription for primary vendor ${this.vendor}`));
|
.catch((err) => this.logger.error({err}, `Error stopping transcription for primary vendor ${this.vendor}`));
|
||||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||||
try {
|
try {
|
||||||
await this._fallback();
|
this.notifyError({ msg: 'ASR error',
|
||||||
|
details:`STT Vendor ${this.vendor} error: ${evt.error || evt.reason}`, failover: 'in progress'});
|
||||||
|
await this._initFallback();
|
||||||
let channel = 1;
|
let channel = 1;
|
||||||
if (this.ep !== _ep) {
|
if (this.ep !== _ep) {
|
||||||
channel = 2;
|
channel = 2;
|
||||||
}
|
}
|
||||||
|
this[`_speechHandlersSet_${channel}`] = false;
|
||||||
this._startTranscribing(cs, _ep, channel);
|
this._startTranscribing(cs, _ep, channel);
|
||||||
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
|
updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid);
|
||||||
return;
|
return true;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
this.notifyError({ msg: 'ASR error',
|
||||||
|
details:`STT Vendor ${this.vendor} error: ${evt.error || evt.reason}`, failover: 'not available'});
|
||||||
this.logger.info({error}, `There is error while falling back to ${this.fallbackVendor}`);
|
this.logger.info({error}, `There is error while falling back to ${this.fallbackVendor}`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const {writeAlerts, AlertType} = cs.srf.locals;
|
this.logger.debug('transcribe:_startFallback no condition for falling back');
|
||||||
|
this.notifyError({ msg: 'ASR error',
|
||||||
|
details:`STT Vendor ${this.vendor} error: ${evt.error || evt.reason}`, failover: 'not available'});
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.vendor === 'nuance') {
|
async _onJambonzError(cs, _ep, evt) {
|
||||||
const {code, error} = evt;
|
if (this.vendor === 'google' && evt.error_code === 0) {
|
||||||
if (code === 404 && error === 'No speech') return this._resolve('timeout');
|
this.logger.info({evt}, 'TaskTranscribe:_onJambonzError - ignoring google error code 0');
|
||||||
if (code === 413 && error === 'Too much speech') return this._resolve('timeout');
|
return;
|
||||||
}
|
}
|
||||||
this.logger.info({evt}, 'TaskTranscribe:_onJambonzError');
|
this.logger.info({evt}, 'TaskTranscribe:_onJambonzError');
|
||||||
writeAlerts({
|
if (this.paused) return;
|
||||||
account_sid: cs.accountSid,
|
const {writeAlerts, AlertType} = cs.srf.locals;
|
||||||
alert_type: AlertType.STT_FAILURE,
|
|
||||||
message: `Custom speech vendor ${this.vendor} error: ${evt.error}`,
|
if (this.vendor === 'nuance') {
|
||||||
vendor: this.vendor,
|
const {code, error} = evt;
|
||||||
}).catch((err) => this.logger.info({err}, 'Error generating alert for jambonz custom connection failure'));
|
if (code === 404 && error === 'No speech') return this._resolve('timeout');
|
||||||
this.notifyError({msg: 'ASR error', details:`Custom speech vendor ${this.vendor} error: ${evt.error}`});
|
if (code === 413 && error === 'Too much speech') return this._resolve('timeout');
|
||||||
|
}
|
||||||
|
this.logger.info({evt}, 'TaskTranscribe:_onJambonzError');
|
||||||
|
writeAlerts({
|
||||||
|
account_sid: cs.accountSid,
|
||||||
|
alert_type: AlertType.STT_FAILURE,
|
||||||
|
message: `Custom speech vendor ${this.vendor} error: ${evt.error}`,
|
||||||
|
vendor: this.vendor,
|
||||||
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for jambonz custom connection failure'));
|
||||||
|
if (!(await this._startFallback(cs, _ep, evt))) {
|
||||||
|
this.notifyTaskDone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onVendorConnectFailure(cs, _ep, channel, evt) {
|
async _onVendorConnectFailure(cs, _ep, channel, evt) {
|
||||||
super._onVendorConnectFailure(cs, _ep, evt);
|
super._onVendorConnectFailure(cs, _ep, evt);
|
||||||
if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) {
|
if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) {
|
||||||
this.childSpan[channel - 1].span.setAttributes({
|
this.childSpan[channel - 1].span.setAttributes({
|
||||||
@@ -538,7 +605,9 @@ class TaskTranscribe extends SttTask {
|
|||||||
});
|
});
|
||||||
this.childSpan[channel - 1].span.end();
|
this.childSpan[channel - 1].span.end();
|
||||||
}
|
}
|
||||||
this.notifyTaskDone();
|
if (!(await this._startFallback(cs, _ep, evt))) {
|
||||||
|
this.notifyTaskDone();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_startAsrTimer(channel) {
|
_startAsrTimer(channel) {
|
||||||
@@ -547,8 +616,9 @@ class TaskTranscribe extends SttTask {
|
|||||||
this._clearAsrTimer(channel);
|
this._clearAsrTimer(channel);
|
||||||
this._asrTimer = setTimeout(() => {
|
this._asrTimer = setTimeout(() => {
|
||||||
this.logger.debug(`TaskTranscribe:_startAsrTimer - asr timer went off for channel: ${channel}`);
|
this.logger.debug(`TaskTranscribe:_startAsrTimer - asr timer went off for channel: ${channel}`);
|
||||||
const evt = this.consolidateTranscripts(this._bufferedTranscripts, channel, this.language);
|
const evt = this.consolidateTranscripts(
|
||||||
this._bufferedTranscripts = [];
|
this._bufferedTranscripts[channel - 1], channel, this.language, this.vendor);
|
||||||
|
this._bufferedTranscripts[channel - 1] = [];
|
||||||
this._resolve(channel, evt);
|
this._resolve(channel, evt);
|
||||||
}, this.asrTimeout);
|
}, this.asrTimeout);
|
||||||
this.logger.debug(`TaskTranscribe:_startAsrTimer: set for ${this.asrTimeout}ms for channel ${channel}`);
|
this.logger.debug(`TaskTranscribe:_startAsrTimer: set for ${this.asrTimeout}ms for channel ${channel}`);
|
||||||
|
|||||||
180
lib/tasks/tts-task.js
Normal file
180
lib/tasks/tts-task.js
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
const Task = require('./task');
|
||||||
|
const { TaskPreconditions } = require('../utils/constants');
|
||||||
|
|
||||||
|
class TtsTask extends Task {
|
||||||
|
|
||||||
|
constructor(logger, data, parentTask) {
|
||||||
|
super(logger, data);
|
||||||
|
this.parentTask = parentTask;
|
||||||
|
|
||||||
|
this.preconditions = TaskPreconditions.Endpoint;
|
||||||
|
|
||||||
|
this.earlyMedia = this.data.earlyMedia === true || (parentTask && parentTask.earlyMedia);
|
||||||
|
this.synthesizer = this.data.synthesizer || {};
|
||||||
|
this.disableTtsCache = this.data.disableTtsCache;
|
||||||
|
this.options = this.synthesizer.options || {};
|
||||||
|
}
|
||||||
|
|
||||||
|
async exec(cs) {
|
||||||
|
super.exec(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
async _synthesizeWithSpecificVendor(cs, ep, {
|
||||||
|
vendor,
|
||||||
|
language,
|
||||||
|
voice,
|
||||||
|
label,
|
||||||
|
disableTtsStreaming,
|
||||||
|
preCache
|
||||||
|
}) {
|
||||||
|
const {srf, accountSid:account_sid} = cs;
|
||||||
|
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, srf);
|
||||||
|
const {writeAlerts, AlertType, stats} = srf.locals;
|
||||||
|
const {synthAudio} = srf.locals.dbHelpers;
|
||||||
|
const engine = this.synthesizer.engine || 'standard';
|
||||||
|
const salt = cs.callSid;
|
||||||
|
|
||||||
|
let credentials = cs.getSpeechCredentials(vendor, 'tts', label);
|
||||||
|
/* parse Nuance voices into name and model */
|
||||||
|
let model;
|
||||||
|
if (vendor === 'nuance' && voice) {
|
||||||
|
const arr = /([A-Za-z-]*)\s+-\s+(enhanced|standard)/.exec(voice);
|
||||||
|
if (arr) {
|
||||||
|
voice = arr[1];
|
||||||
|
model = arr[2];
|
||||||
|
}
|
||||||
|
} else if (vendor === 'deepgram') {
|
||||||
|
model = voice;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* allow for microsoft custom region voice and api_key to be specified as an override */
|
||||||
|
if (vendor === 'microsoft' && this.options.deploymentId) {
|
||||||
|
credentials = credentials || {};
|
||||||
|
credentials.use_custom_tts = true;
|
||||||
|
credentials.custom_tts_endpoint = this.options.deploymentId;
|
||||||
|
credentials.api_key = this.options.apiKey || credentials.apiKey;
|
||||||
|
credentials.region = this.options.region || credentials.region;
|
||||||
|
voice = this.options.voice || voice;
|
||||||
|
} else if (vendor === 'elevenlabs') {
|
||||||
|
credentials = credentials || {};
|
||||||
|
credentials.model_id = this.options.model_id || credentials.model_id;
|
||||||
|
credentials.voice_settings = this.options.voice_settings || {};
|
||||||
|
credentials.optimize_streaming_latency = this.options.optimize_streaming_latency
|
||||||
|
|| credentials.optimize_streaming_latency;
|
||||||
|
voice = this.options.voice_id || voice;
|
||||||
|
}
|
||||||
|
|
||||||
|
ep.set({
|
||||||
|
tts_engine: vendor,
|
||||||
|
tts_voice: voice,
|
||||||
|
cache_speech_handles: 1,
|
||||||
|
}).catch((err) => this.logger.info({err}, `${this.name}: Error setting tts_engine on endpoint`));
|
||||||
|
|
||||||
|
if (!preCache) this.logger.info({vendor, language, voice, model}, `${this.name}:exec`);
|
||||||
|
try {
|
||||||
|
if (!credentials) {
|
||||||
|
writeAlerts({
|
||||||
|
account_sid,
|
||||||
|
alert_type: AlertType.TTS_NOT_PROVISIONED,
|
||||||
|
vendor
|
||||||
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for no tts'));
|
||||||
|
this.notifyError({
|
||||||
|
msg: 'TTS error',
|
||||||
|
details:`No speech credentials provisioned for selected vendor ${vendor}`
|
||||||
|
});
|
||||||
|
throw new Error('no provisioned speech credentials for TTS');
|
||||||
|
}
|
||||||
|
// synthesize all of the text elements
|
||||||
|
let lastUpdated = false;
|
||||||
|
|
||||||
|
/* produce an audio segment from the provided text */
|
||||||
|
const generateAudio = async(text) => {
|
||||||
|
if (this.killed) return;
|
||||||
|
if (text.startsWith('silence_stream://')) return text;
|
||||||
|
|
||||||
|
/* otel: trace time for tts */
|
||||||
|
if (!preCache && !this.parentTask) {
|
||||||
|
const {span} = this.startChildSpan('tts-generation', {
|
||||||
|
'tts.vendor': vendor,
|
||||||
|
'tts.language': language,
|
||||||
|
'tts.voice': voice
|
||||||
|
});
|
||||||
|
this.otelSpan = span;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const {filePath, servedFromCache, rtt} = await synthAudio(stats, {
|
||||||
|
account_sid,
|
||||||
|
text,
|
||||||
|
vendor,
|
||||||
|
language,
|
||||||
|
voice,
|
||||||
|
engine,
|
||||||
|
model,
|
||||||
|
salt,
|
||||||
|
credentials,
|
||||||
|
options: this.options,
|
||||||
|
disableTtsCache : this.disableTtsCache,
|
||||||
|
disableTtsStreaming,
|
||||||
|
preCache
|
||||||
|
});
|
||||||
|
if (!filePath.startsWith('say:')) {
|
||||||
|
this.logger.debug(`file ${filePath}, served from cache ${servedFromCache}`);
|
||||||
|
if (filePath) cs.trackTmpFile(filePath);
|
||||||
|
if (this.otelSpan) {
|
||||||
|
this.otelSpan.setAttributes({'tts.cached': servedFromCache});
|
||||||
|
this.otelSpan.end();
|
||||||
|
this.otelSpan = null;
|
||||||
|
}
|
||||||
|
if (!servedFromCache && !lastUpdated) {
|
||||||
|
lastUpdated = true;
|
||||||
|
updateSpeechCredentialLastUsed(credentials.speech_credential_sid).catch(() => {/* logged error */});
|
||||||
|
}
|
||||||
|
if (!servedFromCache && rtt && !preCache) {
|
||||||
|
this.notifyStatus({
|
||||||
|
event: 'synthesized-audio',
|
||||||
|
vendor,
|
||||||
|
language,
|
||||||
|
characters: text.length,
|
||||||
|
elapsedTime: rtt
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.logger.debug('a streaming tts api will be used');
|
||||||
|
const modifiedPath = filePath.replace('say:{', `say:{session-uuid=${ep.uuid},`);
|
||||||
|
return modifiedPath;
|
||||||
|
}
|
||||||
|
return filePath;
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info({err}, 'Error synthesizing tts');
|
||||||
|
if (this.otelSpan) this.otelSpan.end();
|
||||||
|
writeAlerts({
|
||||||
|
account_sid: cs.accountSid,
|
||||||
|
alert_type: AlertType.TTS_FAILURE,
|
||||||
|
vendor,
|
||||||
|
detail: err.message
|
||||||
|
}).catch((err) => this.logger.info({err}, 'Error generating alert for tts failure'));
|
||||||
|
this.notifyError({msg: 'TTS error', details: err.message || err});
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const arr = this.text.map((t) => (this._validateURL(t) ? t : generateAudio(t)));
|
||||||
|
return (await Promise.all(arr)).filter((fp) => fp && fp.length);
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info(err, 'TaskSay:exec error');
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_validateURL(urlString) {
|
||||||
|
try {
|
||||||
|
new URL(urlString);
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TtsTask;
|
||||||
@@ -266,7 +266,7 @@ module.exports = (logger) => {
|
|||||||
|
|
||||||
/* set stt options */
|
/* set stt options */
|
||||||
logger.info(`starting amd for vendor ${vendor} and language ${language}`);
|
logger.info(`starting amd for vendor ${vendor} and language ${language}`);
|
||||||
const sttOpts = amd.setChannelVarsForStt({name: TaskName.Gather}, sttCredentials, {
|
const sttOpts = amd.setChannelVarsForStt({name: TaskName.Gather}, sttCredentials, language, {
|
||||||
vendor,
|
vendor,
|
||||||
hints,
|
hints,
|
||||||
enhancedModel: true,
|
enhancedModel: true,
|
||||||
|
|||||||
195
lib/utils/background-task-manager.js
Normal file
195
lib/utils/background-task-manager.js
Normal file
@@ -0,0 +1,195 @@
|
|||||||
|
const { normalizeJambones } = require('@jambonz/verb-specifications');
|
||||||
|
const makeTask = require('../tasks/make_task');
|
||||||
|
const { JAMBONZ_RECORD_WS_BASE_URL, JAMBONZ_RECORD_WS_USERNAME, JAMBONZ_RECORD_WS_PASSWORD } = require('../config');
|
||||||
|
const Emitter = require('events');
|
||||||
|
|
||||||
|
class BackgroundTaskManager extends Emitter {
|
||||||
|
constructor({cs, logger, rootSpan}) {
|
||||||
|
super();
|
||||||
|
this.tasks = new Map();
|
||||||
|
this.cs = cs;
|
||||||
|
this.logger = logger;
|
||||||
|
this.rootSpan = rootSpan;
|
||||||
|
}
|
||||||
|
|
||||||
|
isTaskRunning(type) {
|
||||||
|
return this.tasks.has(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
getTask(type) {
|
||||||
|
if (this.tasks.has(type)) {
|
||||||
|
return this.tasks.get(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
count() {
|
||||||
|
return this.tasks.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
async newTask(type, opts, sticky = false) {
|
||||||
|
this.logger.info({opts}, `initiating Background task ${type}`);
|
||||||
|
if (this.tasks.has(type)) {
|
||||||
|
this.logger.info(`Background task ${type} is running, skipped`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let task;
|
||||||
|
switch (type) {
|
||||||
|
case 'listen':
|
||||||
|
task = await this._initListen(opts);
|
||||||
|
break;
|
||||||
|
case 'bargeIn':
|
||||||
|
task = await this._initBargeIn(opts);
|
||||||
|
break;
|
||||||
|
case 'record':
|
||||||
|
task = await this._initRecord();
|
||||||
|
break;
|
||||||
|
case 'transcribe':
|
||||||
|
task = await this._initTranscribe(opts);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (task) {
|
||||||
|
this.tasks.set(type, task);
|
||||||
|
}
|
||||||
|
if (task && sticky) task.sticky = true;
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
stop(type) {
|
||||||
|
const task = this.getTask(type);
|
||||||
|
if (task) {
|
||||||
|
this.logger.info(`stopping background task: ${type}`);
|
||||||
|
task.removeAllListeners();
|
||||||
|
task.span.end();
|
||||||
|
task.kill();
|
||||||
|
// Remove task from managed List
|
||||||
|
this.tasks.delete(type);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
stopAll() {
|
||||||
|
this.logger.debug('BackgroundTaskManager:stopAll');
|
||||||
|
for (const key of this.tasks.keys()) {
|
||||||
|
this.stop(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initiate Listen
|
||||||
|
async _initListen(opts, bugname = 'jambonz-background-listen', ignoreCustomerData = false, type = 'listen') {
|
||||||
|
let task;
|
||||||
|
try {
|
||||||
|
const t = normalizeJambones(this.logger, [opts]);
|
||||||
|
task = makeTask(this.logger, t[0]);
|
||||||
|
task.bugname = bugname;
|
||||||
|
task.ignoreCustomerData = ignoreCustomerData;
|
||||||
|
const resources = await this.cs._evaluatePreconditions(task);
|
||||||
|
const {span, ctx} = this.rootSpan.startChildSpan(`background-${type}:${task.summary}`);
|
||||||
|
task.span = span;
|
||||||
|
task.ctx = ctx;
|
||||||
|
task.exec(this.cs, resources)
|
||||||
|
.then(this._taskCompleted.bind(this, type, task))
|
||||||
|
.catch(this._taskError.bind(this, type, task));
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info({err, opts}, `BackgroundTaskManager:_initListen - Error creating ${bugname} task`);
|
||||||
|
}
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initiate Gather
|
||||||
|
async _initBargeIn(opts) {
|
||||||
|
let task;
|
||||||
|
try {
|
||||||
|
const t = normalizeJambones(this.logger, [opts]);
|
||||||
|
task = makeTask(this.logger, t[0]);
|
||||||
|
task
|
||||||
|
.once('dtmf', this._bargeInTaskCompleted.bind(this))
|
||||||
|
.once('vad', this._bargeInTaskCompleted.bind(this))
|
||||||
|
.once('transcription', this._bargeInTaskCompleted.bind(this))
|
||||||
|
.once('timeout', this._bargeInTaskCompleted.bind(this));
|
||||||
|
const resources = await this.cs._evaluatePreconditions(task);
|
||||||
|
const {span, ctx} = this.rootSpan.startChildSpan(`background-bargeIn:${task.summary}`);
|
||||||
|
task.span = span;
|
||||||
|
task.ctx = ctx;
|
||||||
|
task.bugname_prefix = 'background_bargeIn_';
|
||||||
|
task.exec(this.cs, resources)
|
||||||
|
.then(() => {
|
||||||
|
this._taskCompleted('bargeIn', task);
|
||||||
|
if (task.sticky && !this.cs.callGone && !this.cs._stopping) {
|
||||||
|
this.logger.info('BackgroundTaskManager:_initBargeIn: restarting background bargeIn');
|
||||||
|
this.newTask('bargeIn', opts, true);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
})
|
||||||
|
.catch(this._taskError.bind(this, 'bargeIn', task));
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info(err, 'BackgroundTaskManager:_initGather - Error creating bargeIn task');
|
||||||
|
}
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initiate Record
|
||||||
|
async _initRecord() {
|
||||||
|
if (this.cs.accountInfo.account.record_all_calls || this.cs.application.record_all_calls) {
|
||||||
|
if (!JAMBONZ_RECORD_WS_BASE_URL || !this.cs.accountInfo.account.bucket_credential) {
|
||||||
|
this.logger.error('_initRecord: invalid cfg - missing JAMBONZ_RECORD_WS_BASE_URL or bucket config');
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const listenOpts = {
|
||||||
|
url: `${JAMBONZ_RECORD_WS_BASE_URL}/record/${this.cs.accountInfo.account.bucket_credential.vendor}`,
|
||||||
|
disableBidirectionalAudio: true,
|
||||||
|
mixType : 'stereo',
|
||||||
|
passDtmf: true
|
||||||
|
};
|
||||||
|
if (JAMBONZ_RECORD_WS_USERNAME && JAMBONZ_RECORD_WS_PASSWORD) {
|
||||||
|
listenOpts.wsAuth = {
|
||||||
|
username: JAMBONZ_RECORD_WS_USERNAME,
|
||||||
|
password: JAMBONZ_RECORD_WS_PASSWORD
|
||||||
|
};
|
||||||
|
}
|
||||||
|
this.logger.debug({listenOpts}, '_initRecord: enabling listen');
|
||||||
|
return await this._initListen({verb: 'listen', ...listenOpts}, 'jambonz-session-record', true, 'record');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initiate Transcribe
|
||||||
|
async _initTranscribe(opts) {
|
||||||
|
let task;
|
||||||
|
try {
|
||||||
|
const t = normalizeJambones(this.logger, [opts]);
|
||||||
|
task = makeTask(this.logger, t[0]);
|
||||||
|
const resources = await this.cs._evaluatePreconditions(task);
|
||||||
|
const {span, ctx} = this.rootSpan.startChildSpan(`background-transcribe:${task.summary}`);
|
||||||
|
task.span = span;
|
||||||
|
task.ctx = ctx;
|
||||||
|
task.bugname_prefix = 'background_transcribe_';
|
||||||
|
task.exec(this.cs, resources)
|
||||||
|
.then(this._taskCompleted.bind(this, 'transcribe', task))
|
||||||
|
.catch(this._taskError.bind(this, 'transcribe', task));
|
||||||
|
} catch (err) {
|
||||||
|
this.logger.info(err, 'BackgroundTaskManager:_initTranscribe - Error creating transcribe task');
|
||||||
|
}
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
_taskCompleted(type, task) {
|
||||||
|
this.logger.debug({type, task}, `BackgroundTaskManager:_taskCompleted: task completed, sticky: ${task.sticky}`);
|
||||||
|
task.removeAllListeners();
|
||||||
|
task.span.end();
|
||||||
|
this.tasks.delete(type);
|
||||||
|
}
|
||||||
|
_taskError(type, task, error) {
|
||||||
|
this.logger.info({type, task, error}, 'BackgroundTaskManager:_taskError: task Error');
|
||||||
|
task.removeAllListeners();
|
||||||
|
task.span.end();
|
||||||
|
this.tasks.delete(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
_bargeInTaskCompleted(evt) {
|
||||||
|
this.logger.debug({evt},
|
||||||
|
'BackgroundTaskManager:_bargeInTaskCompleted on event from background bargeIn, emitting bargein-done event');
|
||||||
|
this.emit('bargeIn-done', evt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = BackgroundTaskManager;
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"TaskName": {
|
"TaskName": {
|
||||||
"Cognigy": "cognigy",
|
"Answer": "answer",
|
||||||
"Conference": "conference",
|
"Conference": "conference",
|
||||||
"Config": "config",
|
"Config": "config",
|
||||||
"Dequeue": "dequeue",
|
"Dequeue": "dequeue",
|
||||||
"Dial": "dial",
|
"Dial": "dial",
|
||||||
"Dialogflow": "dialogflow",
|
"Dialogflow": "dialogflow",
|
||||||
"Dtmf": "dtmf",
|
"Dtmf": "dtmf",
|
||||||
|
"Dub": "dub",
|
||||||
"Enqueue": "enqueue",
|
"Enqueue": "enqueue",
|
||||||
"Gather": "gather",
|
"Gather": "gather",
|
||||||
"Hangup": "hangup",
|
"Hangup": "hangup",
|
||||||
@@ -29,7 +30,8 @@
|
|||||||
"Tag": "tag",
|
"Tag": "tag",
|
||||||
"Transcribe": "transcribe"
|
"Transcribe": "transcribe"
|
||||||
},
|
},
|
||||||
"AllowedSipRecVerbs": ["config", "gather", "transcribe", "listen", "tag"],
|
"AllowedSipRecVerbs": ["answer", "config", "gather", "transcribe", "listen", "tag"],
|
||||||
|
"AllowedConfirmSessionVerbs": ["config", "gather", "plays", "say", "tag"],
|
||||||
"CallStatus": {
|
"CallStatus": {
|
||||||
"Trying": "trying",
|
"Trying": "trying",
|
||||||
"Ringing": "ringing",
|
"Ringing": "ringing",
|
||||||
@@ -95,6 +97,10 @@
|
|||||||
"Transcription": "soniox_transcribe::transcription",
|
"Transcription": "soniox_transcribe::transcription",
|
||||||
"Error": "soniox_transcribe::error"
|
"Error": "soniox_transcribe::error"
|
||||||
},
|
},
|
||||||
|
"VerbioTranscriptionEvents": {
|
||||||
|
"Transcription": "verbio_transcribe::transcription",
|
||||||
|
"Error": "verbio_transcribe::error"
|
||||||
|
},
|
||||||
"CobaltTranscriptionEvents": {
|
"CobaltTranscriptionEvents": {
|
||||||
"Transcription": "cobalt_speech::transcription",
|
"Transcription": "cobalt_speech::transcription",
|
||||||
"CompileContext": "cobalt_speech::compile_context_response",
|
"CompileContext": "cobalt_speech::compile_context_response",
|
||||||
@@ -132,6 +138,9 @@
|
|||||||
"ConnectFailure": "assemblyai_transcribe::connect_failed",
|
"ConnectFailure": "assemblyai_transcribe::connect_failed",
|
||||||
"Connect": "assemblyai_transcribe::connect"
|
"Connect": "assemblyai_transcribe::connect"
|
||||||
},
|
},
|
||||||
|
"VadDetection": {
|
||||||
|
"Detection": "vad_detect:detection"
|
||||||
|
},
|
||||||
"ListenEvents": {
|
"ListenEvents": {
|
||||||
"Connect": "mod_audio_fork::connect",
|
"Connect": "mod_audio_fork::connect",
|
||||||
"ConnectFailure": "mod_audio_fork::connect_failed",
|
"ConnectFailure": "mod_audio_fork::connect_failed",
|
||||||
@@ -169,6 +178,7 @@
|
|||||||
"session:new",
|
"session:new",
|
||||||
"session:reconnect",
|
"session:reconnect",
|
||||||
"session:redirect",
|
"session:redirect",
|
||||||
|
"session:adulting",
|
||||||
"call:status",
|
"call:status",
|
||||||
"queue:status",
|
"queue:status",
|
||||||
"dial:confirm",
|
"dial:confirm",
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ const speechMapper = (cred) => {
|
|||||||
const o = JSON.parse(decrypt(credential));
|
const o = JSON.parse(decrypt(credential));
|
||||||
obj.access_key_id = o.access_key_id;
|
obj.access_key_id = o.access_key_id;
|
||||||
obj.secret_access_key = o.secret_access_key;
|
obj.secret_access_key = o.secret_access_key;
|
||||||
|
obj.role_arn = o.role_arn;
|
||||||
obj.aws_region = o.aws_region;
|
obj.aws_region = o.aws_region;
|
||||||
}
|
}
|
||||||
else if ('microsoft' === obj.vendor) {
|
else if ('microsoft' === obj.vendor) {
|
||||||
@@ -75,6 +76,8 @@ const speechMapper = (cred) => {
|
|||||||
else if ('deepgram' === obj.vendor) {
|
else if ('deepgram' === obj.vendor) {
|
||||||
const o = JSON.parse(decrypt(credential));
|
const o = JSON.parse(decrypt(credential));
|
||||||
obj.api_key = o.api_key;
|
obj.api_key = o.api_key;
|
||||||
|
obj.deepgram_stt_uri = o.deepgram_stt_uri;
|
||||||
|
obj.deepgram_stt_use_tls = o.deepgram_stt_use_tls;
|
||||||
}
|
}
|
||||||
else if ('soniox' === obj.vendor) {
|
else if ('soniox' === obj.vendor) {
|
||||||
const o = JSON.parse(decrypt(credential));
|
const o = JSON.parse(decrypt(credential));
|
||||||
@@ -91,6 +94,18 @@ const speechMapper = (cred) => {
|
|||||||
const o = JSON.parse(decrypt(credential));
|
const o = JSON.parse(decrypt(credential));
|
||||||
obj.api_key = o.api_key;
|
obj.api_key = o.api_key;
|
||||||
obj.model_id = o.model_id;
|
obj.model_id = o.model_id;
|
||||||
|
obj.options = o.options;
|
||||||
|
} else if ('playht' === obj.vendor) {
|
||||||
|
const o = JSON.parse(decrypt(credential));
|
||||||
|
obj.api_key = o.api_key;
|
||||||
|
obj.user_id = o.user_id;
|
||||||
|
obj.voice_engine = o.voice_engine;
|
||||||
|
obj.options = o.options;
|
||||||
|
} else if ('rimelabs' === obj.vendor) {
|
||||||
|
const o = JSON.parse(decrypt(credential));
|
||||||
|
obj.api_key = o.api_key;
|
||||||
|
obj.model_id = o.model_id;
|
||||||
|
obj.options = o.options;
|
||||||
} else if ('assemblyai' === obj.vendor) {
|
} else if ('assemblyai' === obj.vendor) {
|
||||||
const o = JSON.parse(decrypt(credential));
|
const o = JSON.parse(decrypt(credential));
|
||||||
obj.api_key = o.api_key;
|
obj.api_key = o.api_key;
|
||||||
@@ -98,6 +113,11 @@ const speechMapper = (cred) => {
|
|||||||
const o = JSON.parse(decrypt(credential));
|
const o = JSON.parse(decrypt(credential));
|
||||||
obj.api_key = o.api_key;
|
obj.api_key = o.api_key;
|
||||||
obj.model_id = o.model_id;
|
obj.model_id = o.model_id;
|
||||||
|
} else if ('verbio' === obj.vendor) {
|
||||||
|
const o = JSON.parse(decrypt(credential));
|
||||||
|
obj.client_id = o.client_id;
|
||||||
|
obj.client_secret = o.client_secret;
|
||||||
|
obj.engine_version = o.engine_version;
|
||||||
} else if (obj.vendor.startsWith('custom:')) {
|
} else if (obj.vendor.startsWith('custom:')) {
|
||||||
const o = JSON.parse(decrypt(credential));
|
const o = JSON.parse(decrypt(credential));
|
||||||
obj.auth_token = o.auth_token;
|
obj.auth_token = o.auth_token;
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ const {
|
|||||||
HTTP_PROXY_PORT,
|
HTTP_PROXY_PORT,
|
||||||
HTTP_PROXY_PROTOCOL,
|
HTTP_PROXY_PROTOCOL,
|
||||||
NODE_ENV,
|
NODE_ENV,
|
||||||
|
HTTP_USER_AGENT_HEADER,
|
||||||
} = require('../config');
|
} = require('../config');
|
||||||
|
|
||||||
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
|
const toBase64 = (str) => Buffer.from(str || '', 'utf8').toString('base64');
|
||||||
@@ -116,6 +117,10 @@ class HttpRequestor extends BaseRequestor {
|
|||||||
const url = hook.url || hook;
|
const url = hook.url || hook;
|
||||||
const method = hook.method || 'POST';
|
const method = hook.method || 'POST';
|
||||||
let buf = '';
|
let buf = '';
|
||||||
|
httpHeaders = {
|
||||||
|
...httpHeaders,
|
||||||
|
...(HTTP_USER_AGENT_HEADER && {'user-agent' : HTTP_USER_AGENT_HEADER})
|
||||||
|
};
|
||||||
|
|
||||||
assert.ok(url, 'HttpRequestor:request url was not provided');
|
assert.ok(url, 'HttpRequestor:request url was not provided');
|
||||||
assert.ok, (['GET', 'POST'].includes(method), `HttpRequestor:request method must be 'GET' or 'POST' not ${method}`);
|
assert.ok, (['GET', 'POST'].includes(method), `HttpRequestor:request method must be 'GET' or 'POST' not ${method}`);
|
||||||
|
|||||||
@@ -171,14 +171,17 @@ function installSrfLocals(srf, logger) {
|
|||||||
retrieveFromSortedSet,
|
retrieveFromSortedSet,
|
||||||
retrieveByPatternSortedSet,
|
retrieveByPatternSortedSet,
|
||||||
sortedSetLength,
|
sortedSetLength,
|
||||||
sortedSetPositionByPattern
|
sortedSetPositionByPattern,
|
||||||
} = require('@jambonz/realtimedb-helpers')({}, logger, tracer);
|
} = require('@jambonz/realtimedb-helpers')({}, logger, tracer);
|
||||||
const registrar = new Registrar(logger, client);
|
const registrar = new Registrar(logger, client);
|
||||||
const {
|
const {
|
||||||
synthAudio,
|
synthAudio,
|
||||||
|
addFileToCache,
|
||||||
getNuanceAccessToken,
|
getNuanceAccessToken,
|
||||||
getIbmAccessToken,
|
getIbmAccessToken,
|
||||||
} = require('@jambonz/speech-utils')({redis_client: client}, logger);
|
getAwsAuthToken,
|
||||||
|
getVerbioAccessToken
|
||||||
|
} = require('@jambonz/speech-utils')({}, logger);
|
||||||
const {
|
const {
|
||||||
writeAlerts,
|
writeAlerts,
|
||||||
AlertType
|
AlertType
|
||||||
@@ -215,6 +218,8 @@ function installSrfLocals(srf, logger) {
|
|||||||
listCalls,
|
listCalls,
|
||||||
deleteCall,
|
deleteCall,
|
||||||
synthAudio,
|
synthAudio,
|
||||||
|
getAwsAuthToken,
|
||||||
|
addFileToCache,
|
||||||
createHash,
|
createHash,
|
||||||
retrieveHash,
|
retrieveHash,
|
||||||
deleteKey,
|
deleteKey,
|
||||||
@@ -235,7 +240,8 @@ function installSrfLocals(srf, logger) {
|
|||||||
retrieveFromSortedSet,
|
retrieveFromSortedSet,
|
||||||
retrieveByPatternSortedSet,
|
retrieveByPatternSortedSet,
|
||||||
sortedSetLength,
|
sortedSetLength,
|
||||||
sortedSetPositionByPattern
|
sortedSetPositionByPattern,
|
||||||
|
getVerbioAccessToken
|
||||||
},
|
},
|
||||||
parentLogger: logger,
|
parentLogger: logger,
|
||||||
getSBC,
|
getSBC,
|
||||||
|
|||||||
18
lib/utils/parse-decibels.js
Normal file
18
lib/utils/parse-decibels.js
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
const parseDecibels = (db) => {
|
||||||
|
if (!db) return 0;
|
||||||
|
if (typeof db === 'number') {
|
||||||
|
return db;
|
||||||
|
}
|
||||||
|
else if (typeof db === 'string') {
|
||||||
|
const match = db.match(/([+-]?\d+(\.\d+)?)\s*db/i);
|
||||||
|
if (match) {
|
||||||
|
return Math.trunc(parseFloat(match[1]));
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = parseDecibels;
|
||||||
@@ -13,9 +13,16 @@ const moment = require('moment');
|
|||||||
const stripCodecs = require('./strip-ancillary-codecs');
|
const stripCodecs = require('./strip-ancillary-codecs');
|
||||||
const RootSpan = require('./call-tracer');
|
const RootSpan = require('./call-tracer');
|
||||||
const uuidv4 = require('uuid-random');
|
const uuidv4 = require('uuid-random');
|
||||||
|
const HttpRequestor = require('./http-requestor');
|
||||||
|
const WsRequestor = require('./ws-requestor');
|
||||||
|
const {makeOpusFirst} = require('./sdp-utils');
|
||||||
|
const {
|
||||||
|
JAMBONES_USE_FREESWITCH_TIMER_FD
|
||||||
|
} = require('../config');
|
||||||
|
|
||||||
class SingleDialer extends Emitter {
|
class SingleDialer extends Emitter {
|
||||||
constructor({logger, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask}) {
|
constructor({logger, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask,
|
||||||
|
onHoldMusic}) {
|
||||||
super();
|
super();
|
||||||
assert(target.type);
|
assert(target.type);
|
||||||
|
|
||||||
@@ -38,6 +45,7 @@ class SingleDialer extends Emitter {
|
|||||||
|
|
||||||
this.callSid = uuidv4();
|
this.callSid = uuidv4();
|
||||||
this.dialTask = dialTask;
|
this.dialTask = dialTask;
|
||||||
|
this.onHoldMusic = onHoldMusic;
|
||||||
|
|
||||||
this.on('callStatusChange', this._notifyCallStatusChange.bind(this));
|
this.on('callStatusChange', this._notifyCallStatusChange.bind(this));
|
||||||
}
|
}
|
||||||
@@ -128,6 +136,7 @@ class SingleDialer extends Emitter {
|
|||||||
this.serviceUrl = srf.locals.serviceUrl;
|
this.serviceUrl = srf.locals.serviceUrl;
|
||||||
|
|
||||||
this.ep = await ms.createEndpoint();
|
this.ep = await ms.createEndpoint();
|
||||||
|
this._configMsEndpoint();
|
||||||
this.logger.debug(`SingleDialer:exec - created endpoint ${this.ep.uuid}`);
|
this.logger.debug(`SingleDialer:exec - created endpoint ${this.ep.uuid}`);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,7 +158,7 @@ class SingleDialer extends Emitter {
|
|||||||
|
|
||||||
Object.assign(opts, {
|
Object.assign(opts, {
|
||||||
proxy: `sip:${this.sbcAddress}`,
|
proxy: `sip:${this.sbcAddress}`,
|
||||||
localSdp: this.ep.local.sdp
|
localSdp: opts.opusFirst ? makeOpusFirst(this.ep.local.sdp) : this.ep.local.sdp
|
||||||
});
|
});
|
||||||
if (this.target.auth) opts.auth = this.target.auth;
|
if (this.target.auth) opts.auth = this.target.auth;
|
||||||
inviteSpan = this.startSpan('invite', {
|
inviteSpan = this.startSpan('invite', {
|
||||||
@@ -177,6 +186,7 @@ class SingleDialer extends Emitter {
|
|||||||
* (a) create a logger for this call
|
* (a) create a logger for this call
|
||||||
*/
|
*/
|
||||||
req.srf = srf;
|
req.srf = srf;
|
||||||
|
this.req = req;
|
||||||
this.callInfo = new CallInfo({
|
this.callInfo = new CallInfo({
|
||||||
direction: CallDirection.Outbound,
|
direction: CallDirection.Outbound,
|
||||||
parentCallInfo: this.parentCallInfo,
|
parentCallInfo: this.parentCallInfo,
|
||||||
@@ -185,6 +195,10 @@ class SingleDialer extends Emitter {
|
|||||||
callSid: this.callSid,
|
callSid: this.callSid,
|
||||||
traceId: this.rootSpan.traceId
|
traceId: this.rootSpan.traceId
|
||||||
});
|
});
|
||||||
|
if (this.dialTask && this.dialTask.tag !== null &&
|
||||||
|
typeof this.dialTask.tag === 'object' && !Array.isArray(this.dialTask.tag)) {
|
||||||
|
this.callInfo.customerData = this.dialTask.tag;
|
||||||
|
}
|
||||||
this.logger = srf.locals.parentLogger.child({
|
this.logger = srf.locals.parentLogger.child({
|
||||||
callSid: this.callSid,
|
callSid: this.callSid,
|
||||||
parentCallSid: this.parentCallInfo.callSid,
|
parentCallSid: this.parentCallInfo.callSid,
|
||||||
@@ -249,7 +263,7 @@ class SingleDialer extends Emitter {
|
|||||||
.on('modify', async(req, res) => {
|
.on('modify', async(req, res) => {
|
||||||
try {
|
try {
|
||||||
if (this.ep) {
|
if (this.ep) {
|
||||||
if (this.dialTask && this.dialTask.isOnHold) {
|
if (this.dialTask && this.dialTask.isOnHoldEnabled) {
|
||||||
this.logger.info('dial is onhold, emit event');
|
this.logger.info('dial is onhold, emit event');
|
||||||
this.emit('reinvite', req, res);
|
this.emit('reinvite', req, res);
|
||||||
} else {
|
} else {
|
||||||
@@ -281,17 +295,17 @@ class SingleDialer extends Emitter {
|
|||||||
if (err.status === 487) status.callStatus = CallStatus.NoAnswer;
|
if (err.status === 487) status.callStatus = CallStatus.NoAnswer;
|
||||||
else if ([486, 600].includes(err.status)) status.callStatus = CallStatus.Busy;
|
else if ([486, 600].includes(err.status)) status.callStatus = CallStatus.Busy;
|
||||||
this.logger.info(`SingleDialer:exec outdial failure ${err.status}`);
|
this.logger.info(`SingleDialer:exec outdial failure ${err.status}`);
|
||||||
inviteSpan.setAttributes({'invite.status_code': err.status});
|
inviteSpan?.setAttributes({'invite.status_code': err.status});
|
||||||
inviteSpan.end();
|
inviteSpan?.end();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.logger.error(err, 'SingleDialer:exec');
|
this.logger.error(err, 'SingleDialer:exec');
|
||||||
status.sipStatus = 500;
|
status.sipStatus = 500;
|
||||||
inviteSpan.setAttributes({
|
inviteSpan?.setAttributes({
|
||||||
'invite.status_code': 500,
|
'invite.status_code': 500,
|
||||||
'invite.err': err.message
|
'invite.err': err.message
|
||||||
});
|
});
|
||||||
inviteSpan.end();
|
inviteSpan?.end();
|
||||||
}
|
}
|
||||||
this.emit('callStatusChange', status);
|
this.emit('callStatusChange', status);
|
||||||
if (this.ep) this.ep.destroy();
|
if (this.ep) this.ep.destroy();
|
||||||
@@ -316,6 +330,16 @@ class SingleDialer extends Emitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_configMsEndpoint() {
|
||||||
|
const opts = {
|
||||||
|
...(this.onHoldMusic && {holdMusic: `shout://${this.onHoldMusic.replace(/^https?:\/\//, '')}`}),
|
||||||
|
...(JAMBONES_USE_FREESWITCH_TIMER_FD && {timer_name: 'timerfd'})
|
||||||
|
};
|
||||||
|
if (Object.keys(opts).length > 0) {
|
||||||
|
this.ep.set(opts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run an application on the call after answer, e.g. call screening.
|
* Run an application on the call after answer, e.g. call screening.
|
||||||
* Once the application completes in some fashion, emit an 'accepted' event
|
* Once the application completes in some fashion, emit an 'accepted' event
|
||||||
@@ -329,6 +353,7 @@ class SingleDialer extends Emitter {
|
|||||||
const json = await this.requestor.request('dial:confirm', confirmHook, this.callInfo.toJSON());
|
const json = await this.requestor.request('dial:confirm', confirmHook, this.callInfo.toJSON());
|
||||||
if (!json || (Array.isArray(json) && json.length === 0)) {
|
if (!json || (Array.isArray(json) && json.length === 0)) {
|
||||||
this.logger.info('SingleDialer:_executeApp: no tasks returned from confirm hook');
|
this.logger.info('SingleDialer:_executeApp: no tasks returned from confirm hook');
|
||||||
|
this.emit('accept');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
const tasks = normalizeJambones(this.logger, json).map((tdata) => makeTask(this.logger, tdata));
|
||||||
@@ -383,15 +408,45 @@ class SingleDialer extends Emitter {
|
|||||||
this.dlg.linkedSpanId = this.rootSpan.traceId;
|
this.dlg.linkedSpanId = this.rootSpan.traceId;
|
||||||
const rootSpan = new RootSpan('outbound-call', this.dlg);
|
const rootSpan = new RootSpan('outbound-call', this.dlg);
|
||||||
const newLogger = logger.child({traceId: rootSpan.traceId});
|
const newLogger = logger.child({traceId: rootSpan.traceId});
|
||||||
|
//clone application from parent call with new requestor
|
||||||
|
//parrent application will be closed in case the parent hangup
|
||||||
|
const app = {...application};
|
||||||
|
if ('WS' === app.call_hook?.method ||
|
||||||
|
app.call_hook?.url.startsWith('ws://') || app.call_hook?.url.startsWith('wss://')) {
|
||||||
|
if (app.call_hook?.url) app.call_hook.url += '/adulting';
|
||||||
|
const requestor = new WsRequestor(logger, this.accountInfo.account.account_sid,
|
||||||
|
app.call_hook, this.accountInfo.account.webhook_secret);
|
||||||
|
app.requestor = requestor;
|
||||||
|
app.notifier = requestor;
|
||||||
|
app.call_hook.method = 'WS';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
app.requestor = new HttpRequestor(logger, this.accountInfo.account.account_sid,
|
||||||
|
app.call_hook, this.accountInfo.account.webhook_secret);
|
||||||
|
if (app.call_status_hook) app.notifier = new HttpRequestor(logger,
|
||||||
|
this.accountInfo.account.account_sid, app.call_status_hook,
|
||||||
|
this.accountInfo.account.webhook_secret);
|
||||||
|
else app.notifier = {request: () => {}, close: () => {}};
|
||||||
|
}
|
||||||
|
// Replace old application with new application.
|
||||||
|
this.application = app;
|
||||||
const cs = new AdultingCallSession({
|
const cs = new AdultingCallSession({
|
||||||
logger: newLogger,
|
logger: newLogger,
|
||||||
singleDialer: this,
|
singleDialer: this,
|
||||||
application,
|
application: app,
|
||||||
callInfo: this.callInfo,
|
callInfo: this.callInfo,
|
||||||
accountInfo: this.accountInfo,
|
accountInfo: this.accountInfo,
|
||||||
tasks,
|
tasks,
|
||||||
rootSpan
|
rootSpan
|
||||||
});
|
});
|
||||||
|
app.requestor.request('session:adulting', '/adulting', {
|
||||||
|
...cs.callInfo.toJSON(),
|
||||||
|
parentCallInfo: this.parentCallInfo
|
||||||
|
}).catch((err) => {
|
||||||
|
newLogger.error({err}, 'doAdulting: error sending adulting request');
|
||||||
|
});
|
||||||
|
|
||||||
|
cs.req = this.req;
|
||||||
cs.exec().catch((err) => newLogger.error({err}, 'doAdulting: error executing session'));
|
cs.exec().catch((err) => newLogger.error({err}, 'doAdulting: error executing session'));
|
||||||
return cs;
|
return cs;
|
||||||
}
|
}
|
||||||
@@ -412,6 +467,7 @@ class SingleDialer extends Emitter {
|
|||||||
async reAnchorMedia() {
|
async reAnchorMedia() {
|
||||||
assert(this.dlg && this.dlg.connected && !this.ep);
|
assert(this.dlg && this.dlg.connected && !this.ep);
|
||||||
this.ep = await this.ms.createEndpoint({remoteSdp: this.dlg.remote.sdp});
|
this.ep = await this.ms.createEndpoint({remoteSdp: this.dlg.remote.sdp});
|
||||||
|
this._configMsEndpoint();
|
||||||
await this.dlg.modify(this.ep.local.sdp, {
|
await this.dlg.modify(this.ep.local.sdp, {
|
||||||
headers: {
|
headers: {
|
||||||
'X-Reason': 'anchor-media'
|
'X-Reason': 'anchor-media'
|
||||||
@@ -442,11 +498,12 @@ class SingleDialer extends Emitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function placeOutdial({
|
function placeOutdial({
|
||||||
logger, srf, ms, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask
|
logger, srf, ms, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask,
|
||||||
|
onHoldMusic
|
||||||
}) {
|
}) {
|
||||||
const myOpts = deepcopy(opts);
|
const myOpts = deepcopy(opts);
|
||||||
const sd = new SingleDialer({
|
const sd = new SingleDialer({
|
||||||
logger, sbcAddress, target, myOpts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask
|
logger, sbcAddress, target, myOpts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask, onHoldMusic
|
||||||
});
|
});
|
||||||
sd.exec(srf, ms, myOpts);
|
sd.exec(srf, ms, myOpts);
|
||||||
return sd;
|
return sd;
|
||||||
|
|||||||
@@ -12,6 +12,30 @@ const mergeSdpMedia = (sdp1, sdp2) => {
|
|||||||
return sdpTransform.write(parsedSdp1);
|
return sdpTransform.write(parsedSdp1);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getCodecPlacement = (parsedSdp, codec) => parsedSdp?.media[0]?.rtp?.findIndex((e) => e.codec === codec);
|
||||||
|
|
||||||
|
const isOpusFirst = (sdp) => {
|
||||||
|
return getCodecPlacement(sdpTransform.parse(sdp), 'opus') === 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
const makeOpusFirst = (sdp) => {
|
||||||
|
const parsedSdp = sdpTransform.parse(sdp);
|
||||||
|
// Find the index of the OPUS codec
|
||||||
|
const opusIndex = getCodecPlacement(parsedSdp, 'opus');
|
||||||
|
|
||||||
|
// Move OPUS codec to the beginning
|
||||||
|
if (opusIndex > 0) {
|
||||||
|
const opusEntry = parsedSdp.media[0].rtp.splice(opusIndex, 1)[0];
|
||||||
|
parsedSdp.media[0].rtp.unshift(opusEntry);
|
||||||
|
|
||||||
|
// Also move the corresponding payload type in the "m" line
|
||||||
|
const opusPayloadType = parsedSdp.media[0].payloads.split(' ')[opusIndex];
|
||||||
|
const otherPayloadTypes = parsedSdp.media[0].payloads.split(' ').filter((pt) => pt != opusPayloadType);
|
||||||
|
parsedSdp.media[0].payloads = [opusPayloadType, ...otherPayloadTypes].join(' ');
|
||||||
|
}
|
||||||
|
return sdpTransform.write(parsedSdp);
|
||||||
|
};
|
||||||
|
|
||||||
const extractSdpMedia = (sdp) => {
|
const extractSdpMedia = (sdp) => {
|
||||||
const parsedSdp1 = sdpTransform.parse(sdp);
|
const parsedSdp1 = sdpTransform.parse(sdp);
|
||||||
if (parsedSdp1.media.length > 1) {
|
if (parsedSdp1.media.length > 1) {
|
||||||
@@ -28,5 +52,7 @@ const extractSdpMedia = (sdp) => {
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
isOnhold,
|
isOnhold,
|
||||||
mergeSdpMedia,
|
mergeSdpMedia,
|
||||||
extractSdpMedia
|
extractSdpMedia,
|
||||||
|
isOpusFirst,
|
||||||
|
makeOpusFirst
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -97,8 +97,12 @@ const parseSiprecPayload = (req, logger) => {
|
|||||||
obj[`${prefix}participantstreamassoc`].forEach((ps) => {
|
obj[`${prefix}participantstreamassoc`].forEach((ps) => {
|
||||||
const part = participants[ps.$.participant_id];
|
const part = participants[ps.$.participant_id];
|
||||||
if (part) {
|
if (part) {
|
||||||
part.send = ps[`${prefix}send`][0];
|
if (ps.hasOwnProperty(`${prefix}send`)) {
|
||||||
part.recv = ps[`${prefix}recv`][0];
|
part.send = ps[`${prefix}send`][0];
|
||||||
|
}
|
||||||
|
if (ps.hasOwnProperty(`${prefix}recv`)) {
|
||||||
|
part.recv = ps[`${prefix}recv`][0];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -109,9 +113,9 @@ const parseSiprecPayload = (req, logger) => {
|
|||||||
obj[`${prefix}stream`].forEach((s) => {
|
obj[`${prefix}stream`].forEach((s) => {
|
||||||
const streamId = s.$.stream_id;
|
const streamId = s.$.stream_id;
|
||||||
let sender;
|
let sender;
|
||||||
for (const [k, v] of Object.entries(participants)) {
|
for (const v of Object.values(participants)) {
|
||||||
if (v.send === streamId) {
|
if (v.send === streamId) {
|
||||||
sender = k;
|
sender = v;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,9 +125,15 @@ const parseSiprecPayload = (req, logger) => {
|
|||||||
|
|
||||||
sender.label = s[`${prefix}label`][0];
|
sender.label = s[`${prefix}label`][0];
|
||||||
|
|
||||||
if (-1 !== ['1', 'a_leg', 'inbound'].indexOf(sender.label)) {
|
if (-1 !== ['1', 'a_leg', 'inbound', '10'].indexOf(sender.label)) {
|
||||||
opts.caller.aor = sender.aor ;
|
opts.caller.aor = sender.aor;
|
||||||
if (sender.name) opts.caller.name = sender.name;
|
if (sender.name) opts.caller.name = sender.name;
|
||||||
|
// Remap the sdp stream base on sender label
|
||||||
|
if (!opts.sdp1.includes(`a=label:${sender.label}`)) {
|
||||||
|
const tmp = opts.sdp1;
|
||||||
|
opts.sdp1 = opts.sdp2;
|
||||||
|
opts.sdp2 = tmp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
opts.callee.aor = sender.aor ;
|
opts.callee.aor = sender.aor ;
|
||||||
|
|||||||
@@ -1,15 +1,5 @@
|
|||||||
const {
|
const {
|
||||||
TaskName,
|
TaskName,
|
||||||
AzureTranscriptionEvents,
|
|
||||||
GoogleTranscriptionEvents,
|
|
||||||
AwsTranscriptionEvents,
|
|
||||||
NuanceTranscriptionEvents,
|
|
||||||
DeepgramTranscriptionEvents,
|
|
||||||
SonioxTranscriptionEvents,
|
|
||||||
NvidiaTranscriptionEvents,
|
|
||||||
CobaltTranscriptionEvents,
|
|
||||||
JambonzTranscriptionEvents,
|
|
||||||
AssemblyAiTranscriptionEvents
|
|
||||||
} = require('./constants.json');
|
} = require('./constants.json');
|
||||||
|
|
||||||
const stickyVars = {
|
const stickyVars = {
|
||||||
@@ -112,7 +102,55 @@ const stickyVars = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
const consolidateTranscripts = (bufferedTranscripts, channel, language) => {
|
/**
|
||||||
|
* @see https://developers.deepgram.com/docs/models-languages-overview
|
||||||
|
*/
|
||||||
|
const optimalDeepramModels = {
|
||||||
|
zh: ['base', 'base'],
|
||||||
|
'zh-CN':['base', 'base'],
|
||||||
|
'zh-TW': ['base', 'base'],
|
||||||
|
da: ['enhanced', 'enhanced'],
|
||||||
|
en: ['nova-2-phonecall', 'nova-2'],
|
||||||
|
'en-US': ['nova-2-phonecall', 'nova-2'],
|
||||||
|
'en-AU': ['nova-2', 'nova-2'],
|
||||||
|
'en-GB': ['nova-2', 'nova-2'],
|
||||||
|
'en-IN': ['nova-2', 'nova-2'],
|
||||||
|
'en-NZ': ['nova-2', 'nova-2'],
|
||||||
|
nl: ['nova-2', 'nova-2'],
|
||||||
|
fr: ['nova-2', 'nova-2'],
|
||||||
|
'fr-CA': ['nova-2', 'nova-2'],
|
||||||
|
de: ['nova-2', 'nova-2'],
|
||||||
|
hi: ['nova-2', 'nova-2'],
|
||||||
|
'hi-Latn': ['nova-2', 'nova-2'],
|
||||||
|
id: ['base', 'base'],
|
||||||
|
it: ['nova-2', 'nova-2'],
|
||||||
|
ja: ['enhanced', 'enhanced'],
|
||||||
|
ko: ['nova-2', 'nova-2'],
|
||||||
|
no: ['nova-2', 'nova-2'],
|
||||||
|
pl: ['nova-2', 'nova-2'],
|
||||||
|
pt: ['nova-2', 'nova-2'],
|
||||||
|
'pt-BR': ['nova-2', 'nova-2'],
|
||||||
|
'pt-PT': ['nova-2', 'nova-2'],
|
||||||
|
ru: ['nova-2', 'nova-2'],
|
||||||
|
es: ['nova-2', 'nova-2'],
|
||||||
|
'es-419': ['nova-2', 'nova-2'],
|
||||||
|
'es-LATAM': ['enhanced', 'enhanced'],
|
||||||
|
sv: ['nova-2', 'nova-2'],
|
||||||
|
ta: ['enhanced', 'enhanced'],
|
||||||
|
taq: ['enhanced', 'enhanced'],
|
||||||
|
tr: ['nova-2', 'nova-2'],
|
||||||
|
uk: ['nova-2', 'nova-2']
|
||||||
|
};
|
||||||
|
|
||||||
|
const selectDefaultDeepgramModel = (task, language) => {
|
||||||
|
if (language in optimalDeepramModels) {
|
||||||
|
const [gather, transcribe] = optimalDeepramModels[language];
|
||||||
|
return task.name === TaskName.Gather ? gather : transcribe;
|
||||||
|
}
|
||||||
|
return 'base';
|
||||||
|
};
|
||||||
|
|
||||||
|
const consolidateTranscripts = (bufferedTranscripts, channel, language, vendor) => {
|
||||||
if (bufferedTranscripts.length === 1) return bufferedTranscripts[0];
|
if (bufferedTranscripts.length === 1) return bufferedTranscripts[0];
|
||||||
let totalConfidence = 0;
|
let totalConfidence = 0;
|
||||||
const finalTranscript = bufferedTranscripts.reduce((acc, evt) => {
|
const finalTranscript = bufferedTranscripts.reduce((acc, evt) => {
|
||||||
@@ -153,7 +191,7 @@ const consolidateTranscripts = (bufferedTranscripts, channel, language) => {
|
|||||||
totalConfidence / bufferedTranscripts.length;
|
totalConfidence / bufferedTranscripts.length;
|
||||||
finalTranscript.alternatives[0].transcript = finalTranscript.alternatives[0].transcript.trim();
|
finalTranscript.alternatives[0].transcript = finalTranscript.alternatives[0].transcript.trim();
|
||||||
finalTranscript.vendor = {
|
finalTranscript.vendor = {
|
||||||
name: 'deepgram',
|
name: vendor,
|
||||||
evt: bufferedTranscripts
|
evt: bufferedTranscripts
|
||||||
};
|
};
|
||||||
return finalTranscript;
|
return finalTranscript;
|
||||||
@@ -232,7 +270,7 @@ const normalizeDeepgram = (evt, channel, language, shortUtterance) => {
|
|||||||
language_code: language,
|
language_code: language,
|
||||||
channel_tag: channel,
|
channel_tag: channel,
|
||||||
is_final: shortUtterance ? evt.is_final : evt.speech_final,
|
is_final: shortUtterance ? evt.is_final : evt.speech_final,
|
||||||
alternatives: [alternatives[0]],
|
alternatives: alternatives.length ? [alternatives[0]] : [],
|
||||||
vendor: {
|
vendor: {
|
||||||
name: 'deepgram',
|
name: 'deepgram',
|
||||||
evt: copy
|
evt: copy
|
||||||
@@ -338,19 +376,20 @@ const normalizeNuance = (evt, channel, language) => {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const normalizeMicrosoft = (evt, channel, language) => {
|
const normalizeMicrosoft = (evt, channel, language, punctuation = true) => {
|
||||||
const copy = JSON.parse(JSON.stringify(evt));
|
const copy = JSON.parse(JSON.stringify(evt));
|
||||||
const nbest = evt.NBest;
|
const nbest = evt.NBest;
|
||||||
const language_code = evt.PrimaryLanguage?.Language || language;
|
const language_code = evt.PrimaryLanguage?.Language || language;
|
||||||
const alternatives = nbest ? nbest.map((n) => {
|
const alternatives = nbest ? nbest.map((n) => {
|
||||||
return {
|
return {
|
||||||
confidence: n.Confidence,
|
confidence: n.Confidence,
|
||||||
transcript: n.Display
|
// remove all puntuation if needed
|
||||||
|
transcript: punctuation ? n.Display : n.Display.replace(/\p{P}/gu, '')
|
||||||
};
|
};
|
||||||
}) :
|
}) :
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
transcript: evt.DisplayText || evt.Text
|
transcript: punctuation ? evt.DisplayText || evt.Text : (evt.DisplayText || evt.Text).replace(/\p{P}/gu, '')
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -400,14 +439,14 @@ const normalizeAssemblyAi = (evt, channel, language) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports = (logger) => {
|
module.exports = (logger) => {
|
||||||
const normalizeTranscription = (evt, vendor, channel, language, shortUtterance) => {
|
const normalizeTranscription = (evt, vendor, channel, language, shortUtterance, punctuation) => {
|
||||||
|
|
||||||
//logger.debug({ evt, vendor, channel, language }, 'normalizeTranscription');
|
//logger.debug({ evt, vendor, channel, language }, 'normalizeTranscription');
|
||||||
switch (vendor) {
|
switch (vendor) {
|
||||||
case 'deepgram':
|
case 'deepgram':
|
||||||
return normalizeDeepgram(evt, channel, language, shortUtterance);
|
return normalizeDeepgram(evt, channel, language, shortUtterance);
|
||||||
case 'microsoft':
|
case 'microsoft':
|
||||||
return normalizeMicrosoft(evt, channel, language);
|
return normalizeMicrosoft(evt, channel, language, punctuation);
|
||||||
case 'google':
|
case 'google':
|
||||||
return normalizeGoogle(evt, channel, language);
|
return normalizeGoogle(evt, channel, language);
|
||||||
case 'aws':
|
case 'aws':
|
||||||
@@ -433,22 +472,15 @@ module.exports = (logger) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const setChannelVarsForStt = (task, sttCredentials, rOpts = {}) => {
|
const setChannelVarsForStt = (task, sttCredentials, language, rOpts = {}) => {
|
||||||
let opts = {};
|
let opts = {};
|
||||||
const {enable, voiceMs = 0, mode = -1} = rOpts.vad || {};
|
|
||||||
const vad = {enable, voiceMs, mode};
|
|
||||||
const vendor = rOpts.vendor;
|
const vendor = rOpts.vendor;
|
||||||
|
|
||||||
/* voice activity detection works across vendors */
|
|
||||||
opts = {
|
|
||||||
...opts,
|
|
||||||
...(vad.enable && {START_RECOGNIZING_ON_VAD: 1}),
|
|
||||||
...(vad.enable && vad.voiceMs && {RECOGNIZER_VAD_VOICE_MS: vad.voiceMs}),
|
|
||||||
...(vad.enable && typeof vad.mode === 'number' && {RECOGNIZER_VAD_MODE: vad.mode}),
|
|
||||||
};
|
|
||||||
|
|
||||||
if ('google' === vendor) {
|
if ('google' === vendor) {
|
||||||
const model = task.name === TaskName.Gather ? 'command_and_search' : 'latest_long';
|
const useV2 = rOpts.googleOptions?.serviceVersion === 'v2';
|
||||||
|
const model = task.name === TaskName.Gather ?
|
||||||
|
(useV2 ? 'telephony_short' : 'command_and_search') :
|
||||||
|
(useV2 ? 'long' : 'latest_long');
|
||||||
opts = {
|
opts = {
|
||||||
...opts,
|
...opts,
|
||||||
...(sttCredentials && {GOOGLE_APPLICATION_CREDENTIALS: JSON.stringify(sttCredentials.credentials)}),
|
...(sttCredentials && {GOOGLE_APPLICATION_CREDENTIALS: JSON.stringify(sttCredentials.credentials)}),
|
||||||
@@ -473,13 +505,34 @@ module.exports = (logger) => {
|
|||||||
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
||||||
{GOOGLE_SPEECH_HINTS: JSON.stringify(rOpts.hints)}),
|
{GOOGLE_SPEECH_HINTS: JSON.stringify(rOpts.hints)}),
|
||||||
...(typeof rOpts.hintsBoost === 'number' && {GOOGLE_SPEECH_HINTS_BOOST: rOpts.hintsBoost}),
|
...(typeof rOpts.hintsBoost === 'number' && {GOOGLE_SPEECH_HINTS_BOOST: rOpts.hintsBoost}),
|
||||||
...(rOpts.altLanguages?.length > 0 &&
|
// When altLanguages is emptylist, we have to send value to freeswitch to clear the previous settings
|
||||||
|
...(rOpts.altLanguages &&
|
||||||
{GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
{GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
||||||
...(rOpts.interactionType &&
|
...(rOpts.interactionType &&
|
||||||
{GOOGLE_SPEECH_METADATA_INTERACTION_TYPE: rOpts.interactionType}),
|
{GOOGLE_SPEECH_METADATA_INTERACTION_TYPE: rOpts.interactionType}),
|
||||||
...{GOOGLE_SPEECH_MODEL: rOpts.model || model},
|
...{GOOGLE_SPEECH_MODEL: rOpts.model || model},
|
||||||
...(rOpts.naicsCode > 0 && {GOOGLE_SPEECH_METADATA_INDUSTRY_NAICS_CODE: rOpts.naicsCode}),
|
...(rOpts.naicsCode > 0 && {GOOGLE_SPEECH_METADATA_INDUSTRY_NAICS_CODE: rOpts.naicsCode}),
|
||||||
GOOGLE_SPEECH_METADATA_RECORDING_DEVICE_TYPE: 'phone_line',
|
GOOGLE_SPEECH_METADATA_RECORDING_DEVICE_TYPE: 'phone_line',
|
||||||
|
...(useV2 && {
|
||||||
|
GOOGLE_SPEECH_RECOGNIZER_PARENT: `projects/${sttCredentials.credentials.project_id}/locations/global`,
|
||||||
|
GOOGLE_SPEECH_CLOUD_SERVICES_VERSION: 'v2',
|
||||||
|
...(rOpts.googleOptions?.speechStartTimeoutMs && {
|
||||||
|
GOOGLE_SPEECH_START_TIMEOUT_MS: rOpts.googleOptions.speechStartTimeoutMs
|
||||||
|
}),
|
||||||
|
...(rOpts.googleOptions?.speechEndTimeoutMs && {
|
||||||
|
GOOGLE_SPEECH_END_TIMEOUT_MS: rOpts.googleOptions.speechEndTimeoutMs
|
||||||
|
}),
|
||||||
|
...(rOpts.googleOptions?.transcriptNormalization && {
|
||||||
|
GOOGLE_SPEECH_TRANSCRIPTION_NORMALIZATION: JSON.stringify(rOpts.googleOptions.transcriptNormalization)
|
||||||
|
}),
|
||||||
|
...(rOpts.googleOptions?.enableVoiceActivityEvents && {
|
||||||
|
GOOGLE_SPEECH_ENABLE_VOICE_ACTIVITY_EVENTS: rOpts.googleOptions.enableVoiceActivityEvents
|
||||||
|
}),
|
||||||
|
...(rOpts.sgoogleOptions?.recognizerId) && {GOOGLE_SPEECH_RECOGNIZER_ID: rOpts.googleOptions.recognizerId},
|
||||||
|
...(rOpts.googleOptions?.enableVoiceActivityEvents && {
|
||||||
|
GOOGLE_SPEECH_ENABLE_VOICE_ACTIVITY_EVENTS: rOpts.googleOptions.enableVoiceActivityEvents
|
||||||
|
}),
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if (['aws', 'polly'].includes(vendor)) {
|
else if (['aws', 'polly'].includes(vendor)) {
|
||||||
@@ -489,9 +542,10 @@ module.exports = (logger) => {
|
|||||||
...(rOpts.vocabularyFilterName && {AWS_VOCABULARY_FILTER_NAME: rOpts.vocabularyFilterName}),
|
...(rOpts.vocabularyFilterName && {AWS_VOCABULARY_FILTER_NAME: rOpts.vocabularyFilterName}),
|
||||||
...(rOpts.filterMethod && {AWS_VOCABULARY_FILTER_METHOD: rOpts.filterMethod}),
|
...(rOpts.filterMethod && {AWS_VOCABULARY_FILTER_METHOD: rOpts.filterMethod}),
|
||||||
...(sttCredentials && {
|
...(sttCredentials && {
|
||||||
AWS_ACCESS_KEY_ID: sttCredentials.accessKeyId,
|
...(sttCredentials.accessKeyId && {AWS_ACCESS_KEY_ID: sttCredentials.accessKeyId}),
|
||||||
AWS_SECRET_ACCESS_KEY: sttCredentials.secretAccessKey,
|
...(sttCredentials.secretAccessKey && {AWS_SECRET_ACCESS_KEY: sttCredentials.secretAccessKey}),
|
||||||
AWS_REGION: sttCredentials.region
|
AWS_REGION: sttCredentials.region,
|
||||||
|
...(sttCredentials.sessionToken && {AWS_SESSION_TOKEN: sttCredentials.sessionToken}),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -503,7 +557,8 @@ module.exports = (logger) => {
|
|||||||
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.trim()).join(',')}),
|
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.trim()).join(',')}),
|
||||||
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
...(rOpts.hints?.length > 0 && typeof rOpts.hints[0] === 'object' &&
|
||||||
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.phrase).join(',')}),
|
{AZURE_SPEECH_HINTS: rOpts.hints.map((h) => h.phrase).join(',')}),
|
||||||
...(rOpts.altLanguages && rOpts.altLanguages.length > 0 &&
|
// When altLanguages is emptylist, we have to send value to freeswitch to clear the previous settings
|
||||||
|
...(rOpts.altLanguages &&
|
||||||
{AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
{AZURE_SPEECH_ALTERNATIVE_LANGUAGE_CODES: [...new Set(rOpts.altLanguages)].join(',')}),
|
||||||
...(rOpts.requestSnr && {AZURE_REQUEST_SNR: 1}),
|
...(rOpts.requestSnr && {AZURE_REQUEST_SNR: 1}),
|
||||||
...(rOpts.profanityOption && {AZURE_PROFANITY_OPTION: rOpts.profanityOption}),
|
...(rOpts.profanityOption && {AZURE_PROFANITY_OPTION: rOpts.profanityOption}),
|
||||||
@@ -517,12 +572,17 @@ module.exports = (logger) => {
|
|||||||
...{AZURE_USE_OUTPUT_FORMAT_DETAILED: 1},
|
...{AZURE_USE_OUTPUT_FORMAT_DETAILED: 1},
|
||||||
...(azureOptions.speechSegmentationSilenceTimeoutMs &&
|
...(azureOptions.speechSegmentationSilenceTimeoutMs &&
|
||||||
{AZURE_SPEECH_SEGMENTATION_SILENCE_TIMEOUT_MS: azureOptions.speechSegmentationSilenceTimeoutMs}),
|
{AZURE_SPEECH_SEGMENTATION_SILENCE_TIMEOUT_MS: azureOptions.speechSegmentationSilenceTimeoutMs}),
|
||||||
|
...(azureOptions.languageIdMode &&
|
||||||
|
{AZURE_LANGUAGE_ID_MODE: azureOptions.languageIdMode}),
|
||||||
...(sttCredentials && {
|
...(sttCredentials && {
|
||||||
...(sttCredentials.api_key && {AZURE_SUBSCRIPTION_KEY: sttCredentials.api_key}),
|
...(sttCredentials.api_key && {AZURE_SUBSCRIPTION_KEY: sttCredentials.api_key}),
|
||||||
...(sttCredentials.region && {AZURE_REGION: sttCredentials.region}),
|
...(sttCredentials.region && {AZURE_REGION: sttCredentials.region}),
|
||||||
}),
|
}),
|
||||||
...(sttCredentials.use_custom_stt && sttCredentials.custom_stt_endpoint &&
|
...(sttCredentials.use_custom_stt && sttCredentials.custom_stt_endpoint &&
|
||||||
{AZURE_SERVICE_ENDPOINT_ID: sttCredentials.custom_stt_endpoint}),
|
{AZURE_SERVICE_ENDPOINT_ID: sttCredentials.custom_stt_endpoint}),
|
||||||
|
//azureSttEndpointId overrides sttCredentials.custom_stt_endpoint
|
||||||
|
...(rOpts.azureSttEndpointId &&
|
||||||
|
{AZURE_SERVICE_ENDPOINT_ID: rOpts.azureSttEndpointId}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if ('nuance' === vendor) {
|
else if ('nuance' === vendor) {
|
||||||
@@ -574,15 +634,24 @@ module.exports = (logger) => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
else if ('deepgram' === vendor) {
|
else if ('deepgram' === vendor) {
|
||||||
|
let {model} = rOpts;
|
||||||
const {deepgramOptions = {}} = rOpts;
|
const {deepgramOptions = {}} = rOpts;
|
||||||
|
const deepgramUri = deepgramOptions.deepgramSttUri || sttCredentials.deepgram_stt_uri;
|
||||||
|
const useTls = deepgramOptions.deepgramSttUseTls || sttCredentials.deepgram_stt_use_tls;
|
||||||
|
|
||||||
|
/* default to a sensible model if not supplied */
|
||||||
|
if (!model) {
|
||||||
|
model = selectDefaultDeepgramModel(task, language);
|
||||||
|
}
|
||||||
opts = {
|
opts = {
|
||||||
...opts,
|
...opts,
|
||||||
|
DEEPGRAM_SPEECH_MODEL: model,
|
||||||
|
...(deepgramUri && {DEEPGRAM_URI: deepgramUri}),
|
||||||
|
...(deepgramUri && useTls && {DEEPGRAM_USE_TLS: 1}),
|
||||||
...(sttCredentials.api_key) &&
|
...(sttCredentials.api_key) &&
|
||||||
{DEEPGRAM_API_KEY: sttCredentials.api_key},
|
{DEEPGRAM_API_KEY: sttCredentials.api_key},
|
||||||
...(deepgramOptions.tier) &&
|
...(deepgramOptions.tier) &&
|
||||||
{DEEPGRAM_SPEECH_TIER: deepgramOptions.tier},
|
{DEEPGRAM_SPEECH_TIER: deepgramOptions.tier},
|
||||||
...(deepgramOptions.model) &&
|
|
||||||
{DEEPGRAM_SPEECH_MODEL: deepgramOptions.model},
|
|
||||||
...(deepgramOptions.punctuate) &&
|
...(deepgramOptions.punctuate) &&
|
||||||
{DEEPGRAM_SPEECH_ENABLE_AUTOMATIC_PUNCTUATION: 1},
|
{DEEPGRAM_SPEECH_ENABLE_AUTOMATIC_PUNCTUATION: 1},
|
||||||
...(deepgramOptions.smartFormatting) &&
|
...(deepgramOptions.smartFormatting) &&
|
||||||
@@ -612,7 +681,9 @@ module.exports = (logger) => {
|
|||||||
...(deepgramOptions.keywords) &&
|
...(deepgramOptions.keywords) &&
|
||||||
{DEEPGRAM_SPEECH_KEYWORDS: deepgramOptions.keywords.join(',')},
|
{DEEPGRAM_SPEECH_KEYWORDS: deepgramOptions.keywords.join(',')},
|
||||||
...('endpointing' in deepgramOptions) &&
|
...('endpointing' in deepgramOptions) &&
|
||||||
{DEEPGRAM_SPEECH_ENDPOINTING: deepgramOptions.endpointing},
|
{DEEPGRAM_SPEECH_ENDPOINTING: deepgramOptions.endpointing === false ? 'false' : deepgramOptions.endpointing,
|
||||||
|
// default DEEPGRAM_SPEECH_UTTERANCE_END_MS is 1000, will be override by user settings later if there is.
|
||||||
|
DEEPGRAM_SPEECH_UTTERANCE_END_MS: 1000},
|
||||||
...(deepgramOptions.utteranceEndMs) &&
|
...(deepgramOptions.utteranceEndMs) &&
|
||||||
{DEEPGRAM_SPEECH_UTTERANCE_END_MS: deepgramOptions.utteranceEndMs},
|
{DEEPGRAM_SPEECH_UTTERANCE_END_MS: deepgramOptions.utteranceEndMs},
|
||||||
...(deepgramOptions.vadTurnoff) &&
|
...(deepgramOptions.vadTurnoff) &&
|
||||||
@@ -725,8 +796,26 @@ module.exports = (logger) => {
|
|||||||
...(rOpts.hints?.length > 0 &&
|
...(rOpts.hints?.length > 0 &&
|
||||||
{ASSEMBLYAI_WORD_BOOST: JSON.stringify(rOpts.hints)})
|
{ASSEMBLYAI_WORD_BOOST: JSON.stringify(rOpts.hints)})
|
||||||
};
|
};
|
||||||
}
|
} else if ('verbio' === vendor) {
|
||||||
else if (vendor.startsWith('custom:')) {
|
const {verbioOptions = {}} = rOpts;
|
||||||
|
opts = {
|
||||||
|
...opts,
|
||||||
|
...(sttCredentials.access_token && { VERBIO_ACCESS_TOKEN: sttCredentials.access_token}),
|
||||||
|
...(sttCredentials.engine_version && {VERBIO_ENGINE_VERSION: sttCredentials.engine_version}),
|
||||||
|
...(language && {VERBIO_LANGUAGE: language}),
|
||||||
|
...(verbioOptions.enable_formatting && {VERBIO_ENABLE_FORMATTING: verbioOptions.enable_formatting}),
|
||||||
|
...(verbioOptions.enable_diarization && {VERBIO_ENABLE_DIARIZATION: verbioOptions.enable_diarization}),
|
||||||
|
...(verbioOptions.topic && {VERBIO_TOPIC: verbioOptions.topic}),
|
||||||
|
...(verbioOptions.inline_grammar && {VERBIO_INLINE_GRAMMAR: verbioOptions.inline_grammar}),
|
||||||
|
...(verbioOptions.grammar_uri && {VERBIO_GRAMMAR_URI: verbioOptions.grammar_uri}),
|
||||||
|
...(verbioOptions.label && {VERBIO_LABEL: verbioOptions.label}),
|
||||||
|
...(verbioOptions.recognition_timeout && {VERBIO_RECOGNITION_TIMEOUT: verbioOptions.recognition_timeout}),
|
||||||
|
...(verbioOptions.speech_complete_timeout &&
|
||||||
|
{VERBIO_SPEECH_COMPLETE_TIMEOUT: verbioOptions.speech_complete_timeout}),
|
||||||
|
...(verbioOptions.speech_incomplete_timeout &&
|
||||||
|
{VERBIO_SPEECH_INCOMPLETE_TIMEOUT: verbioOptions.speech_incomplete_timeout}),
|
||||||
|
};
|
||||||
|
} else if (vendor.startsWith('custom:')) {
|
||||||
let {options = {}} = rOpts;
|
let {options = {}} = rOpts;
|
||||||
const {auth_token, custom_stt_url} = sttCredentials;
|
const {auth_token, custom_stt_url} = sttCredentials;
|
||||||
options = {
|
options = {
|
||||||
@@ -740,7 +829,7 @@ module.exports = (logger) => {
|
|||||||
|
|
||||||
opts = {
|
opts = {
|
||||||
...opts,
|
...opts,
|
||||||
JAMBONZ_STT_API_KEY: auth_token,
|
...(auth_token && {JAMBONZ_STT_API_KEY: auth_token}),
|
||||||
JAMBONZ_STT_URL: custom_stt_url,
|
JAMBONZ_STT_URL: custom_stt_url,
|
||||||
...(Object.keys(options).length > 0 && {JAMBONZ_STT_OPTIONS: JSON.stringify(options)}),
|
...(Object.keys(options).length > 0 && {JAMBONZ_STT_OPTIONS: JSON.stringify(options)}),
|
||||||
};
|
};
|
||||||
@@ -752,48 +841,6 @@ module.exports = (logger) => {
|
|||||||
return opts;
|
return opts;
|
||||||
};
|
};
|
||||||
|
|
||||||
const removeSpeechListeners = (ep) => {
|
|
||||||
ep.removeCustomEventListener(GoogleTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(GoogleTranscriptionEvents.EndOfUtterance);
|
|
||||||
ep.removeCustomEventListener(GoogleTranscriptionEvents.VadDetected);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(AwsTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(AwsTranscriptionEvents.VadDetected);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(AzureTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(AzureTranscriptionEvents.NoSpeechDetected);
|
|
||||||
ep.removeCustomEventListener(AzureTranscriptionEvents.VadDetected);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(NuanceTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(NuanceTranscriptionEvents.TranscriptionComplete);
|
|
||||||
ep.removeCustomEventListener(NuanceTranscriptionEvents.StartOfSpeech);
|
|
||||||
ep.removeCustomEventListener(NuanceTranscriptionEvents.VadDetected);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(DeepgramTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(DeepgramTranscriptionEvents.Connect);
|
|
||||||
ep.removeCustomEventListener(DeepgramTranscriptionEvents.ConnectFailure);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(SonioxTranscriptionEvents.Transcription);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(CobaltTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(CobaltTranscriptionEvents.CompileContext);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(NvidiaTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(NvidiaTranscriptionEvents.TranscriptionComplete);
|
|
||||||
ep.removeCustomEventListener(NvidiaTranscriptionEvents.StartOfSpeech);
|
|
||||||
ep.removeCustomEventListener(NvidiaTranscriptionEvents.VadDetected);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(JambonzTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(JambonzTranscriptionEvents.Connect);
|
|
||||||
ep.removeCustomEventListener(JambonzTranscriptionEvents.ConnectFailure);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(JambonzTranscriptionEvents.Error);
|
|
||||||
|
|
||||||
ep.removeCustomEventListener(AssemblyAiTranscriptionEvents.Transcription);
|
|
||||||
ep.removeCustomEventListener(AssemblyAiTranscriptionEvents.Connect);
|
|
||||||
ep.removeCustomEventListener(AssemblyAiTranscriptionEvents.ConnectFailure);
|
|
||||||
};
|
|
||||||
|
|
||||||
const setSpeechCredentialsAtRuntime = (recognizer) => {
|
const setSpeechCredentialsAtRuntime = (recognizer) => {
|
||||||
if (!recognizer) return;
|
if (!recognizer) return;
|
||||||
if (recognizer.vendor === 'nuance') {
|
if (recognizer.vendor === 'nuance') {
|
||||||
@@ -832,7 +879,6 @@ module.exports = (logger) => {
|
|||||||
return {
|
return {
|
||||||
normalizeTranscription,
|
normalizeTranscription,
|
||||||
setChannelVarsForStt,
|
setChannelVarsForStt,
|
||||||
removeSpeechListeners,
|
|
||||||
setSpeechCredentialsAtRuntime,
|
setSpeechCredentialsAtRuntime,
|
||||||
compileSonioxTranscripts,
|
compileSonioxTranscripts,
|
||||||
consolidateTranscripts
|
consolidateTranscripts
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ const {
|
|||||||
JAMBONES_WS_PING_INTERVAL_MS,
|
JAMBONES_WS_PING_INTERVAL_MS,
|
||||||
MAX_RECONNECTS,
|
MAX_RECONNECTS,
|
||||||
JAMBONES_WS_HANDSHAKE_TIMEOUT_MS,
|
JAMBONES_WS_HANDSHAKE_TIMEOUT_MS,
|
||||||
JAMBONES_WS_MAX_PAYLOAD
|
JAMBONES_WS_MAX_PAYLOAD,
|
||||||
|
HTTP_USER_AGENT_HEADER
|
||||||
} = require('../config');
|
} = require('../config');
|
||||||
|
|
||||||
class WsRequestor extends BaseRequestor {
|
class WsRequestor extends BaseRequestor {
|
||||||
@@ -55,6 +56,12 @@ class WsRequestor extends BaseRequestor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type === 'session:new') this.call_sid = params.callSid;
|
if (type === 'session:new') this.call_sid = params.callSid;
|
||||||
|
if (type === 'session:reconnect') {
|
||||||
|
this._reconnectPromise = new Promise((resolve, reject) => {
|
||||||
|
this._reconnectResolve = resolve;
|
||||||
|
this._reconnectReject = reject;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/* if we have an absolute url, and it is http then do a standard webhook */
|
/* if we have an absolute url, and it is http then do a standard webhook */
|
||||||
if (this._isAbsoluteUrl(url) && url.startsWith('http')) {
|
if (this._isAbsoluteUrl(url) && url.startsWith('http')) {
|
||||||
@@ -70,20 +77,23 @@ class WsRequestor extends BaseRequestor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* connect if necessary */
|
/* connect if necessary */
|
||||||
|
const queueMsg = () => {
|
||||||
|
this.logger.debug(
|
||||||
|
`WsRequestor:request(${this.id}) - queueing ${type} message since we are connecting`);
|
||||||
|
if (wantsAck) {
|
||||||
|
const p = new Promise((resolve, reject) => {
|
||||||
|
this.queuedMsg.push({type, hook, params, httpHeaders, promise: {resolve, reject}});
|
||||||
|
});
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.queuedMsg.push({type, hook, params, httpHeaders});
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
};
|
||||||
if (!this.ws) {
|
if (!this.ws) {
|
||||||
if (this.connectInProgress) {
|
if (this.connectInProgress) {
|
||||||
this.logger.debug(
|
return queueMsg();
|
||||||
`WsRequestor:request(${this.id}) - queueing ${type} message since we are connecting`);
|
|
||||||
if (wantsAck) {
|
|
||||||
const p = new Promise((resolve, reject) => {
|
|
||||||
this.queuedMsg.push({type, hook, params, httpHeaders, promise: {resolve, reject}});
|
|
||||||
});
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.queuedMsg.push({type, hook, params, httpHeaders});
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
this.connectInProgress = true;
|
this.connectInProgress = true;
|
||||||
this.logger.debug(`WsRequestor:request(${this.id}) - connecting since we do not have a connection for ${type}`);
|
this.logger.debug(`WsRequestor:request(${this.id}) - connecting since we do not have a connection for ${type}`);
|
||||||
@@ -101,6 +111,10 @@ class WsRequestor extends BaseRequestor {
|
|||||||
return Promise.reject(err);
|
return Promise.reject(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// If jambonz wait for ack from reconnect, queue the msg until reconnect is acked
|
||||||
|
if (type !== 'session:reconnect' && this._reconnectPromise) {
|
||||||
|
return queueMsg();
|
||||||
|
}
|
||||||
assert(this.ws);
|
assert(this.ws);
|
||||||
|
|
||||||
/* prepare and send message */
|
/* prepare and send message */
|
||||||
@@ -118,7 +132,7 @@ class WsRequestor extends BaseRequestor {
|
|||||||
type,
|
type,
|
||||||
msgid,
|
msgid,
|
||||||
call_sid: this.call_sid,
|
call_sid: this.call_sid,
|
||||||
hook: type === 'verb:hook' ? url : undefined,
|
hook: ['verb:hook', 'session:redirect'].includes(type) ? url : undefined,
|
||||||
data: {...payload},
|
data: {...payload},
|
||||||
...b3
|
...b3
|
||||||
};
|
};
|
||||||
@@ -138,6 +152,18 @@ class WsRequestor extends BaseRequestor {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const rejectQueuedMsgs = (err) => {
|
||||||
|
if (this.queuedMsg.length > 0) {
|
||||||
|
for (const {promise} of this.queuedMsg) {
|
||||||
|
this.logger.debug(`WsRequestor:request - preparing queued ${type} for rejectQueuedMsgs`);
|
||||||
|
if (promise) {
|
||||||
|
promise.reject(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.queuedMsg.length = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
//this.logger.debug({obj}, `websocket: sending (${url})`);
|
//this.logger.debug({obj}, `websocket: sending (${url})`);
|
||||||
|
|
||||||
/* special case: reconnecting before we received ack to session:new */
|
/* special case: reconnecting before we received ack to session:new */
|
||||||
@@ -178,16 +204,37 @@ class WsRequestor extends BaseRequestor {
|
|||||||
this.logger.debug({response}, `WsRequestor:request ${url} succeeded in ${rtt}ms`);
|
this.logger.debug({response}, `WsRequestor:request ${url} succeeded in ${rtt}ms`);
|
||||||
this.stats.histogram('app.hook.ws_response_time', rtt, ['hook_type:app']);
|
this.stats.histogram('app.hook.ws_response_time', rtt, ['hook_type:app']);
|
||||||
resolve(response);
|
resolve(response);
|
||||||
|
if (this._reconnectResolve) {
|
||||||
|
this._reconnectResolve();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
failure: (err) => {
|
failure: (err) => {
|
||||||
|
if (this._reconnectReject) {
|
||||||
|
this._reconnectReject(err);
|
||||||
|
}
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
reject(err);
|
reject(err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/* send the message */
|
/* send the message */
|
||||||
this.ws.send(JSON.stringify(obj), () => {
|
this.ws.send(JSON.stringify(obj), async() => {
|
||||||
this.logger.debug({obj}, `WsRequestor:request websocket: sent (${url})`);
|
this.logger.debug({obj}, `WsRequestor:request websocket: sent (${url})`);
|
||||||
|
// If session:reconnect is waiting for ack, hold here until ack to send queuedMsgs
|
||||||
|
if (this._reconnectPromise) {
|
||||||
|
try {
|
||||||
|
await this._reconnectPromise;
|
||||||
|
} catch (err) {
|
||||||
|
// bad thing happened to session:recconnect
|
||||||
|
rejectQueuedMsgs(err);
|
||||||
|
this.emit('reconnect-error');
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
this._reconnectPromise = null;
|
||||||
|
this._reconnectResolve = null;
|
||||||
|
this._reconnectReject = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
sendQueuedMsgs();
|
sendQueuedMsgs();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -228,6 +275,9 @@ class WsRequestor extends BaseRequestor {
|
|||||||
maxRedirects: 2,
|
maxRedirects: 2,
|
||||||
handshakeTimeout,
|
handshakeTimeout,
|
||||||
maxPayload: JAMBONES_WS_MAX_PAYLOAD ? parseInt(JAMBONES_WS_MAX_PAYLOAD) : 24 * 1024,
|
maxPayload: JAMBONES_WS_MAX_PAYLOAD ? parseInt(JAMBONES_WS_MAX_PAYLOAD) : 24 * 1024,
|
||||||
|
headers: {
|
||||||
|
...(HTTP_USER_AGENT_HEADER && {'user-agent' : HTTP_USER_AGENT_HEADER})
|
||||||
|
}
|
||||||
};
|
};
|
||||||
if (this.username && this.password) opts = {...opts, auth: `${this.username}:${this.password}`};
|
if (this.username && this.password) opts = {...opts, auth: `${this.username}:${this.password}`};
|
||||||
|
|
||||||
@@ -322,7 +372,9 @@ class WsRequestor extends BaseRequestor {
|
|||||||
'WsRequestor:_onSocketClosed time to reconnect');
|
'WsRequestor:_onSocketClosed time to reconnect');
|
||||||
if (!this.ws && !this.connectInProgress) {
|
if (!this.ws && !this.connectInProgress) {
|
||||||
this.connectInProgress = true;
|
this.connectInProgress = true;
|
||||||
this._connect().catch((err) => this.connectInProgress = false);
|
return this._connect()
|
||||||
|
.catch((err) => this.logger.error('WsRequestor:_onSocketClosed There is error while reconnect', err))
|
||||||
|
.finally(() => this.connectInProgress = false);
|
||||||
}
|
}
|
||||||
}, this.backoffMs);
|
}, this.backoffMs);
|
||||||
this.backoffMs = this.backoffMs < 2000 ? this.backoffMs * 2 : (this.backoffMs + 2000);
|
this.backoffMs = this.backoffMs < 2000 ? this.backoffMs * 2 : (this.backoffMs + 2000);
|
||||||
@@ -340,7 +392,9 @@ class WsRequestor extends BaseRequestor {
|
|||||||
/* messages must be JSON format */
|
/* messages must be JSON format */
|
||||||
try {
|
try {
|
||||||
const obj = JSON.parse(content);
|
const obj = JSON.parse(content);
|
||||||
const {type, msgid, command, call_sid = this.call_sid, queueCommand = false, data} = obj;
|
//const {type, msgid, command, call_sid = this.call_sid, queueCommand = false, data} = obj;
|
||||||
|
const {type, msgid, command, queueCommand = false, data} = obj;
|
||||||
|
const call_sid = obj.callSid || this.call_sid;
|
||||||
|
|
||||||
//this.logger.debug({obj}, 'WsRequestor:request websocket: received');
|
//this.logger.debug({obj}, 'WsRequestor:request websocket: received');
|
||||||
assert.ok(type, 'type property not supplied');
|
assert.ok(type, 'type property not supplied');
|
||||||
|
|||||||
11089
package-lock.json
generated
11089
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
72
package.json
72
package.json
@@ -1,9 +1,9 @@
|
|||||||
{
|
{
|
||||||
"name": "jambonz-feature-server",
|
"name": "jambonz-feature-server",
|
||||||
"version": "0.8.5",
|
"version": "0.9.0",
|
||||||
"main": "app.js",
|
"main": "app.js",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 10.16.0"
|
"node": ">= 18.x"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"sip",
|
"sip",
|
||||||
@@ -25,57 +25,57 @@
|
|||||||
"jslint:fix": "eslint app.js tracer.js lib --fix"
|
"jslint:fix": "eslint app.js tracer.js lib --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-auto-scaling": "^3.360.0",
|
"@aws-sdk/client-auto-scaling": "^3.549.0",
|
||||||
"@aws-sdk/client-sns": "^3.360.0",
|
"@aws-sdk/client-sns": "^3.549.0",
|
||||||
"@jambonz/db-helpers": "^0.9.1",
|
"@jambonz/db-helpers": "^0.9.3",
|
||||||
"@jambonz/http-health-check": "^0.0.1",
|
"@jambonz/http-health-check": "^0.0.1",
|
||||||
"@jambonz/mw-registrar": "^0.2.4",
|
"@jambonz/mw-registrar": "^0.2.7",
|
||||||
"@jambonz/realtimedb-helpers": "^0.8.7",
|
"@jambonz/realtimedb-helpers": "^0.8.8",
|
||||||
"@jambonz/speech-utils": "^0.0.26",
|
"@jambonz/speech-utils": "^0.1.3",
|
||||||
"@jambonz/stats-collector": "^0.1.9",
|
"@jambonz/stats-collector": "^0.1.10",
|
||||||
"@jambonz/time-series": "^0.2.8",
|
"@jambonz/time-series": "^0.2.8",
|
||||||
"@jambonz/verb-specifications": "^0.0.46",
|
"@jambonz/verb-specifications": "^0.0.72",
|
||||||
"@opentelemetry/api": "^1.4.0",
|
"@opentelemetry/api": "^1.8.0",
|
||||||
"@opentelemetry/exporter-jaeger": "^1.9.0",
|
"@opentelemetry/exporter-jaeger": "^1.23.0",
|
||||||
"@opentelemetry/exporter-trace-otlp-http": "^0.35.0",
|
"@opentelemetry/exporter-trace-otlp-http": "^0.50.0",
|
||||||
"@opentelemetry/exporter-zipkin": "^1.9.0",
|
"@opentelemetry/exporter-zipkin": "^1.23.0",
|
||||||
"@opentelemetry/instrumentation": "^0.35.0",
|
"@opentelemetry/instrumentation": "^0.50.0",
|
||||||
"@opentelemetry/resources": "^1.9.0",
|
"@opentelemetry/resources": "^1.23.0",
|
||||||
"@opentelemetry/sdk-trace-base": "^1.9.0",
|
"@opentelemetry/sdk-trace-base": "^1.23.0",
|
||||||
"@opentelemetry/sdk-trace-node": "^1.9.0",
|
"@opentelemetry/sdk-trace-node": "^1.23.0",
|
||||||
"@opentelemetry/semantic-conventions": "^1.9.0",
|
"@opentelemetry/semantic-conventions": "^1.23.0",
|
||||||
"bent": "^7.3.12",
|
"bent": "^7.3.12",
|
||||||
"debug": "^4.3.4",
|
"debug": "^4.3.4",
|
||||||
"deepcopy": "^2.1.0",
|
"deepcopy": "^2.1.0",
|
||||||
"drachtio-fsmrf": "^3.0.27",
|
"drachtio-fsmrf": "^3.0.43",
|
||||||
"drachtio-srf": "^4.5.31",
|
"drachtio-srf": "^4.5.35",
|
||||||
"express": "^4.18.2",
|
"express": "^4.19.2",
|
||||||
"express-validator": "^7.0.1",
|
"express-validator": "^7.0.1",
|
||||||
"ip": "^1.1.8",
|
"ip": "^2.0.1",
|
||||||
"moment": "^2.29.4",
|
"moment": "^2.30.1",
|
||||||
"parse-url": "^8.1.0",
|
"parse-url": "^9.2.0",
|
||||||
"pino": "^8.8.0",
|
"pino": "^8.20.0",
|
||||||
"polly-ssml-split": "^0.1.0",
|
"polly-ssml-split": "^0.1.0",
|
||||||
"proxyquire": "^2.1.3",
|
"proxyquire": "^2.1.3",
|
||||||
"sdp-transform": "^2.14.1",
|
"sdp-transform": "^2.14.2",
|
||||||
"short-uuid": "^4.2.2",
|
"short-uuid": "^5.1.0",
|
||||||
"sinon": "^15.0.1",
|
"sinon": "^17.0.1",
|
||||||
"to-snake-case": "^1.0.0",
|
"to-snake-case": "^1.0.0",
|
||||||
"undici": "^5.26.2",
|
"undici": "^6.15.0",
|
||||||
"uuid-random": "^1.3.2",
|
"uuid-random": "^1.3.2",
|
||||||
"verify-aws-sns-signature": "^0.1.0",
|
"verify-aws-sns-signature": "^0.1.0",
|
||||||
"ws": "^8.9.0",
|
"ws": "^8.17.0",
|
||||||
"xml2js": "^0.6.2"
|
"xml2js": "^0.6.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"clear-module": "^4.1.2",
|
"clear-module": "^4.1.2",
|
||||||
"eslint": "^7.32.0",
|
"eslint": "7.32.0",
|
||||||
"eslint-plugin-promise": "^4.3.1",
|
"eslint-plugin-promise": "^6.1.1",
|
||||||
"nyc": "^15.1.0",
|
"nyc": "^15.1.0",
|
||||||
"tape": "^5.6.1"
|
"tape": "^5.7.5"
|
||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"bufferutil": "^4.0.6",
|
"bufferutil": "^4.0.8",
|
||||||
"utf-8-validate": "^5.0.8"
|
"utf-8-validate": "^6.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -99,6 +99,8 @@ test('test create-call call-hook basic authentication', async(t) => {
|
|||||||
let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}`)
|
let obj = await getJSON(`http:127.0.0.1:3100/lastRequest/${from}`)
|
||||||
t.ok(obj.headers.Authorization = 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=',
|
t.ok(obj.headers.Authorization = 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=',
|
||||||
'create-call: call-hook contains basic authentication header');
|
'create-call: call-hook contains basic authentication header');
|
||||||
|
t.ok(obj.headers['user-agent'] = 'jambonz',
|
||||||
|
'create-call: call-hook contains user-agent header');
|
||||||
disconnect();
|
disconnect();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`error received: ${err}`);
|
console.log(`error received: ${err}`);
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ services:
|
|||||||
ipv4_address: 172.38.0.7
|
ipv4_address: 172.38.0.7
|
||||||
|
|
||||||
drachtio:
|
drachtio:
|
||||||
image: drachtio/drachtio-server:0.8.22
|
image: drachtio/drachtio-server:0.8.25-rc8
|
||||||
restart: always
|
restart: always
|
||||||
command: drachtio --contact "sip:*;transport=udp" --mtu 4096 --address 0.0.0.0 --port 9022
|
command: drachtio --contact "sip:*;transport=udp" --mtu 4096 --address 0.0.0.0 --port 9022
|
||||||
ports:
|
ports:
|
||||||
@@ -57,7 +57,7 @@ services:
|
|||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
|
|
||||||
freeswitch:
|
freeswitch:
|
||||||
image: drachtio/drachtio-freeswitch-mrf:0.4.33
|
image: drachtio/drachtio-freeswitch-mrf:0.7.3
|
||||||
restart: always
|
restart: always
|
||||||
command: freeswitch --rtp-range-start 20000 --rtp-range-end 20100
|
command: freeswitch --rtp-range-start 20000 --rtp-range-end 20100
|
||||||
environment:
|
environment:
|
||||||
|
|||||||
53
test/hangup-test.js
Normal file
53
test/hangup-test.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const { sippUac } = require('./sipp')('test_fs');
|
||||||
|
const clearModule = require('clear-module');
|
||||||
|
const {provisionCallHook, provisionCustomHook} = require('./utils')
|
||||||
|
const bent = require('bent');
|
||||||
|
const getJSON = bent('json')
|
||||||
|
|
||||||
|
process.on('unhandledRejection', (reason, p) => {
|
||||||
|
console.log('Unhandled Rejection at: Promise', p, 'reason:', reason);
|
||||||
|
});
|
||||||
|
|
||||||
|
function connect(connectable) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
connectable.on('connect', () => {
|
||||||
|
return resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
test('\'hangup\' custom headers', async(t) => {
|
||||||
|
clearModule.all();
|
||||||
|
const {srf, disconnect} = require('../app');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
|
||||||
|
// GIVEN
|
||||||
|
const verbs = [
|
||||||
|
{
|
||||||
|
verb: 'play',
|
||||||
|
url: 'https://example.com/example.mp3'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verb": "hangup",
|
||||||
|
"headers": {
|
||||||
|
"X-Reason" : "maximum call duration exceeded"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const from = 'hangup_custom_headers';
|
||||||
|
await provisionCallHook(from, verbs)
|
||||||
|
|
||||||
|
// THEN
|
||||||
|
await sippUac('uac-success-received-bye.xml', '172.38.0.10', from);
|
||||||
|
t.pass('play: succeeds when using single link');
|
||||||
|
disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
disconnect();
|
||||||
|
t.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -16,6 +16,8 @@ require('./listen-tests');
|
|||||||
require('./config-test');
|
require('./config-test');
|
||||||
require('./queue-test');
|
require('./queue-test');
|
||||||
require('./in-dialog-test');
|
require('./in-dialog-test');
|
||||||
|
require('./hangup-test');
|
||||||
|
require('./sdp-utils-test');
|
||||||
require('./http-proxy-test');
|
require('./http-proxy-test');
|
||||||
require('./remove-test-db');
|
require('./remove-test-db');
|
||||||
require('./docker_stop');
|
require('./docker_stop');
|
||||||
@@ -188,7 +188,7 @@ test('\'play\' tests with seekOffset and actionHook', async(t) => {
|
|||||||
const seconds = parseInt(obj.body.playback_seconds);
|
const seconds = parseInt(obj.body.playback_seconds);
|
||||||
const milliseconds = parseInt(obj.body.playback_milliseconds);
|
const milliseconds = parseInt(obj.body.playback_milliseconds);
|
||||||
const lastOffsetPos = parseInt(obj.body.playback_last_offset_pos);
|
const lastOffsetPos = parseInt(obj.body.playback_last_offset_pos);
|
||||||
//console.log({obj}, 'lastRequest');
|
console.log({obj}, 'lastRequest');
|
||||||
t.ok(obj.body.reason === "playCompleted", "play: actionHook success received");
|
t.ok(obj.body.reason === "playCompleted", "play: actionHook success received");
|
||||||
t.ok(seconds === 2, "playback_seconds: actionHook success received");
|
t.ok(seconds === 2, "playback_seconds: actionHook success received");
|
||||||
t.ok(milliseconds === 2048, "playback_milliseconds: actionHook success received");
|
t.ok(milliseconds === 2048, "playback_milliseconds: actionHook success received");
|
||||||
|
|||||||
26
test/sdp-utils-test.js
Normal file
26
test/sdp-utils-test.js
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
const test = require('tape');
|
||||||
|
const {makeOpusFirst, isOpusFirst} = require('../lib/utils/sdp-utils');
|
||||||
|
const sdpTransform = require('sdp-transform');
|
||||||
|
|
||||||
|
test('test opus first', (t) => {
|
||||||
|
const sdp = 'v=0\r\no=- 3348584794228993675 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS caca8b77-5ae5-4e73-a4d5-de1fce930335\r\nm=audio 57088 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126\r\nc=IN IP4 14.238.89.50\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=candidate:1401281302 1 udp 2122260223 10.231.36.146 57088 typ host generation 0 network-id 1 network-cost 10\r\na=candidate:2173263513 1 udp 1686052607 14.238.89.50 57088 typ srflx raddr 10.231.36.146 rport 57088 generation 0 network-id 1 network-cost 10\r\na=ice-ufrag:k5nc\r\na=ice-pwd:J0qwMs6HrIcFNZbDG5m8Kqpk\r\na=ice-options:trickle\r\na=fingerprint:sha-256 66:DE:9A:76:CE:11:2D:65:C4:08:C7:87:B4:90:7E:F1:8D:07:B9:F4:FF:E3:81:D7:E7:7D:C6:56:47:01:6E:55\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=sendrecv\r\na=msid:caca8b77-5ae5-4e73-a4d5-de1fce930335 52ad01f1-b1df-4b8e-a208-9201e98b6f7b\r\na=rtcp-mux\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:63 red/48000/2\r\na=fmtp:63 111/111\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:111 opus/48000/2\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:3207459321 cname:4nyPJ6KXvseBUIhu\r\na=ssrc:3207459321 msid:caca8b77-5ae5-4e73-a4d5-de1fce930335 52ad01f1-b1df-4b8e-a208-9201e98b6f7b\r\n';
|
||||||
|
const opusSdp = makeOpusFirst(sdp);
|
||||||
|
const parsedSdp = sdpTransform.parse(opusSdp);
|
||||||
|
const opusIndex = parsedSdp.media[0].rtp.findIndex((entry) => entry.codec === 'opus');
|
||||||
|
t.ok(opusIndex === 0, 'succesffuly move opus to be first offer')
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('test is opus first', (t) => {
|
||||||
|
|
||||||
|
const sdp = 'v=0\r\no=- 3348584794228993675 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS caca8b77-5ae5-4e73-a4d5-de1fce930335\r\nm=audio 57088 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126\r\nc=IN IP4 14.238.89.50\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=candidate:1401281302 1 udp 2122260223 10.231.36.146 57088 typ host generation 0 network-id 1 network-cost 10\r\na=candidate:2173263513 1 udp 1686052607 14.238.89.50 57088 typ srflx raddr 10.231.36.146 rport 57088 generation 0 network-id 1 network-cost 10\r\na=ice-ufrag:k5nc\r\na=ice-pwd:J0qwMs6HrIcFNZbDG5m8Kqpk\r\na=ice-options:trickle\r\na=fingerprint:sha-256 66:DE:9A:76:CE:11:2D:65:C4:08:C7:87:B4:90:7E:F1:8D:07:B9:F4:FF:E3:81:D7:E7:7D:C6:56:47:01:6E:55\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=sendrecv\r\na=msid:caca8b77-5ae5-4e73-a4d5-de1fce930335 52ad01f1-b1df-4b8e-a208-9201e98b6f7b\r\na=rtcp-mux\r\na=rtpmap:111 opus/48000/2\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:63 red/48000/2\r\na=fmtp:63 111/111\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:3207459321 cname:4nyPJ6KXvseBUIhu\r\na=ssrc:3207459321 msid:caca8b77-5ae5-4e73-a4d5-de1fce930335 52ad01f1-b1df-4b8e-a208-9201e98b6f7b\r\n';
|
||||||
|
t.ok(isOpusFirst(sdp), "opus is first offer");
|
||||||
|
|
||||||
|
const sdp2 = 'v=0\r\no=- 3348584794228993675 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\na=group:BUNDLE 0\r\na=extmap-allow-mixed\r\na=msid-semantic: WMS caca8b77-5ae5-4e73-a4d5-de1fce930335\r\nm=audio 57088 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126\r\nc=IN IP4 14.238.89.50\r\na=rtcp:9 IN IP4 0.0.0.0\r\na=candidate:1401281302 1 udp 2122260223 10.231.36.146 57088 typ host generation 0 network-id 1 network-cost 10\r\na=candidate:2173263513 1 udp 1686052607 14.238.89.50 57088 typ srflx raddr 10.231.36.146 rport 57088 generation 0 network-id 1 network-cost 10\r\na=ice-ufrag:k5nc\r\na=ice-pwd:J0qwMs6HrIcFNZbDG5m8Kqpk\r\na=ice-options:trickle\r\na=fingerprint:sha-256 66:DE:9A:76:CE:11:2D:65:C4:08:C7:87:B4:90:7E:F1:8D:07:B9:F4:FF:E3:81:D7:E7:7D:C6:56:47:01:6E:55\r\na=setup:actpass\r\na=mid:0\r\na=extmap:1 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\na=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\na=extmap:3 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\na=extmap:4 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=sendrecv\r\na=msid:caca8b77-5ae5-4e73-a4d5-de1fce930335 52ad01f1-b1df-4b8e-a208-9201e98b6f7b\r\na=rtcp-mux\r\na=rtcp-fb:111 transport-cc\r\na=fmtp:111 minptime=10;useinbandfec=1\r\na=rtpmap:63 red/48000/2\r\na=fmtp:63 111/111\r\na=rtpmap:9 G722/8000\r\na=rtpmap:0 PCMU/8000\r\na=rtpmap:8 PCMA/8000\r\na=rtpmap:13 CN/8000\r\na=rtpmap:111 opus/48000/2\r\na=rtpmap:110 telephone-event/48000\r\na=rtpmap:126 telephone-event/8000\r\na=ssrc:3207459321 cname:4nyPJ6KXvseBUIhu\r\na=ssrc:3207459321 msid:caca8b77-5ae5-4e73-a4d5-de1fce930335 52ad01f1-b1df-4b8e-a208-9201e98b6f7b\r\n';
|
||||||
|
t.ok(!isOpusFirst(sdp2), "opus is not first offer")
|
||||||
|
|
||||||
|
const sdp3 = 'v=0\r\no=xhoaluu2 1314 1504 IN IP4 192.168.1.4\r\ns=Talk\r\nc=IN IP4 192.168.1.4\r\nt=0 0\r\na=ice-pwd:397d063ea23fdc05164e3ee4\r\na=ice-ufrag:16c449a3\r\na=rtcp-xr:rcvr-rtt=all:10000 stat-summary=loss,dup,jitt,TTL voip-metrics\r\na=group:BUNDLE as\r\na=record:off\r\nm=audio 56542 RTP/AVPF 0 8\r\nc=IN IP4 14.226.233.151\r\na=rtcp-mux\r\na=mid:as\r\na=extmap:1 urn:ietf:params:rtp-hdrext:sdes:mid\r\na=rtcp:63076 IN IP4 192.168.1.4\r\na=candidate:1 1 UDP 2130706303 192.168.1.4 56542 typ host\r\na=candidate:1 2 UDP 2130706302 192.168.1.4 63076 typ host\r\na=candidate:2 1 UDP 2130706431 2001:ee0:d744:dcf0:c1d3:d73f:7a93:dc9f 56542 typ host\r\na=candidate:2 2 UDP 2130706430 2001:ee0:d744:dcf0:c1d3:d73f:7a93:dc9f 63076 typ host\r\na=candidate:3 1 UDP 2130706431 2001:ee0:d744:dcf0:15:6be3:8e6b:b736 56542 typ host\r\na=candidate:3 2 UDP 2130706430 2001:ee0:d744:dcf0:15:6be3:8e6b:b736 63076 typ host\r\na=candidate:4 1 UDP 1694498687 14.226.233.151 56542 typ srflx raddr 192.168.1.4 rport 56542\r\na=rtcp-fb:* trr-int 1000\r\na=rtcp-fb:* ccm tmmbr';
|
||||||
|
t.ok(!isOpusFirst(sdp2), "opus is not first offer")
|
||||||
|
t.end();
|
||||||
|
});
|
||||||
@@ -52,6 +52,7 @@ test('\'transcribe\' test - google', async(t) => {
|
|||||||
// THEN
|
// THEN
|
||||||
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
||||||
'transcribe: succeeds when using google credentials');
|
'transcribe: succeeds when using google credentials');
|
||||||
|
|
||||||
@@ -89,6 +90,7 @@ test('\'transcribe\' test - microsoft', async(t) => {
|
|||||||
// THEN
|
// THEN
|
||||||
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
||||||
'transcribe: succeeds when using microsoft credentials');
|
'transcribe: succeeds when using microsoft credentials');
|
||||||
|
|
||||||
@@ -126,6 +128,7 @@ test('\'transcribe\' test - aws', async(t) => {
|
|||||||
// THEN
|
// THEN
|
||||||
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
||||||
'transcribe: succeeds when using aws credentials');
|
'transcribe: succeeds when using aws credentials');
|
||||||
|
|
||||||
@@ -137,6 +140,71 @@ test('\'transcribe\' test - aws', async(t) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
test('\'transcribe\' test - deepgram config options', async(t) => {
|
||||||
|
if (!DEEPGRAM_API_KEY ) {
|
||||||
|
t.pass('skipping deepgram tests');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
clearModule.all();
|
||||||
|
const {srf, disconnect} = require('../app');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
// GIVEN
|
||||||
|
let verbs = [
|
||||||
|
{
|
||||||
|
"verb": "config",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"language": "en-US",
|
||||||
|
"altLanguages": [
|
||||||
|
"en-US"
|
||||||
|
],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"model": "2-ea",
|
||||||
|
"tier": "nova",
|
||||||
|
"numerals": true,
|
||||||
|
"ner": true,
|
||||||
|
"vadTurnoff": 10,
|
||||||
|
"keywords": [
|
||||||
|
"CPT"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verb": "transcribe",
|
||||||
|
"transcriptionHook": "/transcriptionHook",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"altLanguages": [
|
||||||
|
"en-AU"
|
||||||
|
],
|
||||||
|
"hints": ["customer support", "sales", "human resources", "HR"],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"apiKey": DEEPGRAM_API_KEY,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
let from = "gather_success";
|
||||||
|
await provisionCallHook(from, verbs);
|
||||||
|
// THEN
|
||||||
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().includes('like to speak to customer support'),
|
||||||
|
'transcribe: succeeds when using deepgram credentials');
|
||||||
|
|
||||||
|
disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
disconnect();
|
||||||
|
t.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
test('\'transcribe\' test - deepgram', async(t) => {
|
test('\'transcribe\' test - deepgram', async(t) => {
|
||||||
if (!DEEPGRAM_API_KEY ) {
|
if (!DEEPGRAM_API_KEY ) {
|
||||||
t.pass('skipping deepgram tests');
|
t.pass('skipping deepgram tests');
|
||||||
@@ -166,6 +234,7 @@ test('\'transcribe\' test - deepgram', async(t) => {
|
|||||||
// THEN
|
// THEN
|
||||||
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().includes('like to speak to customer support'),
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().includes('like to speak to customer support'),
|
||||||
'transcribe: succeeds when using deepgram credentials');
|
'transcribe: succeeds when using deepgram credentials');
|
||||||
|
|
||||||
@@ -245,9 +314,131 @@ test('\'transcribe\' test - google with asrTimeout', async(t) => {
|
|||||||
// THEN
|
// THEN
|
||||||
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().startsWith('i\'d like to speak to customer support'),
|
||||||
'transcribe: succeeds when using google credentials');
|
'transcribe: succeeds when using google credentials');
|
||||||
|
|
||||||
|
disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
disconnect();
|
||||||
|
t.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('\'transcribe\' test - deepgram config options altLanguages', async(t) => {
|
||||||
|
if (!DEEPGRAM_API_KEY ) {
|
||||||
|
t.pass('skipping deepgram tests');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
clearModule.all();
|
||||||
|
const {srf, disconnect} = require('../app');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
// GIVEN
|
||||||
|
let verbs = [
|
||||||
|
{
|
||||||
|
"verb": "config",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"language": "en-US",
|
||||||
|
"altLanguages": [
|
||||||
|
"en-US"
|
||||||
|
],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"model": "nova-2",
|
||||||
|
"numerals": true,
|
||||||
|
"ner": true,
|
||||||
|
"vadTurnoff": 10,
|
||||||
|
"keywords": [
|
||||||
|
"CPT"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verb": "transcribe",
|
||||||
|
"transcriptionHook": "/transcriptionHook",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"hints": ["customer support", "sales", "human resources", "HR"],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"apiKey": DEEPGRAM_API_KEY,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
let from = "gather_success_no_altLanguages";
|
||||||
|
await provisionCallHook(from, verbs);
|
||||||
|
// THEN
|
||||||
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().includes('like to speak to customer support'),
|
||||||
|
'transcribe: succeeds when using deepgram credentials');
|
||||||
|
|
||||||
|
disconnect();
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error received: ${err}`);
|
||||||
|
disconnect();
|
||||||
|
t.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('\'transcribe\' test - deepgram config options altLanguages', async(t) => {
|
||||||
|
if (!DEEPGRAM_API_KEY ) {
|
||||||
|
t.pass('skipping deepgram tests');
|
||||||
|
return t.end();
|
||||||
|
}
|
||||||
|
clearModule.all();
|
||||||
|
const {srf, disconnect} = require('../app');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await connect(srf);
|
||||||
|
// GIVEN
|
||||||
|
let verbs = [
|
||||||
|
{
|
||||||
|
"verb": "config",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"language": "en-US",
|
||||||
|
"altLanguages": [
|
||||||
|
"en-US"
|
||||||
|
],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"model": "nova-2",
|
||||||
|
"numerals": true,
|
||||||
|
"ner": true,
|
||||||
|
"vadTurnoff": 10,
|
||||||
|
"keywords": [
|
||||||
|
"CPT"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"verb": "transcribe",
|
||||||
|
"transcriptionHook": "/transcriptionHook",
|
||||||
|
"recognizer": {
|
||||||
|
"vendor": "deepgram",
|
||||||
|
"hints": ["customer support", "sales", "human resources", "HR"],
|
||||||
|
"altLanguages": [],
|
||||||
|
"deepgramOptions": {
|
||||||
|
"apiKey": DEEPGRAM_API_KEY,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
let from = "gather_success_has_altLanguages";
|
||||||
|
await provisionCallHook(from, verbs);
|
||||||
|
// THEN
|
||||||
|
await sippUac('uac-gather-account-creds-success.xml', '172.38.0.10', from);
|
||||||
|
let obj = await getJSON(`http://127.0.0.1:3100/lastRequest/${from}_actionHook`);
|
||||||
|
//console.log(JSON.stringify(obj));
|
||||||
|
t.ok(obj.body.speech.alternatives[0].transcript.toLowerCase().includes('like to speak to customer support'),
|
||||||
|
'transcribe: succeeds when using deepgram credentials');
|
||||||
|
|
||||||
disconnect();
|
disconnect();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(`error received: ${err}`);
|
console.log(`error received: ${err}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user