From 648408622220d7c1fc4cda0963f6696059230e56 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Fri, 25 Nov 2022 08:15:18 -0500 Subject: [PATCH] feature: return transcript faster if we get an exact match to a provided hint on an interim transcript (requires env JAMBONZ_GATHER_EARLY_HINTS_MATCH=1) --- lib/tasks/gather.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/tasks/gather.js b/lib/tasks/gather.js index 61f9569f..bb7ce8a5 100644 --- a/lib/tasks/gather.js +++ b/lib/tasks/gather.js @@ -143,6 +143,14 @@ class TaskGather extends Task { this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost}, 'Gather:exec - applying global sttHints'); } + if (process.env.JAMBONZ_GATHER_EARLY_HINTS_MATCH && + !this.isContinuousAsr && + this.hints.length > 0 && this.hints.length <= 10) { + this.earlyHintsMatch = true; + this.interim = true; + this.logger.debug('Gather:exec - early hints match enabled'); + } + if (cs.hasAltLanguages) { this.altLanguages = this.altLanguages.concat(cs.altLanguages); this.logger.debug({altLanguages: this.altLanguages}, @@ -526,6 +534,15 @@ class TaskGather extends Task { } } + if (this.earlyHintsMatch && evt.is_final === false) { + const transcript = evt.alternatives[0].transcript?.toLowerCase(); + if (this.hints.find((h) => h.toLowerCase() === transcript)) { + this.logger.debug({evt}, 'Gather:_onTranscription: early hint match'); + this._resolve('speech', evt); + return; + } + } + /* count words for bargein feature */ const words = evt.alternatives[0].transcript.split(' ').length; const bufferedWords = this._bufferedTranscripts.reduce((count, e) => {