react-native-davoice-tts 1.0.275 → 1.0.276

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.148" # Update to your package version
5
+ s.version = "1.0.149" # 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 .
@@ -160,8 +160,9 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
160
160
  !s.toLowerCase(Locale.US).startsWith("file:") &&
161
161
  !s.toLowerCase(Locale.US).startsWith("content:") &&
162
162
  !s.toLowerCase(Locale.US).startsWith("asset:") &&
163
- // ✅ IMPORTANT: RN release resource names are NOT AssetManager assets
164
- !s.startsWith("assets_");
163
+ // ✅ IMPORTANT: RN release resource names are NOT AssetManager assets (res/raw)
164
+ !s.startsWith("assets_") && !s.startsWith("src_assets_");
165
+
165
166
 
166
167
  final String modelName;
167
168
  if (looksLikePlainAssetPath) {
@@ -241,6 +242,24 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
241
242
  }
242
243
  }
243
244
 
245
+ private File tryCopyRawToCacheIfExists(String name, @Nullable String defaultExt) {
246
+ if (name == null) return null;
247
+ final String s = name.trim();
248
+ if (s.isEmpty()) return null;
249
+
250
+ // Only reasonable resource entry names (no scheme, no slashes)
251
+ if (s.contains("://") || s.contains("/") || s.contains("\\") || s.startsWith(".")) return null;
252
+
253
+ // IMPORTANT: res/raw entry names have NO extension in Android resources
254
+ // If caller passed "foo.wav", strip extension for resource lookup.
255
+ String rawName = s;
256
+ int dot = rawName.lastIndexOf('.');
257
+ if (dot > 0) rawName = rawName.substring(0, dot);
258
+
259
+ File out = copyRawResourceToCache(rawName, defaultExt);
260
+ return (out != null && out.exists()) ? out : null;
261
+ }
262
+
244
263
  // Resolve pathOrURL -> local readable File (supports http(s), asset:/, file://, plain path)
245
264
  // defaultExt can be "wav", "onnx", etc (used for tmp file naming when extension missing)
246
265
  private File resolveToLocalFileForRead(String pathOrURL, @Nullable String defaultExt) throws Exception {
@@ -248,6 +267,16 @@ public class DaVoiceTTSBridge extends ReactContextBaseJavaModule {
248
267
  final String s = pathOrURL.trim();
249
268
  if (s.isEmpty()) return null;
250
269
 
270
+ // 0) RN bundled assets on Android are usually in res/raw and resolve to a resource entry name
271
+ // like "assets_*" OR "src_assets_*" (no extension). Try res/raw first.
272
+ {
273
+ File out = tryCopyRawToCacheIfExists(s, defaultExt);
274
+ if (out != null) {
275
+ Log.i(TAG, "resolveToLocalFileForRead: copied res/raw '" + s + "' -> " + out.getAbsolutePath());
276
+ return out;
277
+ }
278
+ }
279
+
251
280
  // 0) RN bundled assets resolve to res/raw names like "assets_cashregistersound" (NO extension).
252
281
  // They are NOT APK /assets files. Handle exactly like react-native-sound: Resources.getIdentifier(..., "raw", ...)
253
282
  if (s.startsWith("assets_")) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-davoice-tts",
3
- "version": "1.0.275",
3
+ "version": "1.0.276",
4
4
  "description": "tts library for React Native",
5
5
  "main": "tts/index.js",
6
6
  "types": "tts/index.d.ts",
package/speech/index.ts CHANGED
@@ -761,6 +761,11 @@ class Speech {
761
761
  console.log('[Speech.playWav] resolveAssetSource ->', asset);
762
762
 
763
763
  let realPath = asset?.uri ?? pathOrURL;
764
+ if (Platform.OS === 'android' && typeof asset?.uri === 'string') {
765
+ // Pass raw resource entry name through (native will resolve via res/raw)
766
+ realPath = asset.uri;
767
+ }
768
+
764
769
  console.log('[Speech.playWav] resolved realPath:', realPath);
765
770
 
766
771
  if (typeof realPath !== 'string') {