Article image Development of speech recognition applications with Javascript

Development of speech recognition applications with Javascript

Page 32 | Listen in audio

The development of voice recognition applications with Javascript has become increasingly popular, mainly with the advancement of technology and the ease of access to devices that have this functionality, such as smartphones and virtual assistants.

To start developing a speech recognition application, it is necessary to use the Javascript Web Speech API, which allows access to speech recognition and synthesis resources directly in the browser.

With the Web Speech API, you can create custom voice commands for your application, in addition to allowing the user to interact with the website or application through voice, making the experience more intuitive and practical.

To use the Web Speech API, you must first verify that your browser supports this functionality. For that, we can use the following code:

if ('SpeechRecognition' in window || 'webkitSpeechRecognition' in window) {
  // Browser supports Web Speech API
} else {
  // Browser does not support Web Speech API
}

After checking browser compatibility, we can start using the Web Speech API. For that, it is necessary to create an instance of the SpeechRecognition object and configure its properties and events, as in the example below:

const recognition = new SpeechRecognition();

recognition.lang = 'pt-BR';

recognition.onresult = event => {
  const transcript = event.results[0][0].transcript;
  console.log(transcript);
};

recognition.start();

In this example, we create an instance of the SpeechRecognition object, set the recognition language to Brazilian Portuguese, and add an onresult event that will fire when the user's speech is recognized. In the event, we access the speech transcription through the results property and print it to the console.

In addition, you can use the Web Speech API in conjunction with other technologies, such as the Web Audio API, to create sound effects and improve the user experience.

In summary, the development of voice recognition applications with Javascript is a trend that has been gaining more and more space in the market. With the Web Speech API, you can create more intuitive and practical interactions for the user, in addition to customizing voice commands for your application.

Now answer the exercise about the content:

_What is the purpose of the Javascript Web Speech API?

You are right! Congratulations, now go to the next page

You missed! Try again.

Article image Development of image recognition applications with Javascript

Next page of the Free Ebook:

33Development of image recognition applications with Javascript

2 minutes

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text