Categories
JavaScript Answers

How to use Google Text-To-Speech in JavaScript?

Spread the love

Sometimes, we want to use Google Text-To-Speech in JavaScript.

In this article, we’ll look at how to use Google Text-To-Speech in JavaScript.

How to use Google Text-To-Speech in JavaScript?

To use Google Text-To-Speech in JavaScript, we use the SpeechSynthesisUtterance constructor.

For instance, we write

const msg = new SpeechSynthesisUtterance("Hello World");
window.speechSynthesis.speak(msg);

to create a SpeechSynthesisUtterance object with the text string we want the computer to speak.

Then we call window.speechSynthesis.speak with msg to speak it.

Conclusion

To use Google Text-To-Speech in JavaScript, we use the SpeechSynthesisUtterance constructor.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *