From 812b40fcb062e60d86e9d5fd5ef80244d1e5eb0c Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Sat, 26 Feb 2022 22:05:21 +0100 Subject: [PATCH] add possibility to not listen after gather say/play finished --- lib/tasks/gather.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 03ff4de0..7d446d13 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -59,6 +59,12 @@ class TaskGather extends Task { if (this.say) this.sayTask = makeTask(this.logger, {say: this.say}, this); if (this.play) this.playTask = makeTask(this.logger, {play: this.play}, this); + if (this.sayTask || this.playTask) { + // this is specially for barge in where we want to make a bargebale promt + // to a user without listening after the say task has finished + this.listenAfterSpeech = typeof this.data.listenAfterSpeech === 'boolean' ? this.data.listenAfterSpeech : true; + } + this.parentTask = parentTask; } @@ -109,13 +115,26 @@ class TaskGather extends Task { this.sayTask.on('playDone', (err) => { if (err) return this.logger.error({err}, 'Gather:exec Error playing tts'); this.logger.debug('Gather: say task completed'); + if (!this.killed) { + if (this.listenAfterSpeech === true) { + startListening(cs, ep); + } else { + this.notifyTaskDone(); + } + } }); } else if (this.playTask) { this.playTask.exec(cs, ep); // kicked off, _not_ waiting for it to complete this.playTask.on('playDone', (err) => { if (err) return this.logger.error({err}, 'Gather:exec Error playing url'); - if (!this.killed) startListening(cs, ep); + if (!this.killed) { + if (this.listenAfterSpeech === true) { + startListening(cs, ep); + } else { + this.notifyTaskDone(); + } + } }); } else this._startTimer();