react-native-davoice-tts 1.0.40 → 1.0.42

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,27 +1,24 @@
1
- //DaVoiceTTSBridge.java
2
1
  package com.davoice.tts.rn;
3
2
 
4
- import com.davoice.tts.DaVoiceTTSInterface; // core wrapper with all init logic
3
+ import androidx.annotation.Nullable; // add
5
4
  import com.facebook.react.bridge.Promise;
6
5
  import com.facebook.react.bridge.ReactApplicationContext;
7
6
  import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
7
  import com.facebook.react.bridge.ReactMethod;
9
8
  import com.facebook.react.bridge.ReadableMap;
9
+ import com.facebook.react.bridge.WritableMap; // ✅ add
10
+ import com.facebook.react.modules.core.DeviceEventManagerModule; // ✅ add
11
+
12
+ import com.davoice.tts.DaVoiceTTSInterface; // keep
10
13
 
11
- /**
12
- * Minimal RN bridge:
13
- * NativeModules.DaVoiceTTSBridge.initTTS(modelName)
14
- * NativeModules.DaVoiceTTSBridge.speak(text, speakerId)
15
- * NativeModules.DaVoiceTTSBridge.stopSpeaking()
16
- * // JS listens via new NativeEventEmitter(DaVoiceTTSBridge).addListener('onFinishedSpeaking', ...)
17
- * Everything else is handled by DaVoiceTTSInterface.
18
- */
19
14
  public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
20
15
 
21
16
  private final DaVoiceTTSInterface tts;
17
+ private final ReactApplicationContext reactCtx;
22
18
 
23
19
  public DaVoiceTTSBridge(ReactApplicationContext context) {
24
20
  super(context);
21
+ this.reactCtx = context;
25
22
  this.tts = new DaVoiceTTSInterface(context);
26
23
  }
27
24
 
@@ -30,10 +27,7 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
30
27
  return "DaVoiceTTSBridge";
31
28
  }
32
29
 
33
- // ---- helpers ----
34
-
35
30
  private void sendEvent(String name, @Nullable WritableMap params) {
36
- // Emit on UI thread to be safe
37
31
  reactCtx.runOnUiQueueThread(() ->
38
32
  reactCtx
39
33
  .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
@@ -41,8 +35,6 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
41
35
  );
42
36
  }
43
37
 
44
- // ---- API ----
45
-
46
38
  @ReactMethod
47
39
  public void initTTS(ReadableMap config, Promise promise) {
48
40
  try {
@@ -51,19 +43,16 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
51
43
  return;
52
44
  }
53
45
  final String modelName = config.getString("model");
54
- // AAR handles the rest (tokens=<model>.json, espeak dir, etc.)
55
- DaVoiceTTSInterface.Config cfg = new DaVoiceTTSInterface.Config(
56
- modelName, // e.g. "model.onnx"
57
- "en-US", // default voice (ignored/overridden by AAR if needed)
58
- "phonemes_dir" // asset dir name (AAR copies recursively)
59
- );
60
46
 
61
- // Hook native JS finished event
62
- tts.setOnFinishedSpeakingListenerJava(() -> {
63
- // no payload required; JS just needs the signal
64
- sendEvent("onFinishedSpeaking", null);
65
- });
47
+ // 1) attach listener (works even if called before init)
48
+ tts.setOnFinishedSpeakingListenerJava(() -> sendEvent("onFinishedSpeaking", null));
66
49
 
50
+ // 2) init
51
+ DaVoiceTTSInterface.Config cfg = new DaVoiceTTSInterface.Config(
52
+ modelName,
53
+ "en-US",
54
+ "phonemes_dir"
55
+ );
67
56
  boolean ok = tts.initTTS(cfg);
68
57
  if (!ok) {
69
58
  promise.reject("InitFailed", "Engine/TTS init failed");
@@ -95,7 +84,7 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
95
84
  }
96
85
  }
97
86
 
98
- // RN event API stubs (avoid warnings if JS subscribes)
87
+ // RN event API stubs
99
88
  @ReactMethod public void addListener(String eventName) { /* no-op */ }
100
89
  @ReactMethod public void removeListeners(double count) { /* no-op */ }
101
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-davoice-tts",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "description": "tts library for React Native",
5
5
  "main": "tts/index.js",
6
6
  "types": "tts/index.d.ts",