mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
Feature/config verb (#77)
* remove cognigy verb * initial implementation of config verb * further updates to config * Bot mode alex (#75) * do not use default as value for TTS/STT * fix gather listener if no say or play provided Co-authored-by: akirilyuk <a.kirilyuk@cognigy.com> * gather: listenDuringPrompt requires a nested play/say * fix exception * say: fix exception where caller hangs up during say * bugfix: sip refer was not ending if caller hungup during refer * add support for sip:request to ws commands * gather: when bargein is set and minBargeinWordCount is zero, kill audio on endOfUtterrance * gather/transcribe: add support for google boost and azure custom endpoints * minor logging changes * lint error Co-authored-by: akirilyuk <45361199+akirilyuk@users.noreply.github.com> Co-authored-by: akirilyuk <a.kirilyuk@cognigy.com>
This commit is contained in:
@@ -1,248 +0,0 @@
|
||||
const Task = require('./task');
|
||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||
const makeTask = require('./make_task');
|
||||
const { SocketClient } = require('@cognigy/socket-client');
|
||||
|
||||
const parseGallery = (obj = {}) => {
|
||||
const {_default} = obj;
|
||||
if (_default) {
|
||||
const {_gallery} = _default;
|
||||
if (_gallery) return _gallery.fallbackText;
|
||||
}
|
||||
};
|
||||
|
||||
const parseQuickReplies = (obj) => {
|
||||
const {_default} = obj;
|
||||
if (_default) {
|
||||
const {_quickReplies} = _default;
|
||||
if (_quickReplies) return _quickReplies.text || _quickReplies.fallbackText;
|
||||
}
|
||||
};
|
||||
|
||||
const parseBotText = (evt) => {
|
||||
const {text, data} = evt;
|
||||
if (text) return text;
|
||||
|
||||
switch (data?.type) {
|
||||
case 'quickReplies':
|
||||
return parseQuickReplies(data?._cognigy);
|
||||
case 'gallery':
|
||||
return parseGallery(data?._cognigy);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
class Cognigy extends Task {
|
||||
constructor(logger, opts) {
|
||||
super(logger, opts);
|
||||
this.preconditions = TaskPreconditions.Endpoint;
|
||||
|
||||
this.url = this.data.url;
|
||||
this.token = this.data.token;
|
||||
this.prompt = this.data.prompt;
|
||||
this.eventHook = this.data?.eventHook;
|
||||
this.actionHook = this.data?.actionHook;
|
||||
this.data = this.data.data || {};
|
||||
this.prompts = [];
|
||||
}
|
||||
|
||||
get name() { return TaskName.Cognigy; }
|
||||
|
||||
get hasReportedFinalAction() {
|
||||
return this.reportedFinalAction || this.isReplacingApplication;
|
||||
}
|
||||
|
||||
async exec(cs, ep) {
|
||||
await super.exec(cs);
|
||||
|
||||
this.ep = ep;
|
||||
try {
|
||||
/* set event handlers and start transcribing */
|
||||
this.on('transcription', this._onTranscription.bind(this, cs, ep));
|
||||
this.on('error', this._onError.bind(this, cs, ep));
|
||||
|
||||
this.transcribeTask = this._makeTranscribeTask();
|
||||
this.transcribeTask.exec(cs, ep, this)
|
||||
.catch((err) => {
|
||||
this.logger.info({err}, 'Cognigy transcribe task returned error');
|
||||
this.notifyTaskDone();
|
||||
});
|
||||
if (this.prompt) {
|
||||
this.sayTask = this._makeSayTask(this.prompt);
|
||||
this.sayTask.exec(cs, ep, this)
|
||||
.catch((err) => {
|
||||
this.logger.info({err}, 'Cognigy say task returned error');
|
||||
this.notifyTaskDone();
|
||||
});
|
||||
}
|
||||
|
||||
/* connect to the bot and send initial data */
|
||||
this.client = new SocketClient(
|
||||
this.url,
|
||||
this.token,
|
||||
{
|
||||
sessionId: cs.callSid,
|
||||
channel: 'jambonz',
|
||||
forceWebsockets: true,
|
||||
reconnection: true,
|
||||
settings: {
|
||||
enableTypingIndicator: false
|
||||
}
|
||||
}
|
||||
);
|
||||
this.client.on('output', this._onBotUtterance.bind(this, cs, ep));
|
||||
this.client.on('typingStatus', this._onBotTypingStatus.bind(this, cs, ep));
|
||||
this.client.on('error', this._onBotError.bind(this, cs, ep));
|
||||
this.client.on('finalPing', this._onBotFinalPing.bind(this, cs, ep));
|
||||
await this.client.connect();
|
||||
this.client.sendMessage('', {...this.data, ...cs.callInfo});
|
||||
|
||||
await this.awaitTaskDone();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'Cognigy error');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async kill(cs) {
|
||||
super.kill(cs);
|
||||
this.logger.debug('Cognigy:kill');
|
||||
|
||||
this.removeAllListeners();
|
||||
this.transcribeTask && this.transcribeTask.kill();
|
||||
|
||||
this.client.removeAllListeners();
|
||||
if (this.client && this.client.connected) this.client.disconnect();
|
||||
|
||||
if (!this.hasReportedFinalAction) {
|
||||
this.reportedFinalAction = true;
|
||||
this.performAction({cognigyResult: 'caller hungup'})
|
||||
.catch((err) => this.logger.info({err}, 'cognigy - error w/ action webook'));
|
||||
}
|
||||
|
||||
if (this.ep.connected) {
|
||||
await this.ep.api('uuid_break', this.ep.uuid).catch((err) => this.logger.info(err, 'Error killing audio'));
|
||||
}
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
|
||||
_makeTranscribeTask() {
|
||||
const opts = {
|
||||
recognizer: this.data.recognizer || {
|
||||
vendor: 'default',
|
||||
language: 'default',
|
||||
outputFormat: 'detailed'
|
||||
}
|
||||
};
|
||||
this.logger.debug({opts}, 'constructing a nested transcribe object');
|
||||
const transcribe = makeTask(this.logger, {transcribe: opts}, this);
|
||||
return transcribe;
|
||||
}
|
||||
|
||||
_makeSayTask(text) {
|
||||
const opts = {
|
||||
text,
|
||||
synthesizer: this.data.synthesizer ||
|
||||
{
|
||||
vendor: 'default',
|
||||
language: 'default',
|
||||
voice: 'default'
|
||||
}
|
||||
};
|
||||
this.logger.debug({opts}, 'constructing a nested say object');
|
||||
const say = makeTask(this.logger, {say: opts}, this);
|
||||
return say;
|
||||
}
|
||||
|
||||
async _onBotError(cs, ep, evt) {
|
||||
this.logger.info({evt}, 'Cognigy:_onBotError');
|
||||
this.performAction({cognigyResult: 'botError', message: evt.message });
|
||||
this.reportedFinalAction = true;
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
|
||||
async _onBotTypingStatus(cs, ep, evt) {
|
||||
this.logger.info({evt}, 'Cognigy:_onBotTypingStatus');
|
||||
}
|
||||
async _onBotFinalPing(cs, ep) {
|
||||
this.logger.info('Cognigy:_onBotFinalPing');
|
||||
if (this.prompts.length) {
|
||||
const text = this.prompts.join('.');
|
||||
this.prompts = [];
|
||||
if (text && !this.killed) {
|
||||
this.sayTask = this._makeSayTask(text);
|
||||
this.sayTask.exec(cs, ep, this)
|
||||
.catch((err) => {
|
||||
this.logger.info({err}, 'Cognigy say task returned error');
|
||||
this.notifyTaskDone();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async _onBotUtterance(cs, ep, evt) {
|
||||
this.logger.debug({evt}, 'Cognigy:_onBotUtterance');
|
||||
|
||||
if (this.eventHook) {
|
||||
this.performHook(cs, this.eventHook, {event: 'botMessage', message: evt})
|
||||
.then((redirected) => {
|
||||
if (redirected) {
|
||||
this.logger.info('Cognigy_onTranscription: event handler for bot message redirected us to new webhook');
|
||||
this.reportedFinalAction = true;
|
||||
this.performAction({cognigyResult: 'redirect'}, false);
|
||||
}
|
||||
return;
|
||||
})
|
||||
.catch(({err}) => {
|
||||
this.logger.info({err}, 'Cognigy_onTranscription: error sending event hook');
|
||||
});
|
||||
}
|
||||
const text = parseBotText(evt);
|
||||
this.prompts.push(text);
|
||||
}
|
||||
|
||||
async _onTranscription(cs, ep, evt) {
|
||||
this.logger.debug({evt}, `Cognigy: got transcription for callSid ${cs.callSid}`);
|
||||
const utterance = evt.alternatives[0].transcript;
|
||||
|
||||
if (this.eventHook) {
|
||||
this.performHook(cs, this.eventHook, {event: 'userMessage', message: utterance})
|
||||
.then((redirected) => {
|
||||
if (redirected) {
|
||||
this.logger.info('Cognigy_onTranscription: event handler for user message redirected us to new webhook');
|
||||
this.reportedFinalAction = true;
|
||||
this.performAction({cognigyResult: 'redirect'}, false);
|
||||
if (this.transcribeTask) this.transcribeTask.kill(cs);
|
||||
}
|
||||
return;
|
||||
})
|
||||
.catch(({err}) => {
|
||||
this.logger.info({err}, 'Cognigy_onTranscription: error sending event hook');
|
||||
});
|
||||
}
|
||||
|
||||
/* send the user utterance to the bot */
|
||||
try {
|
||||
if (this.client && this.client.connected) {
|
||||
this.client.sendMessage(utterance);
|
||||
}
|
||||
else {
|
||||
this.logger.info('Cognigy_onTranscription - not sending user utterance as bot is disconnected');
|
||||
}
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'Cognigy_onTranscription: Error sending user utterance to Cognigy - ending task');
|
||||
this.performAction({cognigyResult: 'socketError'});
|
||||
this.reportedFinalAction = true;
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
}
|
||||
_onError(cs, ep, err) {
|
||||
this.logger.debug({err}, 'Cognigy: got error');
|
||||
if (!this.hasReportedFinalAction) this.performAction({cognigyResult: 'error', err});
|
||||
this.reportedFinalAction = true;
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Cognigy;
|
||||
80
lib/tasks/config.js
Normal file
80
lib/tasks/config.js
Normal file
@@ -0,0 +1,80 @@
|
||||
const Task = require('./task');
|
||||
const {TaskName, TaskPreconditions} = require('../utils/constants');
|
||||
|
||||
class TaskConfig extends Task {
|
||||
constructor(logger, opts) {
|
||||
super(logger, opts);
|
||||
this.preconditions = TaskPreconditions.Endpoint;
|
||||
|
||||
[
|
||||
'synthesizer',
|
||||
'recognizer',
|
||||
'bargeIn'
|
||||
].forEach((k) => this[k] = this.data[k] || {});
|
||||
|
||||
if (this.hasBargeIn && this.bargeIn.enable === true) {
|
||||
this.gatherOpts = {
|
||||
verb: 'gather',
|
||||
timeout: 0
|
||||
};
|
||||
[
|
||||
'finishOnKey', 'input', 'numDigits', 'minDigits', 'maxDigits',
|
||||
'interDigitTimeout', 'dtmfBargein', 'actionHook'
|
||||
].forEach((k) => {
|
||||
if (this.bargeIn[k]) this.gatherOpts[k] = this.bargeIn[k];
|
||||
});
|
||||
|
||||
this.preconditions = this.hasBargeIn ? TaskPreconditions.Endpoint : TaskPreconditions.None;
|
||||
}
|
||||
}
|
||||
|
||||
get name() { return TaskName.Config; }
|
||||
|
||||
get hasSynthesizer() { return Object.keys(this.synthesizer).length; }
|
||||
|
||||
get hasRecognizer() { return Object.keys(this.recognizer).length; }
|
||||
|
||||
get hasBargeIn() { return Object.keys(this.bargeIn).length; }
|
||||
|
||||
async exec(cs) {
|
||||
await super.exec(cs);
|
||||
|
||||
if (this.hasSynthesizer) {
|
||||
cs.speechSynthesisVendor = this.synthesizer.vendor !== 'default'
|
||||
? this.synthesizer.vendor
|
||||
: cs.speechSynthesisVendor;
|
||||
cs.speechSynthesisLanguage = this.synthesizer.language !== 'default'
|
||||
? this.synthesizer.language
|
||||
: cs.speechSynthesisLanguage;
|
||||
cs.speechSynthesisVoice = this.synthesizer.voice !== 'default'
|
||||
? this.synthesizer.voice
|
||||
: cs.speechSynthesisVoice;
|
||||
this.logger.info({synthesizer: this.synthesizer}, 'Config: updated synthesizer');
|
||||
}
|
||||
if (this.hasRecognizer) {
|
||||
cs.speechRecognizerVendor = this.recognizer.vendor !== 'default'
|
||||
? this.recognizer.vendor
|
||||
: cs.speechRecognizerVendor;
|
||||
cs.speechRecognizerLanguage = this.recognizer.language !== 'default'
|
||||
? this.recognizer.language
|
||||
: cs.speechRecognizerLanguage;
|
||||
this.logger.info({recognizer: this.recognizer}, 'Config: updated recognizer');
|
||||
}
|
||||
if (this.hasBargeIn) {
|
||||
if (this.gatherOpts) {
|
||||
this.logger.debug({opts: this.gatherOpts}, 'Config: enabling bargeIn');
|
||||
cs.enableBotMode(this.gatherOpts);
|
||||
}
|
||||
else {
|
||||
this.logger.debug('Config: disabling bargeIn');
|
||||
cs.disableBotMode();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async kill(cs) {
|
||||
super.kill(cs);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TaskConfig;
|
||||
@@ -25,21 +25,23 @@ class TaskGather extends Task {
|
||||
/* when collecting dtmf, bargein on dtmf is true unless explicitly set to false */
|
||||
if (this.dtmfBargein !== false && this.input.includes('digits')) this.dtmfBargein = true;
|
||||
|
||||
this.timeout = (this.timeout || 15) * 1000;
|
||||
/* timeout of zero means no timeout */
|
||||
this.timeout = this.timeout === 0 ? 0 : (this.timeout || 15) * 1000;
|
||||
this.interim = this.partialResultHook || this.bargein;
|
||||
this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true;
|
||||
if (this.data.recognizer) {
|
||||
const recognizer = this.data.recognizer;
|
||||
this.vendor = recognizer.vendor;
|
||||
this.language = recognizer.language;
|
||||
this.hints = recognizer.hints || [];
|
||||
this.hintsBoost = recognizer.hintsBoost;
|
||||
this.altLanguages = recognizer.altLanguages || [];
|
||||
|
||||
/* vad: if provided, we dont connect to recognizer until voice activity is detected */
|
||||
const {enable, voiceMs = 0, mode = -1} = recognizer.vad || {};
|
||||
this.vad = {enable, voiceMs, mode};
|
||||
|
||||
this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true;
|
||||
this.minBargeinWordCount = this.data.minBargeinWordCount || 1;
|
||||
this.minBargeinWordCount = this.data.minBargeinWordCount || 0;
|
||||
|
||||
/* aws options */
|
||||
this.vocabularyName = recognizer.vocabularyName;
|
||||
@@ -51,6 +53,7 @@ class TaskGather extends Task {
|
||||
this.profanityOption = recognizer.profanityOption || 'raw';
|
||||
this.requestSnr = recognizer.requestSnr || false;
|
||||
this.initialSpeechTimeoutMs = recognizer.initialSpeechTimeoutMs || 0;
|
||||
this.azureServiceEndpoint = recognizer.azureServiceEndpoint;
|
||||
}
|
||||
|
||||
this.digitBuffer = '';
|
||||
@@ -58,6 +61,7 @@ class TaskGather extends Task {
|
||||
|
||||
if (this.say) this.sayTask = makeTask(this.logger, {say: this.say}, this);
|
||||
if (this.play) this.playTask = makeTask(this.logger, {play: this.play}, this);
|
||||
if (!this.sayTask && !this.playTask) this.listenDuringPrompt = false;
|
||||
|
||||
this.parentTask = parentTask;
|
||||
}
|
||||
@@ -78,7 +82,7 @@ class TaskGather extends Task {
|
||||
else s += 'inputs=speech,';
|
||||
|
||||
if (this.input.includes('speech')) {
|
||||
s += `vendor=${this.vendor},language=${this.language}`;
|
||||
s += `vendor=${this.vendor || 'default'},language=${this.language || 'default'}`;
|
||||
}
|
||||
if (this.sayTask) s += ',with nested say task';
|
||||
if (this.playTask) s += ',with nested play task';
|
||||
@@ -87,6 +91,7 @@ class TaskGather extends Task {
|
||||
}
|
||||
|
||||
async exec(cs, ep) {
|
||||
this.logger.debug('Gather:exec');
|
||||
await super.exec(cs);
|
||||
const {updateSpeechCredentialLastUsed} = require('../utils/db-utils')(this.logger, cs.srf);
|
||||
|
||||
@@ -133,7 +138,7 @@ class TaskGather extends Task {
|
||||
if (!this.killed) startListening(cs, ep);
|
||||
});
|
||||
}
|
||||
else this._startTimer();
|
||||
else startListening(cs, ep);
|
||||
|
||||
if (this.input.includes('speech') && this.listenDuringPrompt) {
|
||||
await this._initSpeech(cs, ep);
|
||||
@@ -165,6 +170,12 @@ class TaskGather extends Task {
|
||||
this._resolve('killed');
|
||||
}
|
||||
|
||||
updateTimeout(timeout) {
|
||||
this.logger.info(`TaskGather:updateTimout - updating timeout to ${timeout}`);
|
||||
this.timeout = timeout;
|
||||
this._startTimer();
|
||||
}
|
||||
|
||||
_onDtmf(cs, ep, evt) {
|
||||
this.logger.debug(evt, 'TaskGather:_onDtmf');
|
||||
clearTimeout(this.interDigitTimer);
|
||||
@@ -193,7 +204,7 @@ class TaskGather extends Task {
|
||||
async _initSpeech(cs, ep) {
|
||||
const opts = {};
|
||||
|
||||
if (this.vad.enable) {
|
||||
if (this.vad?.enable) {
|
||||
opts.START_RECOGNIZING_ON_VAD = 1;
|
||||
if (this.vad.voiceMs) opts.RECOGNIZER_VAD_VOICE_MS = this.vad.voiceMs;
|
||||
if (this.vad.mode >= 0 && this.vad.mode <= 3) opts.RECOGNIZER_VAD_MODE = this.vad.mode;
|
||||
@@ -208,6 +219,9 @@ class TaskGather extends Task {
|
||||
});
|
||||
if (this.hints && this.hints.length > 1) {
|
||||
opts.GOOGLE_SPEECH_HINTS = this.hints.map((h) => h.trim()).join(',');
|
||||
if (typeof this.hintsBoost === 'number') {
|
||||
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
||||
}
|
||||
}
|
||||
if (this.altLanguages && this.altLanguages.length > 0) {
|
||||
opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
||||
@@ -243,8 +257,9 @@ class TaskGather extends Task {
|
||||
if (this.hints && this.hints.length > 1) {
|
||||
opts.AZURE_SPEECH_HINTS = this.hints.map((h) => h.trim()).join(',');
|
||||
}
|
||||
//if (this.requestSnr) opts.AZURE_REQUEST_SNR = 1;
|
||||
//if (this.profanityOption !== 'raw') opts.AZURE_PROFANITY_OPTION = this.profanityOption;
|
||||
if (this.requestSnr) opts.AZURE_REQUEST_SNR = 1;
|
||||
if (this.profanityOption !== 'raw') opts.AZURE_PROFANITY_OPTION = this.profanityOption;
|
||||
if (this.azureServiceEndpoint) opts.AZURE_SERVICE_ENDPOINT = this.azureServiceEndpoint;
|
||||
if (this.initialSpeechTimeoutMs > 0) opts.AZURE_INITIAL_SPEECH_TIMEOUT_MS = this.initialSpeechTimeoutMs;
|
||||
opts.AZURE_USE_OUTPUT_FORMAT_DETAILED = 1;
|
||||
|
||||
@@ -256,6 +271,7 @@ class TaskGather extends Task {
|
||||
}
|
||||
|
||||
_startTranscribing(ep) {
|
||||
this.logger.debug('Gather:_startTranscribing');
|
||||
ep.startTranscription({
|
||||
vendor: this.vendor,
|
||||
locale: this.language,
|
||||
@@ -273,6 +289,7 @@ class TaskGather extends Task {
|
||||
}
|
||||
|
||||
_startTimer() {
|
||||
if (0 === this.timeout) return;
|
||||
assert(!this._timeoutTimer);
|
||||
this.logger.debug(`Gather:_startTimer: timeout ${this.timeout}`);
|
||||
this._timeoutTimer = setTimeout(() => this._resolve('timeout'), this.timeout);
|
||||
@@ -339,13 +356,17 @@ class TaskGather extends Task {
|
||||
this._killAudio(cs);
|
||||
}
|
||||
if (this.partialResultHook) {
|
||||
this.cs.requestor.request(this.partialResultHook, Object.assign({speech: evt}, this.cs.callInfo))
|
||||
.catch((err) => this.logger.info(err, 'GatherTask:_onTranscription error'));
|
||||
this.cs.requestor.request(this.partialResultHook, Object.assign({speech: evt}, this.cs.callInfo));
|
||||
}
|
||||
}
|
||||
}
|
||||
_onEndOfUtterance(cs, ep) {
|
||||
this.logger.info('TaskGather:_onEndOfUtterance');
|
||||
if (this.bargein && this.minBargeinWordCount === 0) {
|
||||
this.logger.debug('Gather:_onTranscription - killing audio due to utterance detected');
|
||||
this._killAudio(cs);
|
||||
}
|
||||
|
||||
if (!this.resolved && !this.killed) {
|
||||
this._startTranscribing(ep);
|
||||
}
|
||||
@@ -368,15 +389,25 @@ class TaskGather extends Task {
|
||||
|
||||
this._clearTimer();
|
||||
if (reason.startsWith('dtmf')) {
|
||||
await this.performAction({digits: this.digitBuffer, reason: 'dtmfDetected'});
|
||||
if (this.parentTask) this.parentTask.emit('dtmf', evt);
|
||||
else {
|
||||
this.emit('dtmf', evt);
|
||||
await this.performAction({digits: this.digitBuffer, reason: 'dtmfDetected'});
|
||||
}
|
||||
}
|
||||
else if (reason.startsWith('speech')) {
|
||||
if (this.parentTask) this.parentTask.emit('transcription', evt);
|
||||
else await this.performAction({speech: evt, reason: 'speechDetected'});
|
||||
else {
|
||||
this.emit('transcription', evt);
|
||||
await this.performAction({speech: evt, reason: 'speechDetected'});
|
||||
}
|
||||
}
|
||||
else if (reason.startsWith('timeout')) {
|
||||
if (this.parentTask) this.parentTask.emit('timeout', evt);
|
||||
else await this.performAction({reason: 'timeout'});
|
||||
else {
|
||||
this.emit('timeout', evt);
|
||||
await this.performAction({reason: 'timeout'});
|
||||
}
|
||||
}
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ function makeTask(logger, obj, parent) {
|
||||
case TaskName.SipRefer:
|
||||
const TaskSipRefer = require('./sip_refer');
|
||||
return new TaskSipRefer(logger, data, parent);
|
||||
case TaskName.Cognigy:
|
||||
const TaskCognigy = require('./cognigy');
|
||||
return new TaskCognigy(logger, data, parent);
|
||||
case TaskName.Config:
|
||||
const TaskConfig = require('./config');
|
||||
return new TaskConfig(logger, data, parent);
|
||||
case TaskName.Conference:
|
||||
const TaskConference = require('./conference');
|
||||
return new TaskConference(logger, data, parent);
|
||||
|
||||
@@ -56,6 +56,7 @@ class TaskSay extends Task {
|
||||
// synthesize all of the text elements
|
||||
let lastUpdated = false;
|
||||
const filepath = (await Promise.all(this.text.map(async(text) => {
|
||||
if (this.killed) return;
|
||||
if (text.startsWith('silence_stream://')) return text;
|
||||
const {filePath, servedFromCache} = await synthAudio(stats, {
|
||||
text,
|
||||
@@ -86,7 +87,7 @@ class TaskSay extends Task {
|
||||
|
||||
this.logger.debug({filepath}, 'synthesized files for tts');
|
||||
|
||||
while (!this.killed && (this.loop === 'forever' || this.loop--) && this.ep.connected) {
|
||||
while (!this.killed && (this.loop === 'forever' || this.loop--) && this.ep?.connected) {
|
||||
let segment = 0;
|
||||
do {
|
||||
if (cs.isInConference) {
|
||||
|
||||
@@ -21,20 +21,29 @@
|
||||
"referTo"
|
||||
]
|
||||
},
|
||||
"cognigy": {
|
||||
"config": {
|
||||
"properties": {
|
||||
"url": "string",
|
||||
"token": "string",
|
||||
"synthesizer": "#synthesizer",
|
||||
"recognizer": "#recognizer",
|
||||
"tts": "#synthesizer",
|
||||
"prompt": "string",
|
||||
"bargeIn": "#bargeIn"
|
||||
},
|
||||
"required": []
|
||||
},
|
||||
"bargeIn": {
|
||||
"properties": {
|
||||
"enable": "boolean",
|
||||
"actionHook": "object|string",
|
||||
"eventHook": "object|string",
|
||||
"data": "object"
|
||||
"input": "array",
|
||||
"finishOnKey": "string",
|
||||
"numDigits": "number",
|
||||
"minDigits": "number",
|
||||
"maxDigits": "number",
|
||||
"interDigitTimeout": "number",
|
||||
"dtmfBargein": "boolean",
|
||||
"minBargeinWordCount": "number"
|
||||
},
|
||||
"required": [
|
||||
"url",
|
||||
"token"
|
||||
"enable"
|
||||
]
|
||||
},
|
||||
"dequeue": {
|
||||
@@ -400,6 +409,7 @@
|
||||
"language": "string",
|
||||
"vad": "#vad",
|
||||
"hints": "array",
|
||||
"hintsBoost": "number",
|
||||
"altLanguages": "array",
|
||||
"profanityFilter": "boolean",
|
||||
"interim": "boolean",
|
||||
@@ -453,7 +463,8 @@
|
||||
]
|
||||
},
|
||||
"requestSnr": "boolean",
|
||||
"initialSpeechTimeoutMs": "number"
|
||||
"initialSpeechTimeoutMs": "number",
|
||||
"azureServiceEndpoint": "string"
|
||||
},
|
||||
"required": [
|
||||
"vendor"
|
||||
|
||||
@@ -28,6 +28,7 @@ class TaskTranscribe extends Task {
|
||||
|
||||
/* google-specific options */
|
||||
this.hints = recognizer.hints || [];
|
||||
this.hintsBoost = recognizer.hintsBoost;
|
||||
this.profanityFilter = recognizer.profanityFilter;
|
||||
this.punctuation = !!recognizer.punctuation;
|
||||
this.enhancedModel = !!recognizer.enhancedModel;
|
||||
@@ -50,6 +51,7 @@ class TaskTranscribe extends Task {
|
||||
this.profanityOption = recognizer.profanityOption || 'raw';
|
||||
this.requestSnr = recognizer.requestSnr || false;
|
||||
this.initialSpeechTimeoutMs = recognizer.initialSpeechTimeoutMs || 0;
|
||||
this.azureServiceEndpoint = recognizer.azureServiceEndpoint;
|
||||
}
|
||||
|
||||
get name() { return TaskName.Transcribe; }
|
||||
@@ -138,7 +140,12 @@ class TaskTranscribe extends Task {
|
||||
].forEach((arr) => {
|
||||
if (this[arr[0]]) opts[arr[1]] = true;
|
||||
});
|
||||
if (this.hints.length > 1) opts.GOOGLE_SPEECH_HINTS = this.hints.join(',');
|
||||
if (this.hints.length > 1) {
|
||||
opts.GOOGLE_SPEECH_HINTS = this.hints.join(',');
|
||||
if (typeof this.hintsBoost === 'number') {
|
||||
opts.GOOGLE_SPEECH_HINTS_BOOST = this.hintsBoost;
|
||||
}
|
||||
}
|
||||
if (this.altLanguages.length > 1) opts.GOOGLE_SPEECH_ALTERNATIVE_LANGUAGE_CODES = this.altLanguages.join(',');
|
||||
if ('unspecified' !== this.interactionType) {
|
||||
opts.GOOGLE_SPEECH_METADATA_INTERACTION_TYPE = this.interactionType;
|
||||
@@ -205,6 +212,7 @@ class TaskTranscribe extends Task {
|
||||
if (this.profanityOption !== 'raw') opts.AZURE_PROFANITY_OPTION = this.profanityOption;
|
||||
if (this.initialSpeechTimeoutMs > 0) opts.AZURE_INITIAL_SPEECH_TIMEOUT_MS = this.initialSpeechTimeoutMs;
|
||||
if (this.outputFormat !== 'simple') opts.AZURE_USE_OUTPUT_FORMAT_DETAILED = 1;
|
||||
if (this.azureServiceEndpoint) opts.AZURE_SERVICE_ENDPOINT = this.azureServiceEndpoint;
|
||||
|
||||
await ep.set(opts)
|
||||
.catch((err) => this.logger.info(err, 'TaskTranscribe:_startTranscribing with azure'));
|
||||
|
||||
Reference in New Issue
Block a user