Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to know if webkitSpeechRecognition is started?

I'm making a bot to listen to my voice.
So i did :

this.recognition = new webkitSpeechRecognition();

I can do this to start listen :

this.recognition.start();

And this to stop listen :

this.recognition.stop();

But do you know a function that will return me true if this.recognition is started and false if it's stopped ? Like "isStarted()" ?

Thanks.

like image 278
TomSkat Avatar asked May 28 '17 11:05

TomSkat


People also ask

How webkitSpeechRecognition works?

We'll just make an HTML page with a single button. Once you press the button the browser will start listening to your microphone. The browser will transcribe what you've said when it detects that you're done speaking. After this is done we'll print the results to the console to confirm that everything works.

Why do we use the recognition start () function?

The start() method of the Web Speech API starts the speech recognition service listening to incoming audio with intent to recognize grammars associated with the current SpeechRecognition .

How do you stop a JavaScript speech?

cancel() The cancel() method of the SpeechSynthesis interface removes all utterances from the utterance queue. If an utterance is currently being spoken, speaking will stop immediately.

How to use SpeechRecognition in js?

JavaScript Speech to Text In the above code, we have used: recognition. start() method is used to start the speech recognition. Once we begin speech recognition, the onstart event handler can be used to inform the user that speech recognition has started and they should speak into the mocrophone.


1 Answers

You can do this by raising a flag variable on the onstart and onend events:

var recognition = new webkitSpeechRecognition();
var recognizing = false;

recognition.onstart = function () {
    recognizing = true;
};

recognition.onend = function () {
    recognizing = false;
};

recognition.onerror = function (event) {
    recognizing = false;
};

if (recognizing) {
    // Do stuff
}
like image 200
Koby Douek Avatar answered Oct 05 '22 23:10

Koby Douek