diff --git a/lib/session/call-session.js b/lib/session/call-session.js index b679590f..6407d1cf 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -254,7 +254,7 @@ class CallSession extends Emitter { this.backgroundGatherTask && this.backgroundGatherTask.removeAllListeners(); this.backgroundGatherTask && this.backgroundGatherTask.span.end(); this.backgroundGatherTask = null; - if (autoEnable && !this.callGone) { + if (autoEnable && !this.callGone && !this._stopping) { this.logger.info('CallSession:enableBotMode: restarting background gather'); setImmediate(() => this.enableBotMode(gather, true)); } @@ -274,7 +274,7 @@ class CallSession extends Emitter { if (this.backgroundGatherTask) { try { this.backgroundGatherTask.removeAllListeners(); - this.backgroundGatherTask.kill(); + this.backgroundGatherTask.kill().catch((err) => {}); } catch (err) {} this.backgroundGatherTask = null; } @@ -422,6 +422,8 @@ class CallSession extends Emitter { // all done - cleanup this.logger.info('CallSession:exec all tasks complete'); + this._stopping = true; + this.disableBotMode(); this._onTasksDone(); this._clearResources(); diff --git a/lib/tasks/config.js b/lib/tasks/config.js index 79becf9e..4fc38371 100644 --- a/lib/tasks/config.js +++ b/lib/tasks/config.js @@ -12,11 +12,12 @@ class TaskConfig extends Task { 'bargeIn' ].forEach((k) => this[k] = this.data[k] || {}); - if (this.hasBargeIn && this.bargeIn.enable === true) { + if (this.bargeIn.enable) { this.gatherOpts = { verb: 'gather', timeout: 0, - bargein: true + bargein: true, + input: ['speech'] }; [ 'finishOnKey', 'input', 'numDigits', 'minDigits', 'maxDigits', @@ -24,9 +25,9 @@ class TaskConfig extends Task { ].forEach((k) => { if (this.bargeIn[k]) this.gatherOpts[k] = this.bargeIn[k]; }); - if (this.bargeIn.sticky) this.autoEnable = true; } - this.preconditions = this.hasBargeIn ? TaskPreconditions.Endpoint : TaskPreconditions.None; + if (this.bargeIn.sticky) this.autoEnable = true; + this.preconditions = this.bargeIn.enable ? TaskPreconditions.Endpoint : TaskPreconditions.None; } get name() { return TaskName.Config; } @@ -35,11 +36,9 @@ class TaskConfig extends Task { get hasRecognizer() { return Object.keys(this.recognizer).length; } - get hasBargeIn() { return Object.keys(this.bargeIn).length; } - get summary() { const phrase = []; - if (this.hasBargeIn) phrase.push('enable barge-in'); + if (this.bargeIn.enable) phrase.push('enable barge-in'); if (this.hasSynthesizer) { const {vendor:v, language:l, voice} = this.synthesizer; const s = `{${v},${l},${voice}}`; @@ -75,16 +74,21 @@ class TaskConfig extends Task { cs.speechRecognizerLanguage = this.recognizer.language !== 'default' ? this.recognizer.language : cs.speechRecognizerLanguage; - this.gatherOpts.recognizer = this.recognizer; this.logger.info({recognizer: this.recognizer}, 'Config: updated recognizer'); } - if (this.hasBargeIn) { + if ('enable' in this.bargeIn) { if (this.gatherOpts) { - this.logger.debug({opts: this.gatherOpts}, 'Config: enabling bargeIn'); + this.gatherOpts.recognizer = this.hasRecognizer ? + this.recognizer : + { + vendor: cs.speechRecognizerVendor, + language: cs.speechRecognizerLanguage + }; + this.logger.info({opts: this.gatherOpts}, 'Config: enabling bargeIn'); cs.enableBotMode(this.gatherOpts, this.autoEnable); } else { - this.logger.debug('Config: disabling bargeIn'); + this.logger.info('Config: disabling bargeIn'); cs.disableBotMode(); } } diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 3a932dcc..8fd2ab3e 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -236,7 +236,7 @@ class TaskGather extends Task { GOOGLE_SPEECH_USE_ENHANCED: true, GOOGLE_SPEECH_SINGLE_UTTERANCE: true, GOOGLE_SPEECH_MODEL: 'command_and_search', - GOOGLE_SPEECH_ENABLE_AUTOMATIC_PUNCTUATION: this.punctuation + GOOGLE_SPEECH_ENABLE_AUTOMATIC_PUNCTUATION: !!this.punctuation }); if (this.hints && this.hints.length > 1) { opts.GOOGLE_SPEECH_HINTS = this.hints.map((h) => h.trim()).join(','); diff --git a/lib/utils/ws-requestor.js b/lib/utils/ws-requestor.js index 9e5bbd60..46f8d0ff 100644 --- a/lib/utils/ws-requestor.js +++ b/lib/utils/ws-requestor.js @@ -258,7 +258,7 @@ class WsRequestor extends BaseRequestor { assert.ok(false, `invalid type property: ${type}`); } } catch (err) { - this.logger.info({err}, 'WsRequestor:_onMessage - invalid incoming message'); + this.logger.info({err, content}, 'WsRequestor:_onMessage - invalid incoming message'); } }