DEV Community

loading...

Javascript Speech Synthesis Cheat Sheet

hoanganhlam profile image Lâm ・1 min read

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

Discussion (0)

Forem Open with the Forem app