Reputation: 27
I am using SpeechRecognition to use the microphone in one of my programs.
The Chrome Console is saying at the end: Unexpected end of input
const speechRecognition =
window.webkitSpeechRecognition /*Chrome*/ ||
window.SpeechRecognition;/*Firefox...*/
function startListening() {
const recog = new speechRecognition
recog.start();
recog.onstart = console.log("Started Listening..");
recog.onresult = function (data) {
handleResults(data);
};
//'data' comes from 'onresult'
function handleResults(data) {
let text = data.result[0][0].transcript;
console.log(text);
}
// Call Function On Load
window.addEventListener('DOMContentLoaded', startListening());
Upvotes: 3
Views: 35
Reputation: 17906
you get the unexpected end of input error because you are not closing the startListening function correctly
function startListening() {
const recog = new speechRecognition
recog.start();
recog.onstart = console.log("Started Listening..");
recog.onresult = function (data) {
handleResults(data);
}
} // <-- this is missing in your code
Upvotes: 1