From 565478cc0a1ad16d686f7ebad440b3eafa6def6c Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 12 Feb 2024 10:26:34 -0500 Subject: [PATCH] #573 address race condition in pause/resume recording (#584) --- lib/tasks/transcribe.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/tasks/transcribe.js b/lib/tasks/transcribe.js index 5d4dfc53..723d66a2 100644 --- a/lib/tasks/transcribe.js +++ b/lib/tasks/transcribe.js @@ -41,6 +41,7 @@ class TaskTranscribe extends SttTask { /* buffer speech for continuous asr */ this._bufferedTranscripts = []; this.bugname_prefix = 'transcribe_'; + this.paused = false; } get name() { return TaskName.Transcribe; } @@ -117,9 +118,11 @@ class TaskTranscribe extends SttTask { this.logger.info(`TaskTranscribe:updateTranscribe status ${status}`); switch (status) { case TranscribeStatus.Pause: + this.paused = true; await this._stopTranscription(); break; case TranscribeStatus.Resume: + this.paused = false; await this._startTranscribing(this.cs, this.ep, 1); if (this.separateRecognitionPerChannel && this.ep2) { await this._startTranscribing(this.cs, this.ep2, 2); @@ -296,6 +299,10 @@ class TaskTranscribe extends SttTask { // make sure this is not a transcript from answering machine detection const bugname = fsEvent.getHeader('media-bugname'); if (bugname && this.bugname !== bugname) return; + if (this.paused) { + this.logger.debug({evt}, 'TaskTranscribe:_onTranscription - paused, ignoring transcript'); + } + if (this.vendor === 'ibm' && evt?.state === 'listening') return; @@ -399,7 +406,8 @@ class TaskTranscribe extends SttTask { } _onNoAudio(cs, ep, channel) { - this.logger.debug(`TaskTranscribe:_onNoAudio restarting transcription on channel ${channel}`); + this.logger.debug(`TaskTranscribe:_onNoAudio on channel ${channel}`); + if (this.paused) return; if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) { this.childSpan[channel - 1].span.setAttributes({ channel, @@ -415,7 +423,8 @@ class TaskTranscribe extends SttTask { } _onMaxDurationExceeded(cs, ep, channel) { - this.logger.debug(`TaskTranscribe:_onMaxDurationExceeded restarting transcription on channel ${channel}`); + this.logger.debug(`TaskTranscribe:_onMaxDurationExceeded on channel ${channel}`); + if (this.paused) return; if (this.childSpan[channel - 1] && this.childSpan[channel - 1].span) { this.childSpan[channel - 1].span.setAttributes({ channel, @@ -440,6 +449,7 @@ class TaskTranscribe extends SttTask { async _onJambonzError(cs, _ep, evt) { this.logger.info({evt}, 'TaskTranscribe:_onJambonzError'); + if (this.paused) return; if (this.isHandledByPrimaryProvider && this.fallbackVendor) { _ep.stopTranscription({ vendor: this.vendor,