Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web speech API stops listening after some time passes without input

I'm using the web speech API but once a bit of time passes by (a minute or 2) without any vocal input, it stops listening entirely. I know this because I have it log its parsed text to the console, however, it stops doing this when I do not talk for a minute or two.

Is there any way to fix this?

like image 924
Russell C. Avatar asked Dec 25 '16 20:12

Russell C.


People also ask

Can Google Speech API be used offline?

Android does have offline speech recognition capabilities. You can activate this by going to Settings - Language and Input - Voice Input and touch the cog icon next to Enhanced Google Services.

How good is Web Speech API?

Conclusion. The Web Speech API is powerful and somewhat underused. However, there are a few annoying bugs and the SpeechRecognition interface is poorly supported. speechSynthesis works surprisingly well once you iron out all of its quirks and issues.

What is window webkitSpeechRecognition?

The speech recognition interface lives on the browser's window object as SpeechRecognition in Firefox and as webkitSpeechRecognition in Chrome. Start by setting the recognition interface to SpeechRecognition (regardless of the browser) using: window. SpeechRecognition = window. webkitSpeechRecognition || window.


2 Answers

You can listen to the end event and then restart the recognition on the SpeechRecognition object.

You should use a boolean flag for deciding (in the onend event handler), when to restart the recognition (and when not to restart).

You could use the other recognition-related events for this.

E.g. Chrome triggers the following event handlers when recognition is started:

1. onstart
2. onaudiostart

   (only if sound / speech is detected)
3. onsoundstart
4. onspeechstart

If no sound speech is detected, only the first 2 will be triggered, and then, after some timeout, the corresponding end events (in reverse order).

like image 90
russa Avatar answered Oct 16 '22 01:10

russa


A simple solution for this could probably be to listen for the end event and restart the recognition

recognition.addEventListener('end', recognition.start);
like image 25
Anup Avatar answered Oct 15 '22 23:10

Anup