huu huu - 1 year ago 194
Javascript Question

SpeechSynthesis API onend callback not working

I'm using the Speech Synthesis API on Google Chrome v34.0.1847.131. The API is implemented in Chrome starting in v33.

The text-to-speech works for the most part, except when assigning a callback to

. For instance, the following code:

var message = window.SpeechSynthesisUtterance("Hello world!");
message.onend = function(event) {
console.log('Finished in ' + event.elapsedTime + ' seconds.');

will sometimes call
and sometimes not call it. The timing appears to be completely off. When it does get called, the printed
is always some epoch time like

Answer Source

While this is how i found it to make it work i am not sure if this is the right behavior....

First don't call the speak function it right away, use callback.

2nd, to get time use timeStamp instead of elapsedTime. You could have just used as well.


you get time passed and both events fired for sure.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download