support disable/enable listen DTMF in prompt

This commit is contained in:
Quan HL
2024-07-09 16:11:45 +07:00
committed by Dave Horton
parent 5ccea65b7f
commit f514a65f63

View File

@@ -176,6 +176,12 @@ class TaskGather extends SttTask {
this._startVad(); 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) => { const startListening = async(cs, ep) => {
this._startTimer(); this._startTimer();
if (this.isContinuousAsr && 0 === this.timeout) this._startAsrTimer(); 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 {span, ctx} = this.startChildSpan(`nested:${this.sayTask.summary}`);
const process = () => { const process = () => {
this.logger.debug('Gather: nested say task completed'); this.logger.debug('Gather: nested say task completed');
if (!this.listenDuringPrompt) {
startDtmfListener();
}
this._stopVad(); this._stopVad();
if (!this.killed) { if (!this.killed) {
startListening(cs, ep); startListening(cs, ep);
@@ -226,6 +235,9 @@ class TaskGather extends SttTask {
const {span, ctx} = this.startChildSpan(`nested:${this.playTask.summary}`); const {span, ctx} = this.startChildSpan(`nested:${this.playTask.summary}`);
const process = () => { const process = () => {
this.logger.debug('Gather: nested play task completed'); this.logger.debug('Gather: nested play task completed');
if (!this.listenDuringPrompt) {
startDtmfListener();
}
this._stopVad(); this._stopVad();
if (!this.killed) { if (!this.killed) {
startListening(cs, ep); startListening(cs, ep);
@@ -269,8 +281,8 @@ class TaskGather extends SttTask {
} }
} }
if (this.input.includes('digits') || this.dtmfBargein || this.asrDtmfTerminationDigit) { if (this.listenDuringPrompt) {
ep.on('dtmf', this._onDtmf.bind(this, cs, ep)); startDtmfListener();
} }
await this.awaitTaskDone(); await this.awaitTaskDone();