Speech recognition API duplicated phrases on Android
The results provided on Chrome mobile regarding the result.isFinal
property seem to have a bug or in any case to differ from the ones on Chrome desktop. A possible workaround is to check the confidence attribute of the (first) alternative:
onResultHandler(event) { let i = event.resultIndex; let result = event.results[i]; let isFinal = result.isFinal && (result[0].confidence > 0);}
It also looks like that sometimes the final result is emitted twice (with the same confidence
value), in that case you may want to debounce it or just process the first event, like this:
if (isFinal) { transcript = result[0].transcript; if(transcript == lastDebounceTranscript) { return; } lastDebounceTranscript = transcript;}
where lastDebounceTranscript
is a variable that you initialize outside of the scope of the event handler
Try this:
recognition.continuous = false;recognition.interimResults = false;recognition.maxAlternatives = 1;
JSFiddle: https://jsfiddle.net/envwao8o/4/