Search code examples
javascriptphphtmlspeech-to-text

HTML5's Speech Recognition API


I'm trying to use HTML5's Speech Recognition API, but it's not getting the speech that I'm trying to turn into text. Instead of the words I said, it displayed something else. Please take a look at my code:

<script type = 'text/javascript'>

var recognition = new webkitSpeechRecognition();
recognition.continuous = false;
recognition.interimResults = true;
recognition.onresult = function(event) { 
  alert(event);
}

</script>

<input type = "submit" value = "Start Speaking" onclick = "recognition.start()">

Alerted results:

[object SpeechRecognizationEvent]

Expected results:

"Hello"

^^^That's what I said.


Solution

  • Theres a lot about webkitSpeechRecognition that you can read , you get the object for the following reason :

    That gives an object that needs to be handled in this way :

    recognition.onresult = function(event) { 
    
       for (var i = event.resultIndex; i < event.results.length; ++i) { 
           var identificated = event.results[i][0].transcript;//This is what recognizes 
           if (event.results[i].isFinal) {
                 console.log("Final sentence is : " + identificated );  
           }else{
               console.log("I understood : " + identificated );  
            }
    }
    

    1) Look official demo here Source Code Here

    2) Or read quickly here (Here is what you need ) : Example of what you need

    You can test my library, is of Voice Control using webkitSpeechRecognition

    Artyom Voice Recognition - Control