How to Use Text To Speech In Chrome with JS

mafee6

Mafee7

Posted on March 23, 2021

How to Use Text To Speech In Chrome with JS

image
Text To Speech [Speech Synthesis API]

API Usage:

JavaScript

var T2S; 

if("speechSynthesis" in window || speechSynthesis){ // Checking If speechSynthesis Is Supported.

    var text = prompt("What Text To Say?") || `Text To Speech is Over Powered`; // Ask What To Say or use Default

    T2S = window.speechSynthesis || speechSynthesis; // Storing speechSynthesis API as variable - T2S
    var utter = new SpeechSynthesisUtterance(text); // To Make The Utterance
    T2S.speak(utter); // To Speak The Utterance

    window.onbeforeunload = function(){
        T2S.cancel(); // To Stop Speaking If the Page Is Closed.
    }

}
Enter fullscreen mode Exit fullscreen mode

Pls React & Save!

💖 💪 🙅 🚩
mafee6
Mafee7

Posted on March 23, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related