ak1394 / react-native-tts

React Native Text-To-Speech library for Android and iOS
603 stars 154 forks source link

Android tts-progress event. #175

Closed liviu-padurariu closed 3 years ago

liviu-padurariu commented 3 years ago

I've noticed that android is not triggering the tts-progress event. One could use the onRangeStart method to trigger the event.

I've tested succesfully on my project where I have a progress bar that gets updated for each word.

ak1394 commented 3 years ago

Thanks for the PR! There is one change I'd like you to make though, could you please remove if(ducking) {...} code.

It is used to release audio focus in the similar calls in onDone(), onError() and onStop() because these methods are called at the end of an utterance, while onRangeStart() is called while the utterance is being spoken, and can be called multiple times.

liviu-padurariu commented 3 years ago

Sure thing, let me know if there is something else that I should change.

ak1394 commented 3 years ago

Okay, if you offering to make more changes :), let's do this:

onRangeStart() receives few more arguments: int start, int end, int frame which presumably point at some location in the utterance, and I guess it might be useful to send this info as well.

However, the sendEvent() method takes only one argument which is utteranceId, so to make things work we need to refactor it a little. Can you do the following:

  1. Create additional sendEvent(String eventName, WritableMap params) method that would take existing params and ..emit(...) it.

  2. Update existing sendEvent(String eventName, String utteranceId) method to use newly created sendEvent(String eventName, WritableMap params)

  3. Update onRangeStart() to look something like that: ... WritableMap params = Arguments.createMap(); params.putString("utteranceId", utteranceId); params.putInt("start", start); params.putInt("end", end); params.putInt("frame", frame); sendEvent("tts-progress", params); ...

ak1394 commented 3 years ago

Looks good! I'm merging it. Did you test these? If it works for you, I'm going to publish the new version later today.

liviu-padurariu commented 3 years ago

Yes, everything works the same. Now you can get all from the onRangeStart args in the tts-progress event.

ak1394 commented 3 years ago

Thanks a lot for your contribution! The new release has been published.

dogankablan commented 2 years ago

It doesn't work for me on android. Can you tell me how to run it?