Skip to content

Instantly share code, notes, and snippets.

@bramus
Last active February 27, 2024 22:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bramus/e27fcb783f469b6585007a7453e1bb5a to your computer and use it in GitHub Desktop.
Save bramus/e27fcb783f469b6585007a7453e1bb5a to your computer and use it in GitHub Desktop.
Text-to-Speech with the Web Speech API
// 🗣 Text-to-Speech with the Web Speech API's SpeechSynthesis
// @link https://gist.github.com/bramus/e27fcb783f469b6585007a7453e1bb5a
// @ref https://developer.mozilla.org/en-US/docs/Web/API/SpeechSynthesis
((text) => {
// Create an Utterance (= speech request)
const utter = new SpeechSynthesisUtterance(text);
// Set the voice
utter.voice = window.speechSynthesis.getVoices()[0];
// Speak!
window.speechSynthesis.speak(utter);
})('Hello from the DevTools');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment