Text To Speech In 3 Lines Of JavaScript

published 19.05.2020 19:14


If you're curious about trying this out, that's the 3 lines of code below 👇 var msg = new = "Hello if you're not in a hurry, this article explains everything you need to know about converting text to speech (spoken words) on the web with JavaScript.

And the code below does that: if ('speechSynthesis' in window) { // Speech Synthesis supported 🎉 }else{ // Speech Synthesis Not Supported 😣 alert("Sorry, your browser doesn't support text to speech!")

; } Next step is to create a new speechSynthesis object, add required property and make our app talk👇 var msg = new = "Good Code Explanation Line 1: We created a variable msg, and the value assigned to it is a new instance of the speechSynthesis class.

text property is used to specify the text we want to convert to speech And finally, the code on the 3rd(last) line is what actually make our browser talks.