DEV Community

Lam
Lam

Posted on

Javascript Speech Synthesis Cheat Sheet

SpeechSynthesisUtterance

function speak (message) {
  var msg = new SpeechSynthesisUtterance(message)
  var voices = window.speechSynthesis.getVoices()
  msg.voice = voices[0]
  window.speechSynthesis.speak(msg)
}
Enter fullscreen mode Exit fullscreen mode
speak('Hello, world')
Enter fullscreen mode Exit fullscreen mode

See: SpeechSynthesisUtterance (developer.mozilla.org)

Reference

Top comments (0)