From 22dad4eed61d879b7d84689cc1462ffa78aabd49 Mon Sep 17 00:00:00 2001 From: akirilyuk Date: Thu, 3 Feb 2022 22:01:29 +0100 Subject: [PATCH] restructure gather a bit --- lib/tasks/cognigy/index.js | 3 +-- lib/tasks/gather.js | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/tasks/cognigy/index.js b/lib/tasks/cognigy/index.js index 3d42d7e2..5a77e679 100644 --- a/lib/tasks/cognigy/index.js +++ b/lib/tasks/cognigy/index.js @@ -369,13 +369,12 @@ class Cognigy extends Task { //then stop execution of currently queues bot output before sending the //response to waiting bot since otherwise we could stop upcoming bot output - /* if (this.config.bargeInEnabled && this.config.skipUntilBotInput) { // clear task queue, resolve the last promise and cleanup; this.taskQueue.lastPromise.resolve(); this.taskQueue.end(); this.taskQueue.autostart = true; - }*/ + } if (this.eventHook) { this.performHook(cs, this.eventHook, {event: 'userMessage', message: utterance}) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 11b1debb..7bc3c56d 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -100,16 +100,28 @@ class TaskGather extends Task { try { if (this.sayTask) { this.logger.debug('Gather: kicking off say task'); + if (this.input.includes('speech') && this.listenDuringPrompt) { + await this._initSpeech(cs, ep); + this._startTranscribing(ep); + updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) + .catch(() => {/*already logged error */}); + } this.sayTask.exec(cs, ep); this.sayTask.on('playDone', async(err) => { if (err) return this.logger.error({err}, 'Gather:exec Error playing tts'); this.logger.debug('Gather: say task completed'); if (!this.killed) { - startListening(cs, ep); + startListening(cs, ep); } }); } else if (this.playTask) { + if (this.listenDuringPrompt && this.input.includes('speech')) { + await this._initSpeech(cs, ep); + this._startTranscribing(ep); + updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) + .catch(() => {/*already logged error */}); + } this.playTask.exec(cs, ep); // kicked off, _not_ waiting for it to complete this.playTask.on('playDone', async(err) => { if (err) return this.logger.error({err}, 'Gather:exec Error playing url'); @@ -120,13 +132,6 @@ class TaskGather extends Task { } else startListening(cs, ep); - if (this.input.includes('speech') && this.listenDuringPrompt) { - await this._initSpeech(cs, ep); - this._startTranscribing(ep); - updateSpeechCredentialLastUsed(this.sttCredentials.speech_credential_sid) - .catch(() => {/*already logged error */}); - } - if (this.input.includes('digits') || this.dtmfBargein) { ep.on('dtmf', this._onDtmf.bind(this, cs, ep)); }