From 1bca165fc10c45a1659aecfb1a1341393844e6fa Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 24 Jan 2022 15:04:50 -0500 Subject: [PATCH] bugfix: handle interim results from azure --- lib/tasks/gather.js | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 34406bab..a7e56686 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -22,7 +22,7 @@ class TaskGather extends Task { ].forEach((k) => this[k] = this.data[k]); this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true; this.minBargeinWordCount = this.data.minBargeinWordCount || 1; - this.timeout = (this.timeout || 5) * 1000; + this.timeout = (this.timeout || 15) * 1000; this.interim = this.partialResultCallback; if (this.data.recognizer) { const recognizer = this.data.recognizer; @@ -256,21 +256,33 @@ class TaskGather extends Task { } _onTranscription(cs, ep, evt) { + this.logger.debug(evt, 'TaskGather:_onTranscription'); if ('aws' === this.vendor && Array.isArray(evt) && evt.length > 0) evt = evt[0]; if ('microsoft' === this.vendor) { - const nbest = evt.NBest; - const newEvent = { - is_final: evt.RecognitionStatus === 'Success', - alternatives: [ - { - confidence: nbest[0].Confidence, - transcript: nbest[0].Display - } - ] - }; - evt = newEvent; + const final = evt.RecognitionStatus === 'Success'; + if (final) { + const nbest = evt.NBest; + evt = { + is_final: true, + alternatives: [ + { + confidence: nbest[0].Confidence, + transcript: nbest[0].Display + } + ] + }; + } + else { + evt = { + is_final: false, + alternatives: [ + { + transcript: evt.Text + } + ] + } + } } - this.logger.debug(evt, 'TaskGather:_onTranscription'); if (evt.is_final) this._resolve('speech', evt); else { if (this.bargein && evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) {