How to find out if webkitSpeechRecognition is running?

I make the bot listen to my voice.
So I did:

this.recognition = new webkitSpeechRecognition();

I can do this to start listening to:

this.recognition.start();

And to stop listening:

this.recognition.stop();

But do you know a function that will return me true if this.recognitionrunning and false if it is stopped? How "isStarted()"?

Thank.

+4
source share
1 answer

You can do this by raising the flag variable in events onstartand onend:

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
}
+3
source

Source: https://habr.com/ru/post/1678067/


All Articles