webkitSpeechRecognition is “lagging” behind when gathering results

前端 未结 1 1515
醉酒成梦
醉酒成梦 2021-01-13 03:24

Had an itch to try out the Web Speech API. I copied the code exactly from the article, and I\'m having an issue where you speak, but nothing happens until you speak AGAIN.

相关标签:
1条回答
  • 2021-01-13 03:53

    There is some kind of built in timeout, after which you will get the result even if there is no more input (seems to be around 5-10 seconds).

    In this case you will get the final onresult event, as well as the onend event. You will have to call recognition.start() again if you wish to keep accepting input.

    Also, if you set

    recognition.interimResults = true;
    

    you will get onresult events with non final results, and you can decide if you want to display them before you get the final ones.

    The other option is to turn off continuous with

    recognition.continuous = false;
    

    you will get a result shortly after the input (audio) stopped. You will also get the onend event.
    If you wish to continue the recognition you will have to call again

    recognition.start();
    

    in the onend event handler.
    On a non HTTPS page, this will cause the permission bar to pop up again.

    see example

    0 讨论(0)
提交回复
热议问题