fix asrtimer always return vendor=deepgram (#682)

This commit is contained in:
Hoan Luu Huu
2024-03-13 23:57:55 +07:00
committed by GitHub
parent 40f70e3531
commit b80d39d205
3 changed files with 9 additions and 9 deletions

View File

@@ -534,7 +534,7 @@ class TaskGather extends SttTask {
this._clearAsrTimer(); this._clearAsrTimer();
this._asrTimer = setTimeout(() => { this._asrTimer = setTimeout(() => {
this.logger.debug('_startAsrTimer - asr timer went off'); this.logger.debug('_startAsrTimer - asr timer went off');
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language); const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt); this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
}, this.asrTimeout); }, this.asrTimeout);
this.logger.debug(`_startAsrTimer: set for ${this.asrTimeout}ms`); this.logger.debug(`_startAsrTimer: set for ${this.asrTimeout}ms`);
@@ -663,7 +663,7 @@ class TaskGather extends SttTask {
this._clearFinalAsrTimer(); this._clearFinalAsrTimer();
this._finalAsrTimer = setTimeout(() => { this._finalAsrTimer = setTimeout(() => {
this.logger.debug('_startFinalAsrTimer - final asr timer went off'); this.logger.debug('_startFinalAsrTimer - final asr timer went off');
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language); const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt); this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
}, 1000); }, 1000);
this.logger.debug('_startFinalAsrTimer: set for 1 second'); this.logger.debug('_startFinalAsrTimer: set for 1 second');
@@ -712,7 +712,7 @@ class TaskGather extends SttTask {
} }
else { else {
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript'); this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript');
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language); evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
this._bufferedTranscripts = []; this._bufferedTranscripts = [];
this._resolve('speech', evt); this._resolve('speech', evt);
} }
@@ -782,7 +782,7 @@ class TaskGather extends SttTask {
this._clearTimer(); this._clearTimer();
if (this._finalAsrTimer) { if (this._finalAsrTimer) {
this._clearFinalAsrTimer(); this._clearFinalAsrTimer();
const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language); const evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
return this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt); return this._resolve(this._bufferedTranscripts.length > 0 ? 'speech' : 'timeout', evt);
} }
this._startAsrTimer(); this._startAsrTimer();
@@ -811,7 +811,7 @@ class TaskGather extends SttTask {
/* deepgram can send an empty and final transcript; only if we have any buffered should we resolve */ /* deepgram can send an empty and final transcript; only if we have any buffered should we resolve */
if (this._bufferedTranscripts.length === 0) return; if (this._bufferedTranscripts.length === 0) return;
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language); evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
this._bufferedTranscripts = []; this._bufferedTranscripts = [];
} }

View File

@@ -318,7 +318,7 @@ class TaskTranscribe extends SttTask {
} }
else { else {
this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript'); this.logger.debug('Gather:_onTranscription - got UtteranceEnd event from deepgram, return buffered transcript');
evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language); evt = this.consolidateTranscripts(this._bufferedTranscripts, 1, this.language, this.vendor);
this._bufferedTranscripts = []; this._bufferedTranscripts = [];
this._resolve('speech', evt); this._resolve('speech', evt);
} }
@@ -511,7 +511,7 @@ class TaskTranscribe extends SttTask {
this._clearAsrTimer(channel); this._clearAsrTimer(channel);
this._asrTimer = setTimeout(() => { this._asrTimer = setTimeout(() => {
this.logger.debug(`TaskTranscribe:_startAsrTimer - asr timer went off for channel: ${channel}`); this.logger.debug(`TaskTranscribe:_startAsrTimer - asr timer went off for channel: ${channel}`);
const evt = this.consolidateTranscripts(this._bufferedTranscripts, channel, this.language); const evt = this.consolidateTranscripts(this._bufferedTranscripts, channel, this.language, this.vendor);
this._bufferedTranscripts = []; this._bufferedTranscripts = [];
this._resolve(channel, evt); this._resolve(channel, evt);
}, this.asrTimeout); }, this.asrTimeout);

View File

@@ -150,7 +150,7 @@ const selectDefaultDeepgramModel = (task, language) => {
return 'base'; return 'base';
}; };
const consolidateTranscripts = (bufferedTranscripts, channel, language) => { const consolidateTranscripts = (bufferedTranscripts, channel, language, vendor) => {
if (bufferedTranscripts.length === 1) return bufferedTranscripts[0]; if (bufferedTranscripts.length === 1) return bufferedTranscripts[0];
let totalConfidence = 0; let totalConfidence = 0;
const finalTranscript = bufferedTranscripts.reduce((acc, evt) => { const finalTranscript = bufferedTranscripts.reduce((acc, evt) => {
@@ -191,7 +191,7 @@ const consolidateTranscripts = (bufferedTranscripts, channel, language) => {
totalConfidence / bufferedTranscripts.length; totalConfidence / bufferedTranscripts.length;
finalTranscript.alternatives[0].transcript = finalTranscript.alternatives[0].transcript.trim(); finalTranscript.alternatives[0].transcript = finalTranscript.alternatives[0].transcript.trim();
finalTranscript.vendor = { finalTranscript.vendor = {
name: 'deepgram', name: vendor,
evt: bufferedTranscripts evt: bufferedTranscripts
}; };
return finalTranscript; return finalTranscript;