Files
30-seconds-of-code/snippets/speech-synthesis-(experimental).md
Stefan Feješ b848906fe5 fix naming
2017-12-17 15:41:31 +01:00

602 B

Speech synthesis (experimental)

Use SpeechSynthesisUtterance.voice and window.speechSynthesis.getVoices() to convert a message to speech. Use window.speechSynthesis.speak() to play the message.

Learn more about the SpeechSynthesisUtterance interface of the Web Speech API.

const speechSynthesis = message => {
  const msg = new SpeechSynthesisUtterance(message);
  msg.voice = window.speechSynthesis.getVoices()[0];
  window.speechSynthesis.speak(msg);
};
// speak('Hello, World') -> plays the message