DEV Community

Cover image for Javascript text-to-sppech
Alison Silva 🔥💯⛏️
Alison Silva 🔥💯⛏️

Posted on

Javascript text-to-sppech

Did you know javascript have native text-to-sppech?
Try it in your console.

const speak = (msg, lg = 'en') => {
  const sp = new SpeechSynthesisUtterance(msg);
  [sp.voice] = speechSynthesis.getVoices();
  sp.lang = lg;
  speechSynthesis.speak(sp);
};

speak('Hello, my name is Alison Silva, and I\'m a software developer. Did you know javascript have native text-to-sppech?');
Enter fullscreen mode Exit fullscreen mode

You include can change the language as you see in the code above.

Top comments (0)