From 4b4807e4cf211a0393027b34c6f9e398f67b036b Mon Sep 17 00:00:00 2001 From: rammohan-kore Date: Thu, 25 Jul 2024 21:52:42 +0530 Subject: [PATCH] Check the confidence levels of a transcript with minConfidence (#808) * https://github.com/jambonz/jambonz-feature-server/issues/807 * feat/807: Using minConfidence from recognizer settings * feat/807: new reason stt-min-confidence-error * feat/807: sending stt-min-confidence instead of stt-min-confidence-error * feat/807: sending stt-low-confidence instead of stt-min-confidence-error * feat/807 - removed ? for this.data --- lib/tasks/gather.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 728f5710..fbe4ede2 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -736,6 +736,16 @@ class TaskGather extends SttTask { this.logger.info({evt}, 'TaskGather:_onTranscription - got empty transcript, continue listening'); return; } + const confidence = evt.alternatives[0].confidence; + const minConfidence = this.data.recognizer?.minConfidence; + this.logger.debug({evt}, + `TaskGather:_onTranscription - confidence (${confidence}), minConfidence (${minConfidence})`); + if (confidence && minConfidence && confidence < minConfidence) { + this.logger.info({evt}, + 'TaskGather:_onTranscription - Transcript confidence ' + + `(${confidence}) < minConfidence (${minConfidence})`); + return this._resolve('stt-low-confidence', evt); + } /* fast path: our first partial transcript exactly matches an early hint */ if (this.earlyHintsMatch && evt.is_final === false && this.partialTranscriptsCount++ === 0) { @@ -1091,6 +1101,12 @@ class TaskGather extends SttTask { this.emit('stt-error', evt); returnedVerbs = await this.performAction({reason: 'error', details: evt.error}); } + } else if (reason.startsWith('stt-low-confidence')) { + if (this.parentTask) this.parentTask.emit('stt-low-confidence', evt); + else { + this.emit('stt-low-confidence', evt); + returnedVerbs = await this.performAction({reason: 'stt-low-confidence'}); + } } } catch (err) { /*already logged error*/ }