From 7188648d3b0e6709cad5e0a46ac65cabbea07c84 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 9 Mar 2022 13:34:57 -0500 Subject: [PATCH] gather/config: bargein fixes --- lib/tasks/config.js | 8 ++++---- lib/tasks/gather.js | 29 +++++++++++++++++++++-------- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/lib/tasks/config.js b/lib/tasks/config.js index 7323cb75..afb1c6d6 100644 --- a/lib/tasks/config.js +++ b/lib/tasks/config.js @@ -15,17 +15,17 @@ class TaskConfig extends Task { if (this.hasBargeIn && this.bargeIn.enable === true) { this.gatherOpts = { verb: 'gather', - timeout: 0 + timeout: 0, + bargein: true }; [ 'finishOnKey', 'input', 'numDigits', 'minDigits', 'maxDigits', - 'interDigitTimeout', 'dtmfBargein', 'actionHook' + 'interDigitTimeout', 'bargein', 'dtmfBargein', 'minBargeinWordCount', 'actionHook' ].forEach((k) => { if (this.bargeIn[k]) this.gatherOpts[k] = this.bargeIn[k]; }); - - this.preconditions = this.hasBargeIn ? TaskPreconditions.Endpoint : TaskPreconditions.None; } + this.preconditions = this.hasBargeIn ? TaskPreconditions.Endpoint : TaskPreconditions.None; } get name() { return TaskName.Config; } diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index d4488054..3a34b9b2 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -9,7 +9,7 @@ const { const makeTask = require('./make_task'); const assert = require('assert'); -const GATHER_STABILITY_THRESHOLD = Number(process.env.JAMBONZ_GATHER_STABILITY_THRESHOLD || 0.7); +//const GATHER_STABILITY_THRESHOLD = Number(process.env.JAMBONZ_GATHER_STABILITY_THRESHOLD || 0.7); class TaskGather extends Task { constructor(logger, opts, parentTask) { @@ -29,6 +29,7 @@ class TaskGather extends Task { this.timeout = this.timeout === 0 ? 0 : (this.timeout || 15) * 1000; this.interim = this.partialResultHook || this.bargein; this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true; + this.minBargeinWordCount = this.data.minBargeinWordCount || 0; if (this.data.recognizer) { const recognizer = this.data.recognizer; this.vendor = recognizer.vendor; @@ -41,8 +42,6 @@ class TaskGather extends Task { const {enable, voiceMs = 0, mode = -1} = recognizer.vad || {}; this.vad = {enable, voiceMs, mode}; - this.minBargeinWordCount = this.data.minBargeinWordCount || 0; - /* aws options */ this.vocabularyName = recognizer.vocabularyName; this.vocabularyFilterName = recognizer.vocabularyFilterName; @@ -271,7 +270,11 @@ class TaskGather extends Task { } _startTranscribing(ep) { - this.logger.debug('Gather:_startTranscribing'); + this.logger.debug({ + vendor: this.vendor, + locale: this.language, + interim: this.interim + }, 'Gather:_startTranscribing'); ep.startTranscription({ vendor: this.vendor, locale: this.language, @@ -303,6 +306,15 @@ class TaskGather extends Task { } _killAudio(cs) { + if (!this.sayTask && !this.playTask && this.bargein) { + if (this.ep?.connected && !this.playComplete) { + this.logger.debug('Gather:_killAudio: killing playback of any audio'); + this.playComplete = true; + this.ep.api('uuid_break', this.ep.uuid) + .catch((err) => this.logger.info(err, 'Error killing audio')); + } + return; + } if (this.sayTask && !this.sayTask.killed) { this.sayTask.removeAllListeners('playDone'); this.sayTask.kill(cs); @@ -348,11 +360,13 @@ class TaskGather extends Task { https://cloud.google.com/speech-to-text/docs/basics#streaming_responses others do not. */ - const isStableEnough = typeof evt.stability === 'undefined' || evt.stability > GATHER_STABILITY_THRESHOLD; + //const isStableEnough = typeof evt.stability === 'undefined' || evt.stability > GATHER_STABILITY_THRESHOLD; - if (this.bargein && isStableEnough && + if (this.bargein && /* isStableEnough && */ evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) { - this.logger.debug('Gather:_onTranscription - killing audio due to speech bargein'); + if (!this.playComplete) { + this.logger.debug({transcript: evt.alternatives[0].transcript}, 'killing audio due to speech'); + } this._killAudio(cs); } if (this.partialResultHook) { @@ -363,7 +377,6 @@ class TaskGather extends Task { _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); }