DEV Community

Cover image for Speech Recognition With Javascript

Speech Recognition With Javascript

Asaolu Elijah 🧙‍♂ on January 21, 2020

Introduction Speech recognition refers to the the process of enabling a computer to identify and respond to the sounds produced in human...
Collapse
 
patricnox profile image
PatricNox

Nice! Very neat and simple.

Should include an practical example of where you show the results given through a test.

Collapse
 
asaoluelijah profile image
Asaolu Elijah 🧙‍♂

Thanks Patrick, I'd just added a sub section explaining the result.
And here i showed a practical example implementing speech recognition.

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();
}

Collapse
 
olawanle_joel profile image
Joel Olawanle

This is nice sir

Collapse
 
asaoluelijah profile image
Asaolu Elijah 🧙‍♂

Thank you sire ☺

Collapse
 
deta19 profile image
mihai

can it generate sounds, of different length ways?

Collapse
 
asaoluelijah profile image
Asaolu Elijah 🧙‍♂

Not really Mihai, this is basically to recognize spoken words and not generate. If you are looking to convert text to speech, here is a great tutorial for that.

Collapse
 
tsahay2 profile image
Tushar Sahay

Please visit covid.tusharsahay.com to see a practical example where I have used this API. Let me know how you find it! :-)

Collapse
 
asaoluelijah profile image
Asaolu Elijah 🧙‍♂

Wow, this is amazing Tushar.
Really nice!
Keep up the good work 🎉

Collapse
 
asaoluelijah profile image
Asaolu Elijah 🧙‍♂

Glad you found it super useful ❀

Collapse
 
muteenk profile image
muteenk

Does anyone know how to use the API in Firefox browser, the onresult event function is not executing for some reason