DEV Community

Cover image for Javascript text-to-sppech
1 1

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)

Sentry image

See why 4M developers consider Sentry, β€œnot bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay