Last active
August 13, 2019 00:16
-
-
Save justanotherdot/d314845a882953b707d787b2e4266dd8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const talk = (optText) => { | |
| let text = optText || Array.from(document.querySelectorAll('p')).map(p => p.outerText).join(' '); | |
| let t2s = new SpeechSynthesisUtterance(text); | |
| let voices = window.speechSynthesis.getVoices(); | |
| t2s.voice = voices.filter(v => v.name === 'Samantha')[0]; // Samantha is the standard US voice and lives at index 32 when I call this for my browser. Your locale may change this ordering. | |
| t2s.onend = function(e) { console.log('Read in ' + e.elapsedTime + ' seconds'); }; | |
| window.speechSynthesis.speak(t2s); | |
| }; | |
| // You can stop the output by calling... | |
| const pause = () => window.speechSynthesis.paused ? window.speechSynthesis.resume() : window.speechSynthesis.pause(); | |
| const stop = () => window.speechSynthesis.cancel(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment