From 42731964472e60801bde2c5c106e71df2954060c Mon Sep 17 00:00:00 2001 From: Hoan Luu Huu <110280845+xquanluu@users.noreply.github.com> Date: Mon, 4 Dec 2023 20:16:42 +0700 Subject: [PATCH] Fix/interdigit timeout (#554) * fix interdtmf timeout * wip * wip * wip * remove all speech listener if dtmf is received --- lib/tasks/gather.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 8aa1bdc9..8a9b1ff7 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -319,6 +319,13 @@ class TaskGather extends SttTask { this._resolve('dtmf-terminator-key'); } else if (this.input.includes('digits')) { + if (this.digitBuffer.length === 0 && this.needsStt) { + // DTMF is higher priority than STT. + this.removeSpeechListeners(ep); + ep.stopTranscription({vendor: this.vendor}) + .catch((err) => this.logger.error({err}, + ` Received DTMF, Error stopping transcription for vendor ${this.vendor}`)); + } this.digitBuffer += evt.dtmf; const len = this.digitBuffer.length; if (len === this.numDigits || len === this.maxDigits) { @@ -528,7 +535,9 @@ class TaskGather extends SttTask { this._clearTimer(); this._timeoutTimer = setTimeout(() => { if (this.isContinuousAsr) this._startAsrTimer(); - else if (this.interDigitTimeout <= 0 || this.digitBuffer.length < this.minDigits || this.needsStt) { + else if (this.interDigitTimeout <= 0 || + this.digitBuffer.length < this.minDigits || + this.needsStt && this.digitBuffer.length === 0) { this._resolve(this.digitBuffer.length >= this.minDigits ? 'dtmf-num-digits' : 'timeout'); } }, this.timeout);