Speech Recognition - Continuous Launch

I am trying to create a voice editor with HTML5 support using the speech recognition API. Currently, the problem is when you start recording, it lasts only a certain amount of time (mainly until the user stops talking).

I can set continuous and interimResults to true , but that does not force it to record forever. It is still ending.

I can also say that it fires again during the final event, but then it asks for permission every time, which greatly undermines.

Is there a way to allow it to work continuously, and only ask the user once?

+7
javascript html5 html5-audio speech-recognition
source share
2 answers

Regardless of the settings you choose, Google Chrome will stop the speech recognition engine after a while ... there is no way.

The only reliable solution I found for continuous speech recognition is to fire it again by attaching it to the onend() event, as you suggested.

If you try a similar method, remember the following:

You can see how I handled this in my code - https://github.com/TalAter/annyang/blob/master/annyang.js

+8
source share

Please try this code, I think it does what you need:

 <!DOCTYPE html> <html> <head> <title>Speech recognition</title> <style> #result{ border: 2px solid black; height: 200px; border-radius: 3px; font-size: 14px; } button{ position: absolute; top: 240px; left: 50%; } </style> <script type="application/javascript"> function start(){ var r = document.getElementById("result"); if("webkitSpeechRecognition" in window){ var speechRecognizer = new webkitSpeechRecognition(); speechRecognizer.continuous = true; speechRecognizer.interimResults = true; speechRecognizer.lang = "en-US"; speechRecognizer.start(); var finalTranscripts = ""; speechRecognizer.onresult = function(event){ var interimTranscripts = ""; for(var i=event.resultIndex; i<event.results.length; i++){ var transcript = event.results[i][0].transcript; transcript.replace("\n", "<br>"); if(event.results[i].isFinal){ finalTranscripts += transcript; } else{ interimTranscripts += transcript; } r.innerHTML = finalTranscripts + '<span style="color: #999;">' + interimTranscripts + '</span>'; } }; speechRecognizer.onerror = function(event){ }; } else{ r.innerHTML = "Your browser does not support that."; } } </script> </head> <body> <div id="result"></div> <button onclick="start()">Listen</button> </body> </html> 
-2
source share

All Articles