diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 5f14069e..f0516e5d 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -3009,6 +3009,11 @@ Duration=${duration} ` const task = this.currentTask; if (task && TaskName.Say === task.name) { task.notifyTtsStreamIsEmpty(); + } else if ( + // If Gather nested say task is streaming + TaskName.Gather === task.name && task.sayTask && task.sayTask.isStreamingTts) { + const sayTask = task.sayTask; + sayTask.notifyTtsStreamIsEmpty(); } } diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 37df89d1..ab132894 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -267,11 +267,16 @@ class TaskGather extends SttTask { .catch((err) => { process(); }); - this.sayTask.on('playDone', (err) => { - span.end(); - if (err) this.logger.error({err}, 'Gather:exec Error playing tts'); + if (this.sayTask.isStreamingTts && !this.sayTask.closeOnStreamEmpty) { + // if streaming tts, we do not wait for it to complete if it is not closing the stream automatically process(); - }); + } else { + this.sayTask.on('playDone', (err) => { + span.end(); + if (err) this.logger.error({err}, 'Gather:exec Error playing tts'); + process(); + }); + } } else if (this.playTask) { const {span, ctx} = this.startChildSpan(`nested:${this.playTask.summary}`);