简体   繁体   中英

Google / html5 voice recognition JavaScript SDK Chrome webkitSpeechRecognition

I'm using Google's Javascript SDK voice recognition (webkitSpeechRecognition) for Chrome where I automatically turn on the recognition process and it then submits whatever the user said into my app's submit form on the followig event:

            recognition.onend = function(){}

The problem is that it takes quite long for onend to arrive.

I tried using onspeechend or onsoundend but it would fire at the same moment as onend .

I need something that fires right when the person finished talking or not so long thereafter.

Can anybody recommend a setting that I'm missing in this JS SDK or a solution?

Thank you!

If you don't want to wait until the browser detects user stopped to talk, it may take few seconds due to background noise, you can try to use partial (interim) results:

var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = true;

recognition.onresult = function(event) {
    var interim_transcript = '';
    for (var i = event.resultIndex; i < event.results.length; ++i) {
      if (event.results[i].isFinal) {
        final_transcript += event.results[i][0].transcript;
      } else {
        interim_transcript += event.results[i][0].transcript;
      }
    }

     document.querySelector('input').value = interim_transcript;  
  };

document.querySelector('button').addEventListener('click', function(){
    recognition.start();  
});

http://jsfiddle.net/2o1xjtud/

this is an excerpt from https://github.com/GoogleChrome/webplatform-samples/blob/master/webspeechdemo/webspeechdemo.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM