Search code examples
javascriptresponsivevoice

How to detect end of speech in ResponsiveVoice JS


I'm working with the ResponsiveVoice text to speech library.

Everything is working perfectly fine except there seems to be no way of detecting the end of speech in the API.

On the responsiveVoice object I'm able to see the OnFinishedPlaying callback but it doesn't work. Neither does the onend callback mentioned here.

Right now I'm using the setInterval to poll on isPlaying method to detect the end of speech. However it would be great if there was a method to do so properly.

Here's the code on Github that I'm working with.

And here's a minimal JSFiddle test code.


Solution

  • The mentioned onend callback is working if you put the options object as the 3rd parameter:

    responsiveVoice.speak('Responsive Voice is ready', 'UK English Male', {onend: yourCallbackGoesHere});
    

    See JSFiddle