2

i use the webkitSpeechRecognition() to create my own little voice recorder.

Here is a demo (works only with chrome!)
http://jsfiddle.net/gsu4aod2/

Say a sentence and
1a.) if the text correct, click on the "add sentence" button
1b.) if the text not correct click the "speak again" button

My problem is that i dont know how to "reset" the text. When i use the stop() and start() method, the text is removed but than i must confirm the access to the microphone again and again.

Any ideas?

Web Speech API Specification https://www.google.com/intl/en/chrome/demos/speech.html

Peter
  • 11,413
  • 31
  • 100
  • 152
  • Please see ["Should questions include “tags” in their titles?"](http://meta.stackexchange.com/questions/19190/should-questions-include-tags-in-their-titles), where the consensus is "no, they should not"! –  Apr 07 '15 at 06:57

1 Answers1

3

You are getting the events.result data starting from index 0. You need to start the for loop with something called event.resultIndex.

resultIndex attribute: The resultIndex must be set to the lowest index in the "results" array that has changed. [source]

recognition.onresult = function (event) {
    //console.log(event);
      var final = "";
      var interim = "";
      for (var i = event.resultIndex; i < event.results.length; ++i) {
        if (event.results[i].final) {
          final += event.results[i][0].transcript;
        } else {
          interim += event.results[i][0].transcript;
        }
      }

Fiddle Demo

anpsmn
  • 7,217
  • 2
  • 28
  • 44