tom-s / speak-tts

76 stars 19 forks source link

How can I detect end of paragraph? #1

Closed webmagnets closed 7 years ago

webmagnets commented 7 years ago

I am having this speak a paragraph. The onEnd callback fires when the first sentence is finished. How can I make onEnd fire when the full paragraph string is spoken?

Thanks for all your work on this project!

tom-s commented 7 years ago

Hi. https://github.com/tom-s/speak-tts/blob/master/src/speak-tts.js -> line 223 we loop on the sentences and play them. Line 244 we assign the onEnd event, you want to assign it for the last sentance only (this is a bug, my bad). I don't have much time to do it at the moment but feel free to submit a PR.

webmagnets commented 7 years ago

I had a look at the code and try a few things, but I am too inexperienced to fix it. I don't understand the code.

tom-s commented 7 years ago

something like

sentences.forEach((sentence, index) => { ... utterance.onend = (e) => { if(onEnd && index === sentences.length - 1) onEnd() }

tom-s commented 7 years ago

I did the change, you can see the PR here : https://github.com/tom-s/speak-tts/pull/2

I publish on npm, it's version 1.0.1 now.

Please close the issue if it works for you.