From 51afd2b323b927b9b5f89c5797ba7de53773ddf1 Mon Sep 17 00:00:00 2001 From: Liviu Padurariu Date: Wed, 24 Mar 2021 11:43:30 +0100 Subject: [PATCH 1/3] Add: on progess event --- .../src/main/java/net/no_mad/tts/TextToSpeechModule.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java b/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java index c01c7c1..bc5ad95 100644 --- a/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java +++ b/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java @@ -89,6 +89,14 @@ public void onStop(String utteranceId, boolean interrupted) { } sendEvent("tts-cancel", utteranceId); } + + @Override + public void onRangeStart (String utteranceId, int start, int end, int frame) { + if(ducking) { + audioManager.abandonAudioFocus(afChangeListener); + } + sendEvent("tts-progress", utteranceId); + } }); } } From 91fb6c2905c4c4d1110b5c06a20c8c215a46986c Mon Sep 17 00:00:00 2001 From: Liviu Padurariu Date: Thu, 25 Mar 2021 17:57:43 +0100 Subject: [PATCH 2/3] Rem: ducking from the tts-progress event --- android/src/main/java/net/no_mad/tts/TextToSpeechModule.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java b/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java index bc5ad95..684999b 100644 --- a/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java +++ b/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java @@ -92,9 +92,6 @@ public void onStop(String utteranceId, boolean interrupted) { @Override public void onRangeStart (String utteranceId, int start, int end, int frame) { - if(ducking) { - audioManager.abandonAudioFocus(afChangeListener); - } sendEvent("tts-progress", utteranceId); } }); From 525bac67e2b4c30a252d2f5ed3fd702c0be42325 Mon Sep 17 00:00:00 2001 From: Liviu Padurariu Date: Thu, 25 Mar 2021 18:59:52 +0100 Subject: [PATCH 3/3] Add: new sendEvent method --- .../main/java/net/no_mad/tts/TextToSpeechModule.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java b/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java index 684999b..6be44a4 100644 --- a/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java +++ b/android/src/main/java/net/no_mad/tts/TextToSpeechModule.java @@ -92,7 +92,12 @@ public void onStop(String utteranceId, boolean interrupted) { @Override public void onRangeStart (String utteranceId, int start, int end, int frame) { - sendEvent("tts-progress", utteranceId); + WritableMap params = Arguments.createMap(); + params.putString("utteranceId", utteranceId); + params.putInt("start", start); + params.putInt("end", end); + params.putInt("frame", frame); + sendEvent("tts-progress", params); } }); } @@ -512,6 +517,10 @@ private int speak(String utterance, String utteranceId, ReadableMap inputParams) private void sendEvent(String eventName, String utteranceId) { WritableMap params = Arguments.createMap(); params.putString("utteranceId", utteranceId); + sendEvent(eventName, params); + } + + private void sendEvent(String eventName, WritableMap params) { getReactApplicationContext() .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) .emit(eventName, params);