mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2026-01-25 02:07:56 +00:00
Compare commits
20 Commits
logging
...
v0.9.5-rc1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d2d3b4583e | ||
|
|
854c26db11 | ||
|
|
e77666a1a7 | ||
|
|
5acb19225b | ||
|
|
1d6f84c2d7 | ||
|
|
de9b970a93 | ||
|
|
ec786ef1dd | ||
|
|
a95a6d1683 | ||
|
|
65b3066866 | ||
|
|
057f52e56c | ||
|
|
b46be57eba | ||
|
|
f950d19d1c | ||
|
|
859132bb1c | ||
|
|
acaadceaa2 | ||
|
|
add8d63e8e | ||
|
|
a05b72a420 | ||
|
|
28ff85225f | ||
|
|
f2fe7c4d24 | ||
|
|
97408c7d3b | ||
|
|
db5f0a0dce |
6
app.js
6
app.js
@@ -29,6 +29,12 @@ const {LifeCycleEvents, FS_UUID_SET_NAME, SystemState, FEATURE_SERVER} = require
|
||||
const installSrfLocals = require('./lib/utils/install-srf-locals');
|
||||
const createHttpListener = require('./lib/utils/http-listener');
|
||||
const healthCheck = require('@jambonz/http-health-check');
|
||||
const ProcessMonitor = require('./lib/utils/process-monitor');
|
||||
const monitor = new ProcessMonitor(logger);
|
||||
|
||||
// Log startup
|
||||
monitor.logStartup();
|
||||
monitor.setupSignalHandlers();
|
||||
|
||||
logger.on('level-change', (lvl, _val, prevLvl, _prevVal, instance) => {
|
||||
if (logger !== instance) {
|
||||
|
||||
@@ -174,5 +174,61 @@
|
||||
"non è raggiungibile",
|
||||
"lascia pure un messaggio",
|
||||
"puoi lasciare un messaggio"
|
||||
],
|
||||
"ja-JP": [
|
||||
"この通話は留守番電話に転送されました",
|
||||
"発信先は現在電話に出ることができません",
|
||||
"発信音の後でメッセージを録音してください",
|
||||
"録音を完了したら電話を切ることができます",
|
||||
"只今電話に出ることができません",
|
||||
"ただ今電話に出ることができません",
|
||||
"ただいま電話に出ることができません",
|
||||
"ピーという発信音の後にお名前とご用件をお話しください",
|
||||
"ファックスを送られる方はスタートボタンを押してください",
|
||||
"FAXを送られる方はスタートボタンを押してください",
|
||||
"おかけになった電話をお呼びしましたが",
|
||||
"お出になりません",
|
||||
"おでになりません",
|
||||
"お掛けになった電話番号は",
|
||||
"おかけになった電話番号は",
|
||||
"お掛けになった電話は",
|
||||
"おかけになった電話は",
|
||||
"現在使われておりません",
|
||||
"番号をお確かめになって",
|
||||
"お掛け直し下さい",
|
||||
"おかけ直し下さい",
|
||||
"おかけ直しください",
|
||||
"こちらはNTTドコモです",
|
||||
"こちらはエーユーです",
|
||||
"こちらはソフトバンクです",
|
||||
"電波の届かない",
|
||||
"電源が入っていない",
|
||||
"掛かりません",
|
||||
"かかりません",
|
||||
"お繋ぎすることが出来ません",
|
||||
"お繋ぎ出来ません",
|
||||
"お繋ぎすることができません",
|
||||
"お繋ぎできません",
|
||||
"おつなぎすることができません",
|
||||
"おつなぎできません",
|
||||
"メッセージを録音",
|
||||
"留守番電話",
|
||||
"お留守番サービス",
|
||||
"留守番",
|
||||
"留守電",
|
||||
"留守",
|
||||
"接続します",
|
||||
"合図の音",
|
||||
"ピーと",
|
||||
"発信音",
|
||||
"ご用件",
|
||||
"伝言",
|
||||
"お話しください",
|
||||
"ファックス",
|
||||
"FAX",
|
||||
"終了",
|
||||
"終了しました",
|
||||
"終了いたしました",
|
||||
"営業時間"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ router.post('/',
|
||||
|
||||
// find handling sbc sip for called user
|
||||
if (JAMBONES_DIAL_SBC_FOR_REGISTERED_USER && target.type === 'user') {
|
||||
const { registrar } = srf.locals.dbHelpers;
|
||||
const { registrar} = srf.locals.dbHelpers;
|
||||
const reg = await registrar.query(target.name);
|
||||
if (reg) {
|
||||
sbcAddress = selectHostPort(logger, reg.sbcAddress, 'tcp')[1];
|
||||
@@ -159,7 +159,9 @@ router.post('/',
|
||||
* trunk isn't specified,
|
||||
* check if from-number matches any existing numbers on Jambonz
|
||||
* */
|
||||
if (target.type === 'phone' && !target.trunk) {
|
||||
const { lookupLcrByAccount} = srf.locals.dbHelpers;
|
||||
const lcrs = await lookupLcrByAccount(req.body.account_sid);
|
||||
if (target.type === 'phone' && !target.trunk && lcrs.length == 0) {
|
||||
const str = restDial.from || '';
|
||||
const callingNumber = str.startsWith('+') ? str.substring(1) : str;
|
||||
const voip_carrier_sid = await lookupCarrierByPhoneNumber(req.body.account_sid, callingNumber);
|
||||
|
||||
@@ -710,7 +710,7 @@ class CallSession extends Emitter {
|
||||
}
|
||||
|
||||
|
||||
hasGlobalSttPunctuation() {
|
||||
get hasGlobalSttPunctuation() {
|
||||
return this._globalSttPunctuation !== undefined;
|
||||
}
|
||||
|
||||
@@ -1017,8 +1017,6 @@ class CallSession extends Emitter {
|
||||
(type === 'tts' && credential.use_for_tts) ||
|
||||
(type === 'stt' && credential.use_for_stt)
|
||||
)) {
|
||||
this.logger.debug(
|
||||
`${type}: ${credential.vendor} ${credential.label ? `, label: ${credential.label}` : ''} `);
|
||||
if ('google' === vendor) {
|
||||
if (type === 'tts' && !credential.tts_tested_ok ||
|
||||
type === 'stt' && !credential.stt_tested_ok) {
|
||||
@@ -1167,7 +1165,7 @@ class CallSession extends Emitter {
|
||||
service_version: credential.service_version
|
||||
};
|
||||
}
|
||||
else if ('deepgramriver' === vendor) {
|
||||
else if ('deepgramflux' === vendor) {
|
||||
return {
|
||||
speech_credential_sid: credential.speech_credential_sid,
|
||||
api_key: credential.api_key,
|
||||
@@ -1417,7 +1415,11 @@ class CallSession extends Emitter {
|
||||
}
|
||||
else {
|
||||
if (this.req && !this.dlg) {
|
||||
this.req.cancel();
|
||||
try {
|
||||
this.req.cancel();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'CallSession:_lccCallStatus error cancelling request');
|
||||
}
|
||||
this._callReleased();
|
||||
}
|
||||
}
|
||||
@@ -1864,7 +1866,7 @@ Duration=${duration} `
|
||||
return;
|
||||
}
|
||||
else if (tokens === undefined) {
|
||||
this.logger.info({opts}, 'CallSession:_lccTtsTokens - invalid command since id is missing');
|
||||
this.logger.info({opts}, 'CallSession:_lccTtsTokens - invalid command since tokens is missing');
|
||||
return this.requestor.request('tts:tokens-result', '/tokens-result', {
|
||||
id,
|
||||
status: 'failed',
|
||||
@@ -2683,7 +2685,7 @@ Duration=${duration} `
|
||||
*/
|
||||
_onRefer(req, res) {
|
||||
const task = this.currentTask;
|
||||
const sd = task.sd;
|
||||
const sd = task?.sd;
|
||||
if (task && TaskName.Dial === task.name && sd && task.referHook) {
|
||||
task.handleRefer(this, req, res);
|
||||
}
|
||||
@@ -3082,7 +3084,7 @@ Duration=${duration} `
|
||||
task.notifyTtsStreamIsEmpty();
|
||||
} else if (
|
||||
// If Gather nested say task is streaming
|
||||
TaskName.Gather === task.name && task.sayTask && task.sayTask.isStreamingTts) {
|
||||
task && TaskName.Gather === task.name && task.sayTask && task.sayTask.isStreamingTts) {
|
||||
const sayTask = task.sayTask;
|
||||
sayTask.notifyTtsStreamIsEmpty();
|
||||
}
|
||||
|
||||
@@ -641,7 +641,9 @@ class TaskDial extends Task {
|
||||
* trunk isn't specified,
|
||||
* check if number matches any existing numbers
|
||||
* */
|
||||
if (t.type === 'phone' && !t.trunk) {
|
||||
const { lookupLcrByAccount} = srf.locals.dbHelpers;
|
||||
const lcrs = await lookupLcrByAccount(cs.accountSid);
|
||||
if (t.type === 'phone' && !t.trunk && lcrs.length == 0) {
|
||||
const str = this.callerId || req.callingNumber || '';
|
||||
const callingNumber = str.startsWith('+') ? str.substring(1) : str;
|
||||
const voip_carrier_sid = await lookupCarrierByPhoneNumber(cs.accountSid, callingNumber);
|
||||
@@ -674,7 +676,8 @@ class TaskDial extends Task {
|
||||
rootSpan: cs.rootSpan,
|
||||
startSpan: this.startSpan.bind(this),
|
||||
dialTask: this,
|
||||
onHoldMusic: this.cs.onHoldMusic
|
||||
onHoldMusic: this.cs.onHoldMusic,
|
||||
tmpFiles: this.cs.tmpFiles,
|
||||
});
|
||||
this.dials.set(sd.callSid, sd);
|
||||
|
||||
@@ -775,6 +778,9 @@ class TaskDial extends Task {
|
||||
this.epOther.api('uuid_break', this.epOther.uuid);
|
||||
this.epOther.bridge(sd.ep);
|
||||
}
|
||||
else {
|
||||
this.logger.error('Dial:_connectSingleDial - no other endpoint to bridge!');
|
||||
}
|
||||
this.bridged = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ const {
|
||||
NvidiaTranscriptionEvents,
|
||||
JambonzTranscriptionEvents,
|
||||
AssemblyAiTranscriptionEvents,
|
||||
DeepgramRiverTranscriptionEvents,
|
||||
DeepgramfluxTranscriptionEvents,
|
||||
VoxistTranscriptionEvents,
|
||||
CartesiaTranscriptionEvents,
|
||||
OpenAITranscriptionEvents,
|
||||
@@ -395,6 +395,7 @@ class TaskGather extends SttTask {
|
||||
if (this.digitBuffer.length === 0 && this.needsStt) {
|
||||
// DTMF is higher priority than STT.
|
||||
this.removeCustomEventListeners();
|
||||
this._clearAsrTimer(); //clear ASR timer as we're now using dtmf
|
||||
this._stopTranscribing(ep);
|
||||
}
|
||||
this.digitBuffer += evt.dtmf;
|
||||
@@ -409,6 +410,7 @@ class TaskGather extends SttTask {
|
||||
const ms = this.interDigitTimeout * 1000;
|
||||
this.logger.debug(`starting interdigit timer of ${ms}`);
|
||||
this.interDigitTimer = setTimeout(() => this._resolve('dtmf-interdigit-timeout'), ms);
|
||||
this._clearTimer(); //clear main timer as we're now using interdigit dtmf timer
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,16 +468,18 @@ class TaskGather extends SttTask {
|
||||
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.ConnectFailure,
|
||||
this._onVendorConnectFailure.bind(this, cs, ep));
|
||||
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
|
||||
break;
|
||||
|
||||
case 'deepgramriver':
|
||||
this.bugname = `${this.bugname_prefix}deepgramriver_transcribe`;
|
||||
case 'deepgramflux':
|
||||
this.bugname = `${this.bugname_prefix}deepgramflux_transcribe`;
|
||||
this.addCustomEventListener(
|
||||
ep, DeepgramRiverTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||
ep, DeepgramfluxTranscriptionEvents.Transcription, this._onTranscription.bind(this, cs, ep));
|
||||
this.addCustomEventListener(
|
||||
ep, DeepgramRiverTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||
this.addCustomEventListener(ep, DeepgramRiverTranscriptionEvents.ConnectFailure,
|
||||
ep, DeepgramfluxTranscriptionEvents.Connect, this._onVendorConnect.bind(this, cs, ep));
|
||||
this.addCustomEventListener(ep, DeepgramfluxTranscriptionEvents.ConnectFailure,
|
||||
this._onVendorConnectFailure.bind(this, cs, ep));
|
||||
this.addCustomEventListener(ep, DeepgramfluxTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
|
||||
break;
|
||||
|
||||
case 'soniox':
|
||||
@@ -702,8 +706,8 @@ class TaskGather extends SttTask {
|
||||
this.logger.debug(`Starting timoutTimer of ${this.timeout}ms`);
|
||||
this._clearTimer();
|
||||
this._timeoutTimer = setTimeout(() => {
|
||||
// If continuousASR in use then extend by the asr window for more transcripts.
|
||||
if (this.isContinuousAsr) this._startAsrTimer();
|
||||
if (this.interDigitTimer) return; // let the inter-digit timer complete
|
||||
else {
|
||||
this._resolve(this.digitBuffer.length >= this.minDigits ? 'dtmf-num-digits' : 'timeout');
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ class TaskLlmUltravox_S2S extends Task {
|
||||
async _onServerEvent(_ep, evt) {
|
||||
let endConversation = false;
|
||||
const type = evt.type;
|
||||
this.logger.debug({evt}, 'TaskLlmUltravox_S2S:_onServerEvent');
|
||||
//this.logger.debug({evt}, 'TaskLlmUltravox_S2S:_onServerEvent');
|
||||
|
||||
/* server errors of some sort */
|
||||
if (type === 'error') {
|
||||
|
||||
@@ -19,6 +19,7 @@ class TaskRestDial extends Task {
|
||||
this.timeout = this.data.timeout || 60;
|
||||
this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
||||
this.referHook = this.data.referHook;
|
||||
this.recentCallStatus = 0;
|
||||
|
||||
this.on('connect', this._onConnect.bind(this));
|
||||
this.on('callStatus', this._onCallStatus.bind(this));
|
||||
@@ -57,7 +58,11 @@ class TaskRestDial extends Task {
|
||||
this._clearCallTimer();
|
||||
if (this.canCancel) {
|
||||
this.canCancel = false;
|
||||
cs?.req?.cancel();
|
||||
try {
|
||||
cs?.req?.cancel();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'TaskRestDial: error cancelling call');
|
||||
}
|
||||
}
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
@@ -118,7 +123,8 @@ class TaskRestDial extends Task {
|
||||
}
|
||||
|
||||
_onCallStatus(status) {
|
||||
this.logger.debug(`CallStatus: ${status}`);
|
||||
this.logger.debug(`RestDial CallStatus: ${status}`);
|
||||
this.recentCallStatus = status;
|
||||
if (status >= 200) {
|
||||
this.canCancel = false;
|
||||
this._clearCallTimer();
|
||||
@@ -136,11 +142,16 @@ class TaskRestDial extends Task {
|
||||
}
|
||||
|
||||
_onCallTimeout() {
|
||||
this.logger.debug('TaskRestDial: timeout expired without answer, killing task');
|
||||
this.logger.debug(`TaskRestDial: timeout expired without answer, last status ${this.recentCallStatus}`);
|
||||
this.timer = null;
|
||||
if (this.canCancel) {
|
||||
if (this.canCancel && this.recentCallStatus < 200) {
|
||||
this.logger.debug('TaskRestDial: cancelling call attempt');
|
||||
this.canCancel = false;
|
||||
this.cs?.req?.cancel();
|
||||
try {
|
||||
this.cs?.req?.cancel();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'TaskRestDial: error cancelling call');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,28 @@ const pollySSMLSplit = require('polly-ssml-split');
|
||||
const { SpeechCredentialError } = require('../utils/error');
|
||||
const { sleepFor } = require('../utils/helpers');
|
||||
|
||||
/**
|
||||
* Discard unmatching responses:
|
||||
* (1) I sent a playback id but get a response with a different playback id
|
||||
* (2) I sent a playback id but get a response with no playback id
|
||||
* (3) I did not send a playback id but get a response with a playback id
|
||||
* (4) I sent a cache file but get a response with a different cache file
|
||||
*/
|
||||
|
||||
const isMatchingEvent = (logger, filename, playbackId, evt) => {
|
||||
|
||||
if (!!playbackId && !!evt.variable_tts_playback_id && evt.variable_tts_playback_id === playbackId) {
|
||||
//logger.debug({filename, playbackId, evt}, 'Say:isMatchingEvent - playbackId matched');
|
||||
return true;
|
||||
}
|
||||
if (!!filename && !!evt.file && evt.file === filename) {
|
||||
//logger.debug({filename, playbackId, evt}, 'Say:isMatchingEvent - filename matched');
|
||||
return true;
|
||||
}
|
||||
logger.info({filename, playbackId, evt}, 'Say:isMatchingEvent - no match');
|
||||
return false;
|
||||
};
|
||||
|
||||
const breakLengthyTextIfNeeded = (logger, text) => {
|
||||
// As The text can be used for tts streaming, we need to break lengthy text into smaller chunks
|
||||
// HIGH_WATER_BUFFER_SIZE defined in tts-streaming-buffer.js
|
||||
@@ -259,40 +281,32 @@ class TaskSay extends TtsTask {
|
||||
while (!this.killed && (this.loop === 'forever' || this.loop--) && ep?.connected) {
|
||||
let segment = 0;
|
||||
while (!this.killed && segment < filepath.length) {
|
||||
const filename = filepath[segment];
|
||||
if (cs.isInConference) {
|
||||
const {memberId, confName, confUuid} = cs;
|
||||
await this.playToConfMember(ep, memberId, confName, confUuid, filepath[segment]);
|
||||
await this.playToConfMember(ep, memberId, confName, confUuid, filename);
|
||||
}
|
||||
else {
|
||||
let playbackId;
|
||||
const isStreaming = filepath[segment].startsWith('say:{');
|
||||
const isStreaming = filename.startsWith('say:{');
|
||||
if (isStreaming) {
|
||||
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)}`);
|
||||
const arr = /^say:\{.*\}\s*(.*)$/.exec(filename);
|
||||
if (arr) this.logger.debug(`Say:exec sending streaming tts request ${arr[1].substring(0, 64)}..`);
|
||||
else this.logger.debug(`Say:exec sending ${filename.substring(0, 64)}`);
|
||||
}
|
||||
|
||||
const onPlaybackStop = (evt) => {
|
||||
try {
|
||||
this.logger.debug({evt},
|
||||
`Say got playback-stop ${evt.variable_tts_playback_id ? evt.variable_tts_playback_id : ''}`);
|
||||
|
||||
/**
|
||||
* If we got a playback id on both the start and stop events, and they don't match,
|
||||
* then we must have received a playback-stop event for an earlier play request.
|
||||
*/
|
||||
const unmatchedResponse = (!!playbackId && !!evt.variable_tts_playback_id) &&
|
||||
evt.variable_tts_playback_id !== playbackId;
|
||||
if (unmatchedResponse) {
|
||||
this.logger.info({currentPlaybackId: playbackId, stopPPlaybackId: evt.variable_tts_playback_id},
|
||||
const playbackId = this.getPlaybackId(segment);
|
||||
const isMatch = isMatchingEvent(this.logger, filename, playbackId, evt);
|
||||
if (!isMatch) {
|
||||
this.logger.info({currentPlaybackId: playbackId, stopPlaybackId: evt.variable_tts_playback_id},
|
||||
'Say:exec discarding playback-stop for earlier play');
|
||||
ep.once('playback-stop', this._boundOnPlaybackStop);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.logger.debug({evt},
|
||||
`Say got playback-stop ${evt.variable_tts_playback_id ? evt.variable_tts_playback_id : ''}`);
|
||||
this.notifyStatus({event: 'stop-playback'});
|
||||
this.notifiedPlayBackStop = true;
|
||||
const tts_error = evt.variable_tts_error;
|
||||
@@ -331,6 +345,7 @@ class TaskSay extends TtsTask {
|
||||
!this.disableTtsCache
|
||||
) {
|
||||
const text = parseTextFromSayString(this.text[segment]);
|
||||
this.logger.debug({text, cacheFile: evt.variable_tts_cache_filename}, 'Say:exec cache tts');
|
||||
addFileToCache(evt.variable_tts_cache_filename, {
|
||||
account_sid,
|
||||
vendor,
|
||||
@@ -358,9 +373,17 @@ class TaskSay extends TtsTask {
|
||||
};
|
||||
this._boundOnPlaybackStop = onPlaybackStop.bind(this);
|
||||
|
||||
ep.once('playback-start', (evt) => {
|
||||
const onPlaybackStart = (evt) => {
|
||||
try {
|
||||
playbackId = evt.variable_tts_playback_id;
|
||||
const playbackId = this.getPlaybackId(segment);
|
||||
const isMatch = isMatchingEvent(this.logger, filename, playbackId, evt);
|
||||
if (!isMatch) {
|
||||
this.logger.info({currentPlaybackId: playbackId, startPlaybackId: evt.variable_tts_playback_id},
|
||||
'Say:exec playback-start - unmatched playback_id');
|
||||
ep.once('playback-start', this._boundOnPlaybackStart);
|
||||
return;
|
||||
}
|
||||
ep.once('playback-stop', this._boundOnPlaybackStop);
|
||||
this.logger.debug({evt},
|
||||
`Say got playback-start ${evt.variable_tts_playback_id ? evt.variable_tts_playback_id : ''}`);
|
||||
if (this.otelSpan) {
|
||||
@@ -374,16 +397,21 @@ class TaskSay extends TtsTask {
|
||||
} catch (err) {
|
||||
this.logger.info({err}, 'Error handling playback-start event');
|
||||
}
|
||||
});
|
||||
ep.once('playback-stop', this._boundOnPlaybackStop);
|
||||
};
|
||||
this._boundOnPlaybackStart = onPlaybackStart.bind(this);
|
||||
|
||||
ep.once('playback-start', this._boundOnPlaybackStart);
|
||||
|
||||
// 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;
|
||||
});
|
||||
const r = await ep.play(filepath[segment]);
|
||||
const r = await ep.play(filename);
|
||||
this.logger.debug({r}, 'Say:exec play result');
|
||||
if (r.playbackSeconds == null && r.playbackMilliseconds == null && r.playbackLastOffsetPos == null) {
|
||||
this._playReject(new Error('Playback failed to start'));
|
||||
}
|
||||
try {
|
||||
// wait for playback-stop event received to confirm if the playback is successful
|
||||
await this._playPromise;
|
||||
@@ -400,12 +428,12 @@ class TaskSay extends TtsTask {
|
||||
this._playResolve = null;
|
||||
this._playReject = null;
|
||||
}
|
||||
if (filepath[segment].startsWith('say:{')) {
|
||||
const arr = /^say:\{.*\}\s*(.*)$/.exec(filepath[segment]);
|
||||
if (filename.startsWith('say:{')) {
|
||||
const arr = /^say:\{.*\}\s*(.*)$/.exec(filename);
|
||||
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]}`);
|
||||
this.logger.debug(`Say:exec completed play file ${filename}`);
|
||||
}
|
||||
}
|
||||
segment++;
|
||||
|
||||
@@ -6,7 +6,7 @@ const {
|
||||
AwsTranscriptionEvents,
|
||||
AzureTranscriptionEvents,
|
||||
DeepgramTranscriptionEvents,
|
||||
DeepgramRiverTranscriptionEvents,
|
||||
DeepgramfluxTranscriptionEvents,
|
||||
SonioxTranscriptionEvents,
|
||||
CobaltTranscriptionEvents,
|
||||
IbmTranscriptionEvents,
|
||||
@@ -237,19 +237,23 @@ class TaskTranscribe extends SttTask {
|
||||
this._onVendorConnect.bind(this, cs, ep));
|
||||
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.ConnectFailure,
|
||||
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
||||
this.addCustomEventListener(ep, DeepgramTranscriptionEvents.Error, this._onVendorError.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;
|
||||
case 'deepgramriver':
|
||||
this.bugname = `${this.bugname_prefix}deepgramriver_transcribe`;
|
||||
this.addCustomEventListener(ep, DeepgramRiverTranscriptionEvents.Transcription,
|
||||
case 'deepgramflux':
|
||||
this.bugname = `${this.bugname_prefix}deepgramflux_transcribe`;
|
||||
this.addCustomEventListener(ep, DeepgramfluxTranscriptionEvents.Transcription,
|
||||
this._onTranscription.bind(this, cs, ep, channel));
|
||||
this.addCustomEventListener(ep, DeepgramRiverTranscriptionEvents.Connect,
|
||||
this.addCustomEventListener(ep, DeepgramfluxTranscriptionEvents.Connect,
|
||||
this._onVendorConnect.bind(this, cs, ep));
|
||||
this.addCustomEventListener(ep, DeepgramRiverTranscriptionEvents.ConnectFailure,
|
||||
this.addCustomEventListener(ep, DeepgramfluxTranscriptionEvents.ConnectFailure,
|
||||
this._onVendorConnectFailure.bind(this, cs, ep, channel));
|
||||
this.addCustomEventListener(ep, DeepgramfluxTranscriptionEvents.Error, this._onVendorError.bind(this, cs, ep));
|
||||
|
||||
break;
|
||||
case 'soniox':
|
||||
this.bugname = `${this.bugname_prefix}soniox_transcribe`;
|
||||
|
||||
@@ -3,6 +3,16 @@ const { TaskPreconditions } = require('../utils/constants');
|
||||
const { SpeechCredentialError } = require('../utils/error');
|
||||
const dbUtils = require('../utils/db-utils');
|
||||
|
||||
const extractPlaybackId = (str) => {
|
||||
// Match say:{...} and capture the content inside braces
|
||||
const match = str.match(/say:\{([^}]*)\}/);
|
||||
if (!match) return null;
|
||||
|
||||
// Look for playback_id=value within the captured content
|
||||
const playbackMatch = match[1].match(/playback_id=([^,]*)/);
|
||||
return playbackMatch ? playbackMatch[1] : null;
|
||||
};
|
||||
|
||||
class TtsTask extends Task {
|
||||
|
||||
constructor(logger, data, parentTask) {
|
||||
@@ -22,6 +32,11 @@ class TtsTask extends Task {
|
||||
this.disableTtsCache = this.data.disableTtsCache;
|
||||
this.options = this.synthesizer.options || {};
|
||||
this.instructions = this.data.instructions;
|
||||
this.playbackIds = [];
|
||||
}
|
||||
|
||||
getPlaybackId(offset) {
|
||||
return this.playbackIds[offset];
|
||||
}
|
||||
|
||||
async exec(cs) {
|
||||
@@ -69,8 +84,7 @@ class TtsTask extends Task {
|
||||
const {api_key, model_id, custom_tts_streaming_url, auth_token} = credentials;
|
||||
let obj;
|
||||
|
||||
this.logger.debug({credentials},
|
||||
`setTtsStreamingChannelVars: vendor: ${vendor}, language: ${language}, voice: ${voice}`);
|
||||
this.logger.debug(`setTtsStreamingChannelVars: vendor: ${vendor}, language: ${language}, voice: ${voice}`);
|
||||
|
||||
switch (vendor) {
|
||||
case 'deepgram':
|
||||
@@ -280,6 +294,7 @@ class TtsTask extends Task {
|
||||
renderForCaching: preCache
|
||||
});
|
||||
if (!filePath.startsWith('say:')) {
|
||||
this.playbackIds.push(null);
|
||||
this.logger.debug(`Say: file ${filePath}, served from cache ${servedFromCache}`);
|
||||
if (filePath) cs.trackTmpFile(filePath);
|
||||
if (this.otelSpan) {
|
||||
@@ -309,8 +324,16 @@ class TtsTask extends Task {
|
||||
}
|
||||
}
|
||||
else {
|
||||
this.logger.debug('Say: a streaming tts api will be used');
|
||||
this.playbackIds.push(extractPlaybackId(filePath));
|
||||
this.logger.debug({playbackIds: this.playbackIds}, 'Say: a streaming tts api will be used');
|
||||
const modifiedPath = filePath.replace('say:{', `say:{session-uuid=${ep.uuid},`);
|
||||
this.notifyStatus({
|
||||
event: 'synthesized-audio',
|
||||
vendor,
|
||||
language,
|
||||
servedFromCache,
|
||||
'id': this.id
|
||||
});
|
||||
return modifiedPath;
|
||||
}
|
||||
return filePath;
|
||||
|
||||
@@ -94,12 +94,14 @@
|
||||
"DeepgramTranscriptionEvents": {
|
||||
"Transcription": "deepgram_transcribe::transcription",
|
||||
"ConnectFailure": "deepgram_transcribe::connect_failed",
|
||||
"Connect": "deepgram_transcribe::connect"
|
||||
"Connect": "deepgram_transcribe::connect",
|
||||
"Error": "deepgram_transcribe::error"
|
||||
},
|
||||
"DeepgramRiverTranscriptionEvents": {
|
||||
"Transcription": "deepgramriver_transcribe::transcription",
|
||||
"ConnectFailure": "deepgramriver_transcribe::connect_failed",
|
||||
"Connect": "deepgramriver_transcribe::connect"
|
||||
"DeepgramfluxTranscriptionEvents": {
|
||||
"Transcription": "deepgramflux_transcribe::transcription",
|
||||
"ConnectFailure": "deepgramflux_transcribe::connect_failed",
|
||||
"Connect": "deepgramflux_transcribe::connect",
|
||||
"Error": "deepgramflux_transcribe::error"
|
||||
},
|
||||
"SonioxTranscriptionEvents": {
|
||||
"Transcription": "soniox_transcribe::transcription",
|
||||
|
||||
@@ -81,7 +81,7 @@ const speechMapper = (cred) => {
|
||||
obj.deepgram_tts_uri = o.deepgram_tts_uri;
|
||||
obj.deepgram_stt_use_tls = o.deepgram_stt_use_tls;
|
||||
}
|
||||
else if ('deepgramriver' === obj.vendor) {
|
||||
else if ('deepgramflux' === obj.vendor) {
|
||||
const o = JSON.parse(decrypt(credential));
|
||||
obj.api_key = o.api_key;
|
||||
}
|
||||
|
||||
@@ -173,7 +173,8 @@ function installSrfLocals(srf, logger, {
|
||||
lookupAccountCapacitiesBySid,
|
||||
lookupSmppGateways,
|
||||
lookupClientByAccountAndUsername,
|
||||
lookupSystemInformation
|
||||
lookupSystemInformation,
|
||||
lookupLcrByAccount
|
||||
} = require('@jambonz/db-helpers')({
|
||||
host: JAMBONES_MYSQL_HOST,
|
||||
user: JAMBONES_MYSQL_USER,
|
||||
@@ -279,7 +280,8 @@ function installSrfLocals(srf, logger, {
|
||||
retrieveByPatternSortedSet,
|
||||
sortedSetLength,
|
||||
sortedSetPositionByPattern,
|
||||
getVerbioAccessToken
|
||||
getVerbioAccessToken,
|
||||
lookupLcrByAccount
|
||||
},
|
||||
parentLogger: logger,
|
||||
getSBC,
|
||||
|
||||
@@ -20,7 +20,7 @@ const { createMediaEndpoint } = require('./media-endpoint');
|
||||
|
||||
class SingleDialer extends Emitter {
|
||||
constructor({logger, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask,
|
||||
onHoldMusic}) {
|
||||
onHoldMusic, tmpFiles}) {
|
||||
super();
|
||||
assert(target.type);
|
||||
|
||||
@@ -44,6 +44,7 @@ class SingleDialer extends Emitter {
|
||||
this.callSid = crypto.randomUUID();
|
||||
this.dialTask = dialTask;
|
||||
this.onHoldMusic = onHoldMusic;
|
||||
this.tmpFiles = tmpFiles;
|
||||
|
||||
this.on('callStatusChange', this._notifyCallStatusChange.bind(this));
|
||||
}
|
||||
@@ -328,7 +329,13 @@ class SingleDialer extends Emitter {
|
||||
*/
|
||||
async kill(Reason) {
|
||||
this.killed = true;
|
||||
if (this.inviteInProgress) await this.inviteInProgress.cancel();
|
||||
if (this.inviteInProgress) {
|
||||
try {
|
||||
await this.inviteInProgress.cancel();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'SingleDialer:kill error cancelling invite');
|
||||
}
|
||||
}
|
||||
else if (this.dlg && this.dlg.connected) {
|
||||
const duration = moment().diff(this.dlg.connectTime, 'seconds');
|
||||
this.logger.debug('SingleDialer:kill hanging up called party');
|
||||
@@ -402,7 +409,7 @@ class SingleDialer extends Emitter {
|
||||
tasks,
|
||||
rootSpan: this.rootSpan,
|
||||
req: this.req,
|
||||
tmpFiles: cs.tmpFiles,
|
||||
tmpFiles: this.tmpFiles,
|
||||
});
|
||||
await cs.exec();
|
||||
|
||||
@@ -536,12 +543,12 @@ class SingleDialer extends Emitter {
|
||||
|
||||
function placeOutdial({
|
||||
logger, srf, ms, sbcAddress, target, opts, application, callInfo, accountInfo, rootSpan, startSpan, dialTask,
|
||||
onHoldMusic
|
||||
onHoldMusic, tmpFiles
|
||||
}) {
|
||||
const myOpts = deepcopy(opts);
|
||||
const sd = new SingleDialer({
|
||||
logger, sbcAddress, target, opts: myOpts, application, callInfo,
|
||||
accountInfo, rootSpan, startSpan, dialTask, onHoldMusic
|
||||
accountInfo, rootSpan, startSpan, dialTask, onHoldMusic, tmpFiles
|
||||
});
|
||||
sd.exec(srf, ms, myOpts);
|
||||
return sd;
|
||||
|
||||
91
lib/utils/process-monitor.js
Normal file
91
lib/utils/process-monitor.js
Normal file
@@ -0,0 +1,91 @@
|
||||
// lib/utils/process-monitor.js
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
class ProcessMonitor {
|
||||
constructor(logger) {
|
||||
this.logger = logger;
|
||||
this.packageInfo = this.getPackageInfo();
|
||||
this.processName = this.packageInfo.name || 'unknown-app';
|
||||
}
|
||||
|
||||
getPackageInfo() {
|
||||
try {
|
||||
const packagePath = path.join(process.cwd(), 'package.json');
|
||||
return JSON.parse(fs.readFileSync(packagePath, 'utf8'));
|
||||
} catch (e) {
|
||||
return { name: 'unknown', version: 'unknown' };
|
||||
}
|
||||
}
|
||||
|
||||
logStartup(additionalInfo = {}) {
|
||||
const startupInfo = {
|
||||
msg: `${this.processName} started`,
|
||||
app_name: this.processName,
|
||||
app_version: this.packageInfo.version,
|
||||
pid: process.pid,
|
||||
ppid: process.ppid,
|
||||
pm2_instance_id: process.env.NODE_APP_INSTANCE || 'not_pm2',
|
||||
pm2_id: process.env.pm_id,
|
||||
is_pm2: !!process.env.PM2,
|
||||
node_version: process.version,
|
||||
uptime: process.uptime(),
|
||||
timestamp: new Date().toISOString(),
|
||||
...additionalInfo
|
||||
};
|
||||
|
||||
this.logger.info(startupInfo);
|
||||
return startupInfo;
|
||||
}
|
||||
|
||||
setupSignalHandlers() {
|
||||
// Log when we receive signals that would cause restart
|
||||
process.on('SIGINT', () => {
|
||||
this.logger.info({
|
||||
msg: 'SIGINT received',
|
||||
app_name: this.processName,
|
||||
pid: process.pid,
|
||||
ppid: process.ppid,
|
||||
uptime: process.uptime(),
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('SIGTERM', () => {
|
||||
this.logger.info({
|
||||
msg: 'SIGTERM received',
|
||||
app_name: this.processName,
|
||||
pid: process.pid,
|
||||
ppid: process.ppid,
|
||||
uptime: process.uptime(),
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
process.on('uncaughtException', (error) => {
|
||||
this.logger.error({
|
||||
msg: 'Uncaught exception - process will restart',
|
||||
app_name: this.processName,
|
||||
error: error.message,
|
||||
stack: error.stack,
|
||||
pid: process.pid,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('unhandledRejection', (reason, promise) => {
|
||||
this.logger.error({
|
||||
msg: 'Unhandled rejection',
|
||||
app_name: this.processName,
|
||||
reason,
|
||||
pid: process.pid,
|
||||
timestamp: new Date().toISOString()
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ProcessMonitor;
|
||||
@@ -339,20 +339,32 @@ const normalizeDeepgram = (evt, channel, language, shortUtterance) => {
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeDeepgramRiver = (evt, channel, language, shortUtterance) => {
|
||||
const normalizeDeepgramFlux = (evt, channel, language) => {
|
||||
const copy = JSON.parse(JSON.stringify(evt));
|
||||
|
||||
let turnTakingEvent;
|
||||
if (['StartOfTurn', 'EagerEndOfTurn', 'TurnResumed', 'EndOfTurn'].includes(evt.event)) {
|
||||
turnTakingEvent = evt.event;
|
||||
}
|
||||
|
||||
/* calculate total confidence based on word-level confidence */
|
||||
const realWords = (evt.words || [])
|
||||
.filter((w) => ![',.!?;'].includes(w.word));
|
||||
const confidence = realWords.length > 0 ? realWords.reduce((acc, w) => acc + w.confidence, 0) / realWords.length : 0;
|
||||
return {
|
||||
language_code: language,
|
||||
channel_tag: channel,
|
||||
is_final: evt.event === 'EndOfTurn',
|
||||
alternatives: [
|
||||
{
|
||||
confidence: evt.end_of_turn_confidence,
|
||||
confidence,
|
||||
end_of_turn_confidence: evt.end_of_turn_confidence,
|
||||
transcript: evt.transcript,
|
||||
...(turnTakingEvent && {turn_taking_event: turnTakingEvent})
|
||||
}
|
||||
],
|
||||
vendor: {
|
||||
name: 'deepgramriver',
|
||||
name: 'deepgramflux',
|
||||
evt: copy
|
||||
}
|
||||
};
|
||||
@@ -669,8 +681,8 @@ module.exports = (logger) => {
|
||||
switch (vendor) {
|
||||
case 'deepgram':
|
||||
return normalizeDeepgram(evt, channel, language, shortUtterance);
|
||||
case 'deepgramriver':
|
||||
return normalizeDeepgramRiver(evt, channel, language, shortUtterance);
|
||||
case 'deepgramflux':
|
||||
return normalizeDeepgramFlux(evt, channel, language, shortUtterance);
|
||||
case 'microsoft':
|
||||
return normalizeMicrosoft(evt, channel, language, punctuation);
|
||||
case 'google':
|
||||
@@ -965,19 +977,23 @@ module.exports = (logger) => {
|
||||
...(entityPrompt && {DEEPGRAM_SPEECH_ENTITY_PROMPT: entityPrompt}),
|
||||
};
|
||||
}
|
||||
else if ('deepgramriver' === vendor) {
|
||||
else if ('deepgramflux' === vendor) {
|
||||
const {
|
||||
preflightThreshold,
|
||||
eotThreshold,
|
||||
eotTimeoutMs,
|
||||
mipOptOut
|
||||
mipOptOut,
|
||||
model,
|
||||
eagerEotThreshold,
|
||||
keyterms
|
||||
} = rOpts.deepgramOptions || {};
|
||||
opts = {
|
||||
DEEPGRAM_API_KEY: sttCredentials.api_key,
|
||||
...(preflightThreshold && {DEEPGRAM_SPEECH_PRELIGHT_THRESHOLD: preflightThreshold}),
|
||||
...(eotThreshold && {DEEPGRAM_SPEECH_EOT_THRESHOLD: eotThreshold}),
|
||||
...(eotTimeoutMs && {DEEPGRAM_SPEECH_EOT_TIMEOUT_MS: eotTimeoutMs}),
|
||||
...(mipOptOut && {DEEPGRAM_SPEECH_MIP_OPT_OUT: mipOptOut}),
|
||||
DEEPGRAMFLUX_API_KEY: sttCredentials.api_key,
|
||||
DEEPGRAMFLUX_SPEECH_MODEL: model || 'flux-general-en',
|
||||
...(eotThreshold && {DEEPGRAMFLUX_SPEECH_EOT_THRESHOLD: eotThreshold}),
|
||||
...(eotTimeoutMs && {DEEPGRAMFLUX_SPEECH_EOT_TIMEOUT_MS: eotTimeoutMs}),
|
||||
...(mipOptOut && {DEEPGRAMFLUX_SPEECH_MIP_OPT_OUT: mipOptOut}),
|
||||
...(eagerEotThreshold && {DEEPGRAMFLUX_SPEECH_EAGER_EOT_THRESHOLD: eagerEotThreshold}),
|
||||
...(keyterms && keyterms.length > 0 && {DEEPGRAMFLUX_SPEECH_KEYTERMS: keyterms.join(',')}),
|
||||
};
|
||||
}
|
||||
else if ('soniox' === vendor) {
|
||||
|
||||
@@ -293,7 +293,7 @@ class WsRequestor extends BaseRequestor {
|
||||
|
||||
/* send the message */
|
||||
this.ws.send(JSON.stringify(obj), async() => {
|
||||
this.logger.debug({obj}, `WsRequestor:request websocket: sent (${url})`);
|
||||
if (obj.type !== 'llm:event') 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 {
|
||||
|
||||
5414
package-lock.json
generated
5414
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -27,14 +27,14 @@
|
||||
"dependencies": {
|
||||
"@aws-sdk/client-auto-scaling": "^3.549.0",
|
||||
"@aws-sdk/client-sns": "^3.549.0",
|
||||
"@jambonz/db-helpers": "^0.9.16",
|
||||
"@jambonz/db-helpers": "^0.9.17",
|
||||
"@jambonz/http-health-check": "^0.0.1",
|
||||
"@jambonz/mw-registrar": "^0.2.7",
|
||||
"@jambonz/realtimedb-helpers": "^0.8.15",
|
||||
"@jambonz/speech-utils": "^0.2.19",
|
||||
"@jambonz/speech-utils": "^0.2.24",
|
||||
"@jambonz/stats-collector": "^0.1.10",
|
||||
"@jambonz/time-series": "^0.2.14",
|
||||
"@jambonz/verb-specifications": "^0.0.113",
|
||||
"@jambonz/verb-specifications": "^0.0.116",
|
||||
"@modelcontextprotocol/sdk": "^1.9.0",
|
||||
"@opentelemetry/api": "^1.8.0",
|
||||
"@opentelemetry/exporter-jaeger": "^1.23.0",
|
||||
@@ -49,7 +49,7 @@
|
||||
"debug": "^4.3.4",
|
||||
"deepcopy": "^2.1.0",
|
||||
"drachtio-fsmrf": "^4.1.2",
|
||||
"drachtio-srf": "^5.0.5",
|
||||
"drachtio-srf": "^5.0.11",
|
||||
"express": "^4.19.2",
|
||||
"express-validator": "^7.0.1",
|
||||
"moment": "^2.30.1",
|
||||
|
||||
Reference in New Issue
Block a user