Reputation: 1142
I am doing webkitSpeechRecognition with JavaScript, and it's doing great, but I am facing a problem: I want my speech recognition to start when loading the page always on, and after every word, print it on console log.
I could not make my program to print every word even though I tried with while and so.
Here what I came up with so far:
<script>
function startDictation() {
if (window.hasOwnProperty('webkitSpeechRecognition')) {
var recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.interimResults = false;
recognition.lang = "en-US";
recognition.start();
recognition.onresult = function(e) {
//recognition.stop();
understand(e.results[0][0].transcript);
};
recognition.onerror = function(e) {
//recognition.stop();
}
}
}
window.onload = startDictation;
function understand(msg) {
console.log(msg);
//startDictation();
}
</script>
Upvotes: 5
Views: 9835
Reputation: 1882
Try replacing
recognition.interimResults = false;
with
recognition.interimResults = true;
You need to set interim results to true. It may not give you word by word but will give phrases as they are recognized. You can see more at: Voice Driven Web Apps: Introduction to the Web Speech API
Upvotes: 2