Anoynomous
Anoynomous

Reputation: 27

Unexpected End Of Input Using Microphone

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

Answers (1)

john Smith
john Smith

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

Related Questions