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)

This commit is contained in:
Dave Horton
2022-11-25 08:15:18 -05:00
parent 01645df920
commit 6484086222

View File

@@ -143,6 +143,14 @@ class TaskGather extends Task {
this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost}, this.logger.debug({hints: this.hints, hintsBoost: this.hintsBoost},
'Gather:exec - applying global sttHints'); '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) { if (cs.hasAltLanguages) {
this.altLanguages = this.altLanguages.concat(cs.altLanguages); this.altLanguages = this.altLanguages.concat(cs.altLanguages);
this.logger.debug({altLanguages: this.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 */ /* count words for bargein feature */
const words = evt.alternatives[0].transcript.split(' ').length; const words = evt.alternatives[0].transcript.split(' ').length;
const bufferedWords = this._bufferedTranscripts.reduce((count, e) => { const bufferedWords = this._bufferedTranscripts.reduce((count, e) => {