This JavaScript code is a small part of Web Speech API to implement Speech Recognition. "recognition.onend function" will be fired Whenever speech recognition service has disconnected, for example when "recognition.stop()" happens. Now The problem is because "recognition.stop()" happens in my if statement each time "recognition.onend function" fires again and it makes a loop over and over.
How To Stop this loop?
recognition.onend = function(event) {
//Fired when the speech recognition service has disconnected.
if (speechResult === "Hello") {
recognition.stop();
} else {
recognition.stop();
// and do something else
}
};