"react voice recognition" Code Answer's
You're definitely familiar with the best coding language Javascript that developers use to develop their projects and they get all their queries like "react voice recognition" answered properly. Developers are finding an appropriate answer about react voice recognition related to the Javascript coding language. By visiting this online portal developers get answers concerning Javascript codes question like react voice recognition. Enter your desired code related query in the search bar and get every piece of information about Javascript code related question on react voice recognition.
react voice recognition
import React, { useState, useEffect } from 'react';
// the button form material-ui is optional
// npm install @material-ui/core
import Button from '@material-ui/core/Button';
const SpeechRecognition =
window.SpeechRecognition || window.webkitSpeechRecognition
const mic = new SpeechRecognition()
mic.continuous = true
mic.interimResults = true
mic.lang = 'en-US'
const RecordButton = () => {
const [isMicOn, setIsMicOn] = useState(false);
var buttonColour;
var buttonLabel;
if (isMicOn) {
buttonColour = "secondary";
buttonLabel = "Recording...";
} else {
buttonColour = "primary";
buttonLabel = "Record";
}
useEffect(() => {
handleListen()
}, [isMicOn])
const handleListen = () => {
if (isMicOn) {
mic.start()
mic.onend = () => {
console.log('continue..')
mic.start()
}
} else {
mic.stop()
mic.onend = () => {
console.log('Stopped Mic on Click')
}
}
mic.onstart = () => {
console.log('Mics on')
}
mic.onresult = event => {
const transcript = Array.from(event.results)
.map(result => result[0])
.map(result => result.transcript)
.join('')
console.log(transcript)
mic.onerror = event => {
console.log(event.error)
}
}
}
// if you don't want to us the button from Material-ui, just change Button to button
return(
<Button variant="contained" color={buttonColour} onClick={() => {setIsMicOn(!isMicOn)}} >{buttonLabel}</Button>
)
}
export default RecordButton;
All those coders who are working on the Javascript based application and are stuck on react voice recognition can get a collection of related answers to their query. Programmers need to enter their query on react voice recognition related to Javascript code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about react voice recognition for the programmers working on Javascript code while coding their module. Coders are also allowed to rectify already present answers of react voice recognition while working on the Javascript language code. Developers can add up suggestions if they deem fit any other answer relating to "react voice recognition". Visit this developer's friendly online web community, CodeProZone, and get your queries like react voice recognition resolved professionally and stay updated to the latest Javascript updates.