1

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!

Aerodynamika
  • 7,883
  • 16
  • 78
  • 137

1 Answers1

3

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

Luizgrs
  • 4,765
  • 1
  • 22
  • 28