Skip to content

Commit 4f3448d

Browse files
committed
fixed a 'no-speech' error handling bug in stt-socket-worker
1 parent e57c1cd commit 4f3448d

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/modules/stt-socket-worker.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -469,20 +469,25 @@ function maxLengthReached(){
469469

470470
//send result message (partial or final)
471471
function sendWebSpeechCompatibleRecognitionResult(isFinal, transcript){
472-
postMessage({
473-
recognitionEvent: {
474-
type: "result",
475-
resultIndex: 0,
476-
results: [{
477-
isFinal: isFinal,
478-
"0": {
479-
transcript: transcript
480-
}
481-
}],
482-
timeStamp: Date.now()
483-
},
484-
eventFormat: "webSpeechApi"
485-
});
472+
if (isFinal && !transcript){
473+
//this is actually a 'nomatch'/'no-speech' error (no-speech usually fails more gently)
474+
sendWebSpeechCompatibleError("no-speech", "Final result was empty");
475+
}else{
476+
postMessage({
477+
recognitionEvent: {
478+
type: "result",
479+
resultIndex: 0,
480+
results: [{
481+
isFinal: isFinal,
482+
"0": {
483+
transcript: transcript
484+
}
485+
}],
486+
timeStamp: Date.now()
487+
},
488+
eventFormat: "webSpeechApi"
489+
});
490+
}
486491
}
487492
function sendDefaultRecognitionResult(event){
488493
if (event && !event.type) event.type = "result";

0 commit comments

Comments
 (0)