react-native-davoice-tts 1.0.276 → 1.0.277

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.
@@ -2,7 +2,7 @@ require 'json'
2
2
 
3
3
  Pod::Spec.new do |s|
4
4
  s.name = "TTSRNBridge"
5
- s.version = "1.0.149" # Update to your package version
5
+ s.version = "1.0.150" # Update to your package version
6
6
  s.summary = "TTS for React Native."
7
7
  s.description = <<-DESC
8
8
  A React Native module for tts .
@@ -1 +1 @@
1
- 0f748bfafef7fdc5d03bbefdb41bfcdd tts-1.0.0.aar
1
+ faa5cade26dcaf91c23989be5442e102 tts-1.0.0.aar
@@ -1 +1 @@
1
- 39cfd203581433a5e0e36e57abd911bcb30ea922 tts-1.0.0.aar
1
+ d00ea3703391db2243e11526aebb47f37e146b97 tts-1.0.0.aar
@@ -24,10 +24,14 @@ import android.content.res.AssetFileDescriptor;
24
24
  import java.io.IOException;
25
25
  import java.net.URL;
26
26
  import java.net.URLConnection;
27
+ import com.google.android.play.core.assetpacks.AssetPackLocation;
28
+ import com.google.android.play.core.assetpacks.AssetPackManager;
29
+ import com.google.android.play.core.assetpacks.AssetPackManagerFactory;
27
30
 
28
31
 
29
32
  import com.davoice.tts.DaVoiceTTSInterface;
30
33
 
34
+
31
35
  public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
32
36
 
33
37
  private final DaVoiceTTSInterface tts;
@@ -166,8 +170,13 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
166
170
 
167
171
  final String modelName;
168
172
  if (looksLikePlainAssetPath) {
169
- // PASS THROUGH (old working behavior)
170
- modelName = s;
173
+ File f = resolvePlainModelToFile(s, modelExt != null ? modelExt : "onnx");
174
+ if (f != null) {
175
+ modelName = f.getAbsolutePath(); // pass a real filesystem path to the engine
176
+ } else {
177
+ // Last resort: keep old behavior (in case engine itself can open via AssetManager)
178
+ modelName = s;
179
+ }
171
180
  } else {
172
181
  // Use provided extension when RN gave us assets_* (no ext), otherwise fall back safely.
173
182
  final String ext = (modelExt != null && !modelExt.isEmpty()) ? modelExt : "onnx";
@@ -198,6 +207,53 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
198
207
  }
199
208
  }
200
209
 
210
+ /** models_pack → absolute file (if installed), else null */
211
+ @Nullable
212
+ private File getFileFromAssetPack(String relative) {
213
+ try {
214
+ AssetPackManager apm = AssetPackManagerFactory.getInstance(reactCtx.getApplicationContext());
215
+ AssetPackLocation loc = apm.getPackLocation("models_pack");
216
+ if (loc == null) return null;
217
+ String root = loc.assetsPath(); // .../assets
218
+ if (root == null) return null;
219
+
220
+ // Accept both "model.onnx" and "models/model.onnx"
221
+ String rel = relative.startsWith("models/") ? relative : ("models/" + relative);
222
+ File f = new File(root, rel);
223
+ return f.exists() ? f : null;
224
+ } catch (Throwable t) {
225
+ Log.w(TAG, "getFileFromAssetPack failed: " + t.getMessage());
226
+ return null;
227
+ }
228
+ }
229
+
230
+ /** If in res/raw, copy to cache and return File; else null. */
231
+ @Nullable
232
+ private File tryResolveFromResRawToCache(String nameMaybeWithExt, @Nullable String defaultExt) {
233
+ // Accept "model.onnx" or "model"
234
+ String rawName = nameMaybeWithExt;
235
+ if (rawName == null) return null;
236
+ rawName = rawName.trim();
237
+ if (rawName.isEmpty()) return null;
238
+ int dot = rawName.lastIndexOf('.');
239
+ if (dot > 0) rawName = rawName.substring(0, dot);
240
+ return copyRawResourceToCache(rawName, defaultExt);
241
+ }
242
+
243
+ /** For plain names, resolve to an absolute File using res/raw or asset-pack. */
244
+ @Nullable
245
+ private File resolvePlainModelToFile(String plain, @Nullable String defaultExt) {
246
+ // 1) res/raw (RN may map bundled assets there in release)
247
+ File fromRaw = tryResolveFromResRawToCache(plain, defaultExt);
248
+ if (fromRaw != null && fromRaw.exists()) return fromRaw;
249
+
250
+ // 2) fast-follow asset pack
251
+ File fromPack = getFileFromAssetPack(plain);
252
+ if (fromPack != null && fromPack.exists()) return fromPack;
253
+
254
+ return null;
255
+ }
256
+
201
257
  @ReactMethod
202
258
  public void speak(String text, int speakerId, double speed, Promise promise) {
203
259
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-davoice-tts",
3
- "version": "1.0.276",
3
+ "version": "1.0.277",
4
4
  "description": "tts library for React Native",
5
5
  "main": "tts/index.js",
6
6
  "types": "tts/index.d.ts",