1

Below is a simple demo of how I am using the Web Speech API for speech recognition. If you run the demo yourself, just say something after you give mic permissions and watch the console:

var recognition = new webkitSpeechRecognition();
recognition.onresult = function(event) {

 // get SpeechRecognitionResultList object
 var resultList = event.results;

 // get first SpeechRecognitionResult object
 var firstResult = resultList[0];

 // get this result's first SpeechRecognitionAlternative object
 var firstAlternative = firstResult[0];
 
 // this is the puzzling part
 console.log(firstAlternative);
 console.log(firstAlternative.hasOwnProperty('transcript'));
};
recognition.start();

In Chrome at least (only webkitty browsers work), I get these two outputs in the console (an object and boolean as expected):

{
  "transcript": "hello",
  "confidence": 0.9483599662780762
}
false

But I expect to see true and not false because I would think that transcript and confidence would pass a hasOwnProperty check. Why don't they?

See SpeechRecognitionAlternative on MDN

Web_Designer
  • 72,308
  • 93
  • 206
  • 262

0 Answers0