I've been following this and supplementing it with various youtube videos and stack overflow questions. But, I am not exactly sure why my speech recognition is not working. I am asked about allowing microphone access rarely.
I want the user microphone to pick up the user's speech speech and append it to a certain input value. Here's my code:
const recognition = new SpeechRecognition();
recognition.interimResults = true;
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
name.value = event.results[0][0].transcript;
}
}
recognition.addEventListener("end", () => {
recognition.start();
});
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
location.value = event.results[0][0].transcript;
}
}
recognition.addEventListener("end", () => {
recognition.start();
});
var recognition = new SpeechRecognition();
recognition.onresult = function(event) {
if (event.results.length > 0) {
state.value = event.results[0][0].transcript;
document.care.submit();
}
}
recognition.addEventListener("end", () => {
window.location.pathname = '/care';
document.care.submit();
});
Here are the errors I am getting:
Uncaught ReferenceError: recognition is not defined at HTMLButtonElement.onclick
Uncaught SyntaxError: Identifier 'recognition' has already been declared
Failed to load resource: net::ERR_FAILED