A Pen by Massimo Santini on CodePen.
Created
November 29, 2015 19:52
-
-
Save mapio/967b6a65b50d39c2ae4f to your computer and use it in GitHub Desktop.
(Sort of) busy wait workaround for SpeechSynthesisUtterance.onend bug
This file contains 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
<button onclick="doit()">Greet…</button> |
This file contains 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
function speak( text, onend ) { | |
window.speechSynthesis.cancel(); | |
var ssu = new SpeechSynthesisUtterance( text ); | |
window.speechSynthesis.speak( ssu ); | |
function _wait() { | |
if ( ! window.speechSynthesis.speaking ) { | |
onend(); | |
return; | |
} | |
window.setTimeout( _wait, 200 ); | |
} | |
_wait(); | |
} | |
function doit() { | |
speak( 'Hello, world!', function() { alert( 'done' ); } ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment