bugfix: handle interim results from azure

This commit is contained in:
Dave Horton
2022-01-24 15:04:50 -05:00
parent b94605127e
commit 1bca165fc1

View File

@@ -22,7 +22,7 @@ class TaskGather extends Task {
].forEach((k) => this[k] = this.data[k]); ].forEach((k) => this[k] = this.data[k]);
this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true; this.listenDuringPrompt = this.data.listenDuringPrompt === false ? false : true;
this.minBargeinWordCount = this.data.minBargeinWordCount || 1; this.minBargeinWordCount = this.data.minBargeinWordCount || 1;
this.timeout = (this.timeout || 5) * 1000; this.timeout = (this.timeout || 15) * 1000;
this.interim = this.partialResultCallback; this.interim = this.partialResultCallback;
if (this.data.recognizer) { if (this.data.recognizer) {
const recognizer = this.data.recognizer; const recognizer = this.data.recognizer;
@@ -256,21 +256,33 @@ class TaskGather extends Task {
} }
_onTranscription(cs, ep, evt) { _onTranscription(cs, ep, evt) {
this.logger.debug(evt, 'TaskGather:_onTranscription');
if ('aws' === this.vendor && Array.isArray(evt) && evt.length > 0) evt = evt[0]; if ('aws' === this.vendor && Array.isArray(evt) && evt.length > 0) evt = evt[0];
if ('microsoft' === this.vendor) { if ('microsoft' === this.vendor) {
const nbest = evt.NBest; const final = evt.RecognitionStatus === 'Success';
const newEvent = { if (final) {
is_final: evt.RecognitionStatus === 'Success', const nbest = evt.NBest;
alternatives: [ evt = {
{ is_final: true,
confidence: nbest[0].Confidence, alternatives: [
transcript: nbest[0].Display {
} confidence: nbest[0].Confidence,
] transcript: nbest[0].Display
}; }
evt = newEvent; ]
};
}
else {
evt = {
is_final: false,
alternatives: [
{
transcript: evt.Text
}
]
}
}
} }
this.logger.debug(evt, 'TaskGather:_onTranscription');
if (evt.is_final) this._resolve('speech', evt); if (evt.is_final) this._resolve('speech', evt);
else { else {
if (this.bargein && evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) { if (this.bargein && evt.alternatives[0].transcript.split(' ').length >= this.minBargeinWordCount) {