DEV Community

Discussion on: Speech Recognition With Javascript

Collapse
 
mrmalik16 profile image
Sharjeel Faiq

This is a great post! Can you show me how to use this in react js functional component. I don't really have an idea how to capture my text area's value inside a js variable.

Below is the onclick() function that I'm using to invoke record() function inside a button in reactjs.

Speech to text

const record = () => {
window.recognition.onresult = function(event) {
console.log(event);
let output = document.getElementById("output");
output.innerHTML = "";

  for (let i = 0; i < event.results.length; i++) {

      output.innerHTML = output.innerHTML + event.results[i][0].transcript;

  }
Enter fullscreen mode Exit fullscreen mode

}
window.recognition.start();
}