From 4f3448d544b27265a13a6ab1a5e336e9251a8f17 Mon Sep 17 00:00:00 2001 From: Florian Quirin Date: Sun, 10 Apr 2022 13:48:57 +0200 Subject: [PATCH] fixed a 'no-speech' error handling bug in stt-socket-worker --- src/modules/stt-socket-worker.js | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/src/modules/stt-socket-worker.js b/src/modules/stt-socket-worker.js index cdf012f..b507007 100644 --- a/src/modules/stt-socket-worker.js +++ b/src/modules/stt-socket-worker.js @@ -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";