react-native-davoice-tts 1.0.39 → 1.0.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- 715d5d23b48a82519e826c8c574071d2 tts-1.0.0.aar
1
+ 7e2cece002e93d8b58526eb8a8b64dfc tts-1.0.0.aar
@@ -1 +1 @@
1
- 409267c90cbc3d35d2903bc8509ec6c5c1364720 tts-1.0.0.aar
1
+ 0bc26879bfc87aa9a9698b4d9ecfaf93de4abea0 tts-1.0.0.aar
@@ -1,3 +1,4 @@
1
+ //DaVoiceTTSBridge.java
1
2
  package com.davoice.tts.rn;
2
3
 
3
4
  import com.davoice.tts.DaVoiceTTSInterface; // core wrapper with all init logic
@@ -11,15 +12,18 @@ import com.facebook.react.bridge.ReadableMap;
11
12
  * Minimal RN bridge:
12
13
  * NativeModules.DaVoiceTTSBridge.initTTS(modelName)
13
14
  * NativeModules.DaVoiceTTSBridge.speak(text, speakerId)
14
- *
15
+ * NativeModules.DaVoiceTTSBridge.stopSpeaking()
16
+ * // JS listens via new NativeEventEmitter(DaVoiceTTSBridge).addListener('onFinishedSpeaking', ...)
15
17
  * Everything else is handled by DaVoiceTTSInterface.
16
18
  */
17
19
  public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
18
20
 
19
21
  private final DaVoiceTTSInterface tts;
22
+ private final ReactApplicationContext reactCtx;
20
23
 
21
24
  public DaVoiceTTSBridge(ReactApplicationContext context) {
22
25
  super(context);
26
+ this.reactCtx = context;
23
27
  this.tts = new DaVoiceTTSInterface(context);
24
28
  }
25
29
 
@@ -28,6 +32,19 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
28
32
  return "DaVoiceTTSBridge";
29
33
  }
30
34
 
35
+ // ---- helpers ----
36
+
37
+ private void sendEvent(String name, @Nullable WritableMap params) {
38
+ // Emit on UI thread to be safe
39
+ reactCtx.runOnUiQueueThread(() ->
40
+ reactCtx
41
+ .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
42
+ .emit(name, params)
43
+ );
44
+ }
45
+
46
+ // ---- API ----
47
+
31
48
  @ReactMethod
32
49
  public void initTTS(ReadableMap config, Promise promise) {
33
50
  try {
@@ -43,6 +60,11 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
43
60
  "phonemes_dir" // asset dir name (AAR copies recursively)
44
61
  );
45
62
 
63
+ // Hook native → JS finished event
64
+ tts.setOnFinishedSpeakingListenerJava(() -> {
65
+ // no payload required; JS just needs the signal
66
+ sendEvent("onFinishedSpeaking", null);
67
+ });
46
68
 
47
69
  boolean ok = tts.initTTS(cfg);
48
70
  if (!ok) {
@@ -65,6 +87,16 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
65
87
  }
66
88
  }
67
89
 
90
+ @ReactMethod
91
+ public void stopSpeaking(Promise promise) {
92
+ try {
93
+ tts.stopSpeaking();
94
+ promise.resolve(null);
95
+ } catch (Exception e) {
96
+ promise.reject("StopError", e.getMessage(), e);
97
+ }
98
+ }
99
+
68
100
  // RN event API stubs (avoid warnings if JS subscribes)
69
101
  @ReactMethod public void addListener(String eventName) { /* no-op */ }
70
102
  @ReactMethod public void removeListeners(double count) { /* no-op */ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-davoice-tts",
3
- "version": "1.0.39",
3
+ "version": "1.0.41",
4
4
  "description": "tts library for React Native",
5
5
  "main": "tts/index.js",
6
6
  "types": "tts/index.d.ts",