I am doing a POC and my requirement is that I want to implement the feature like OK google
or Hey Siri
on browser.
I am using the Chrome Browser's Web speech api
. The things I noticed that I can't continuous the recognition as it terminates automatically after a certain period of time and I know its relevant because of security concern. I just does another hack like when the SpeechReognition
terminates then on its end
event I further start
the SpeechRecogntion
but it is not the best way to implement such a solution because suppose if I am using the 2 instances of same application on the different browser tab then It doesn't work or may be I am using another application in my browser that uses the speech recognition then both the application doesn't behave the same as expected. I am looking for a best approach to solve this problem.
Thanks in advance.
Since your problem is that you can't run the SpeechRecognition continuously for long periods of time, one way would be to start the SpeechRecognition only when you get some input in the mic.
This way only when there is some input, you will start the SR, looking for your magic_word.
If the magic_word is found, then you will be able to use the SR normally for your other tasks.
This can be detected by the WebAudioAPI, which is not tied by this time restriction SR suffers from. You can feed it by an LocalMediaStream from
MediaDevices.getUserMedia
.For more info, on below script, you can see this answer.
Here is how you could attach it to a SpeechRecognition:
As a plunker, since neither StackSnippets nor jsfiddle's iframes will allow gUM in two versions...