Skip to content

Instantly share code, notes, and snippets.

@amielucha
Last active March 23, 2020 12:18
Show Gist options
  • Save amielucha/4fa5fff856699d85632f0dfa07f79e8b to your computer and use it in GitHub Desktop.
Save amielucha/4fa5fff856699d85632f0dfa07f79e8b to your computer and use it in GitHub Desktop.
Text to speech one-liner
// Store an article node as a temp1 variable and run this:
[...temp1.querySelectorAll('p')].forEach(p => speechSynthesis.speak(new SpeechSynthesisUtterance(p.textContent)))
// or:
speechSynthesis.speak(new SpeechSynthesisUtterance([...temp1.querySelectorAll('p')].map(p => p.textContent).join(' ')))
// To stop playback:
speechSynthesis.cancel()
// Also:
speechSynthesis.pause()
speechSynthesis.resume()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment