最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to know if webkitSpeechRecognition is started? - Stack Overflow

programmeradmin6浏览0评论

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.

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.

Share Improve this question edited May 28, 2017 at 11:34 Koby Douek 16.7k20 gold badges78 silver badges110 bronze badges asked May 28, 2017 at 11:30 TomSkatTomSkat 2834 silver badges11 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 17

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
}

You can simple check this

if(this.recognition){
    //do something if true
}else{
    // do something else if false
}
发布评论

评论列表(0)

  1. 暂无评论