From f514a65f630ae7bad404e750a2b0c0b46e5adc69 Mon Sep 17 00:00:00 2001 From: Quan HL Date: Tue, 9 Jul 2024 16:11:45 +0700 Subject: [PATCH] support disable/enable listen DTMF in prompt --- lib/tasks/gather.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 16c7ca3e..728f5710 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -176,6 +176,12 @@ class TaskGather extends SttTask { this._startVad(); + const startDtmfListener = () => { + if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) { + ep.on('dtmf', this._onDtmf.bind(this, cs, ep)); + } + }; + const startListening = async(cs, ep) => { this._startTimer(); if (this.isContinuousAsr && 0 === this.timeout) this._startAsrTimer(); @@ -199,6 +205,9 @@ class TaskGather extends SttTask { const {span, ctx} = this.startChildSpan(`nested:${this.sayTask.summary}`); const process = () => { this.logger.debug('Gather: nested say task completed'); + if (!this.listenDuringPrompt) { + startDtmfListener(); + } this._stopVad(); if (!this.killed) { startListening(cs, ep); @@ -226,6 +235,9 @@ class TaskGather extends SttTask { const {span, ctx} = this.startChildSpan(`nested:${this.playTask.summary}`); const process = () => { this.logger.debug('Gather: nested play task completed'); + if (!this.listenDuringPrompt) { + startDtmfListener(); + } this._stopVad(); if (!this.killed) { startListening(cs, ep); @@ -269,8 +281,8 @@ class TaskGather extends SttTask { } } - if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) { - ep.on('dtmf', this._onDtmf.bind(this, cs, ep)); + if (this.listenDuringPrompt) { + startDtmfListener(); } await this.awaitTaskDone();