Skip to content

Commit

Permalink
fixed a 'no-speech' error handling bug in stt-socket-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
fquirin committed Apr 10, 2022
1 parent e57c1cd commit 4f3448d
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/modules/stt-socket-worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,20 +469,25 @@ function maxLengthReached(){

//send result message (partial or final)
function sendWebSpeechCompatibleRecognitionResult(isFinal, transcript){
postMessage({
recognitionEvent: {
type: "result",
resultIndex: 0,
results: [{
isFinal: isFinal,
"0": {
transcript: transcript
}
}],
timeStamp: Date.now()
},
eventFormat: "webSpeechApi"
});
if (isFinal && !transcript){
//this is actually a 'nomatch'/'no-speech' error (no-speech usually fails more gently)
sendWebSpeechCompatibleError("no-speech", "Final result was empty");
}else{
postMessage({
recognitionEvent: {
type: "result",
resultIndex: 0,
results: [{
isFinal: isFinal,
"0": {
transcript: transcript
}
}],
timeStamp: Date.now()
},
eventFormat: "webSpeechApi"
});
}
}
function sendDefaultRecognitionResult(event){
if (event && !event.type) event.type = "result";
Expand Down

0 comments on commit 4f3448d

Please sign in to comment.