diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index df421893..c3e6bdec 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -515,10 +515,6 @@ class TaskGather extends Task { /* count words for bargein feature */ const words = evt.alternatives[0].transcript.split(' ').length; - const bufferedWords = this._bufferedTranscripts.reduce((count, e) => { - return count + e.alternatives[0].transcript.split(' ').length; - }, 0); - if (evt.is_final) { if (evt.alternatives[0].transcript === '' && !this.callSession.callGone && !this.killed) { if ('microsoft' === this.vendor && finished === 'true') { @@ -549,14 +545,14 @@ class TaskGather extends Task { return this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout'); } this._startAsrTimer(); - return this._startTranscribing(ep); + if ('microsoft' !== this.vendor) this._startTranscribing(ep); + return; } else { - if (this.bargein && (words + bufferedWords) < this.minBargeinWordCount) { - this.logger.debug({evt, words, bufferedWords}, - 'TaskGather:_onTranscription - final transcript but < min barge words'); - this._bufferedTranscripts.push(evt); - this._startTranscribing(ep); + if (this.bargein && words < this.minBargeinWordCount) { + this.logger.debug({evt}, + `TaskGather:_onTranscription - got ${words} but minBargein is ${this.minBargeinWordCount}; discarding`); + if ('microsoft' !== this.vendor) this._startTranscribing(ep); return; } else { @@ -570,9 +566,9 @@ class TaskGather extends Task { others do not. */ //const isStableEnough = typeof evt.stability === 'undefined' || evt.stability > GATHER_STABILITY_THRESHOLD; - if (this.bargein && (words + bufferedWords) >= this.minBargeinWordCount) { + if (this.bargein && words >= this.minBargeinWordCount) { if (!this.playComplete) { - this.logger.debug({transcript: evt.alternatives[0].transcript}, 'killing audio due to speech'); + this.logger.debug({transcript: evt.alternatives[0].transcript}, 'killing audio due to minBargein words'); this.emit('vad'); } this._killAudio(cs);