react-native-davoice-tts 1.0.325 → 1.0.326

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.
Files changed (19) hide show
  1. package/TTSRNBridge.podspec +1 -1
  2. package/android/src/main/java/com/davoice/stt/rn/STTModule.kt +35 -12
  3. package/ios/SpeechBridge/SpeechBridge.m +87 -1
  4. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DavoiceTTS +0 -0
  5. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.abi.json +8777 -8756
  6. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.private.swiftinterface +49 -49
  7. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftinterface +49 -49
  8. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DavoiceTTS +0 -0
  9. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.abi.json +8186 -8165
  10. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +52 -52
  11. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftinterface +52 -52
  12. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.abi.json +8186 -8165
  13. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +52 -52
  14. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +52 -52
  15. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeDirectory +0 -0
  16. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeRequirements-1 +0 -0
  17. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeResources +24 -24
  18. package/package.json +1 -1
  19. package/speech/index.ts +93 -0
@@ -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.207" # Update to your package version
5
+ s.version = "1.0.208" # 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 .
@@ -35,6 +35,21 @@ class STTModule(private val rc: ReactApplicationContext)
35
35
  return stt!!
36
36
  }
37
37
 
38
+ private fun readOnboardingJson(options: ReadableMap?): String? {
39
+ var onboardingJson: String? = null
40
+ try {
41
+ if (options != null && options.hasKey("onboardingJsonPath") && !options.isNull("onboardingJsonPath")) {
42
+ val p = options.getString("onboardingJsonPath")
43
+ if (!p.isNullOrBlank()) {
44
+ onboardingJson = java.io.File(p).readText(Charsets.UTF_8)
45
+ }
46
+ }
47
+ } catch (_: Throwable) {
48
+ onboardingJson = null
49
+ }
50
+ return onboardingJson
51
+ }
52
+
38
53
  // ===== JS API =====
39
54
 
40
55
  @ReactMethod
@@ -66,22 +81,18 @@ class STTModule(private val rc: ReactApplicationContext)
66
81
  // ANDROID expects (locale, options, callback) like @react-native-voice
67
82
  @ReactMethod
68
83
  fun startSpeech(locale: String?, options: ReadableMap, cb: Callback) {
69
- var onboardingJson: String? = null
70
- try {
71
- if (options.hasKey("onboardingJsonPath") && !options.isNull("onboardingJsonPath")) {
72
- val p = options.getString("onboardingJsonPath")
73
- if (!p.isNullOrBlank()) {
74
- onboardingJson = java.io.File(p).readText(Charsets.UTF_8)
75
- }
76
- }
77
- } catch (_: Throwable) {
78
- onboardingJson = null
79
- }
80
-
84
+ val onboardingJson = readOnboardingJson(options)
81
85
  ensure().startSpeech(locale, onboardingJson, null)
82
86
  cb.invoke(false) // parity with voice: callback(false) on success
83
87
  }
84
88
 
89
+ @ReactMethod
90
+ fun initWithoutModel(locale: String?, options: ReadableMap?, cb: Callback) {
91
+ val onboardingJson = readOnboardingJson(options)
92
+ ensure().startSpeech(locale, onboardingJson, null)
93
+ cb.invoke(false)
94
+ }
95
+
85
96
  @ReactMethod
86
97
  fun stopSpeech(cb: Callback) {
87
98
  stt?.stopSpeech()
@@ -101,6 +112,18 @@ class STTModule(private val rc: ReactApplicationContext)
101
112
  cb.invoke(false)
102
113
  }
103
114
 
115
+ @ReactMethod
116
+ fun destroyWihtouModel(cb: Callback) {
117
+ stt?.destroySpeech()
118
+ stt = null
119
+ cb.invoke(false)
120
+ }
121
+
122
+ @ReactMethod
123
+ fun destroyWithoutModel(cb: Callback) {
124
+ destroyWihtouModel(cb)
125
+ }
126
+
104
127
  @ReactMethod
105
128
  fun isSpeechAvailable(p: Promise) {
106
129
  STT.isSpeechAvailable(rc) { ok -> p.resolve(ok) }
@@ -510,6 +510,11 @@ RCT_EXPORT_METHOD(initAll:(NSDictionary *)opts
510
510
  }
511
511
  NSLog(@"[TTS] INIT: modelURL == %@", modelURL);
512
512
 
513
+ if (self.tts) {
514
+ @try { [self.tts stopSpeaking]; [self.tts destroy]; } @catch (__unused id e) {}
515
+ self.tts = nil;
516
+ }
517
+
513
518
  dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0), ^{
514
519
  NSError *err = nil;
515
520
  DaVoiceTTS *tts = [[DaVoiceTTS alloc] initWithModel:modelURL error:&err];
@@ -541,6 +546,55 @@ RCT_EXPORT_METHOD(initAll:(NSDictionary *)opts
541
546
  });
542
547
  }
543
548
 
549
+ RCT_EXPORT_METHOD(initWithoutModel:(NSDictionary *)opts
550
+ resolver:(RCTPromiseResolveBlock)resolve
551
+ rejecter:(RCTPromiseRejectBlock)reject)
552
+ {
553
+ dispatch_async(dispatch_get_main_queue(), ^{
554
+ if (self.initializing) { resolve(@"already_initializing"); return; }
555
+ if (!self.tts) {
556
+ reject(@"no_tts", @"initWithoutModel() requires a successful initAll() first", nil);
557
+ return;
558
+ }
559
+ if (self.initialized && self.stt) {
560
+ resolve(@"already_initialized");
561
+ return;
562
+ }
563
+
564
+ self.initializing = YES;
565
+ self.sttEngineHot = NO;
566
+
567
+ NSString *locale = opts[@"locale"] ?: @"en-US";
568
+ NSString *onboardingJsonPath = opts[@"onboardingJsonPath"];
569
+ NSNumber *timeoutMs = opts[@"timeoutMs"];
570
+
571
+ @try { [self.stt destroySpeech:nil]; } @catch (__unused id e) {}
572
+ self.stt = nil;
573
+
574
+ [self ensureSTT];
575
+ if (onboardingJsonPath && (id)onboardingJsonPath != [NSNull null] && onboardingJsonPath.length > 0) {
576
+ [self.stt startSpeechWithLocaleStr:locale onboardingJsonPath:onboardingJsonPath];
577
+ } else {
578
+ [self.stt startSpeechWithLocaleStr:locale];
579
+ }
580
+
581
+ [self waitForSTTEngineHotWithTimeoutMs:timeoutMs completion:^(BOOL ok) {
582
+ if (!ok) {
583
+ self.initializing = NO;
584
+ self.initialized = NO;
585
+ self.sttEngineHot = NO;
586
+ @try { [self.stt destroySpeech:nil]; } @catch (__unused id e) {}
587
+ self.stt = nil;
588
+ reject(@"stt_init_timeout", @"STT did not become ready before timeout", nil);
589
+ return;
590
+ }
591
+ self.initialized = YES;
592
+ self.initializing = NO;
593
+ resolve(@"initialized_without_model");
594
+ }];
595
+ });
596
+ }
597
+
544
598
  // --- SpeechRecognitionLite pause/unpause (counter-based) ---
545
599
 
546
600
  RCT_EXPORT_METHOD(pauseSpeechRecognitionLite:(RCTResponseSenderBlock)callback)
@@ -694,7 +748,7 @@ RCT_EXPORT_METHOD(destroyAll:(RCTPromiseResolveBlock)resolve
694
748
  rejecter:(RCTPromiseRejectBlock)reject)
695
749
  {
696
750
  dispatch_async(dispatch_get_main_queue(), ^{
697
- if (!self.initialized && !self.initializing) {
751
+ if (!self.tts && !self.stt && !self.initialized && !self.initializing) {
698
752
  resolve(@"already_destroyed");
699
753
  return;
700
754
  }
@@ -715,6 +769,38 @@ RCT_EXPORT_METHOD(destroyAll:(RCTPromiseResolveBlock)resolve
715
769
  });
716
770
  }
717
771
 
772
+ RCT_EXPORT_METHOD(destroyWihtouModel:(RCTPromiseResolveBlock)resolve
773
+ rejecter:(RCTPromiseRejectBlock)reject)
774
+ {
775
+ dispatch_async(dispatch_get_main_queue(), ^{
776
+ if (!self.tts) {
777
+ reject(@"no_tts", @"destroyWihtouModel() requires a successful initAll() first", nil);
778
+ return;
779
+ }
780
+
781
+ if (!self.stt && !self.initialized && !self.initializing) {
782
+ resolve(@"already_destroyed_without_model");
783
+ return;
784
+ }
785
+
786
+ self.initializing = YES;
787
+
788
+ @try { [self.stt destroySpeech:nil]; } @catch (__unused id e) {}
789
+ self.stt = nil;
790
+
791
+ self.sttEngineHot = NO;
792
+ self.initialized = NO;
793
+ self.initializing = NO;
794
+ resolve(@"destroyed_without_model");
795
+ });
796
+ }
797
+
798
+ RCT_EXPORT_METHOD(destroyWithoutModel:(RCTPromiseResolveBlock)resolve
799
+ rejecter:(RCTPromiseRejectBlock)reject)
800
+ {
801
+ [self destroyWihtouModel:resolve rejecter:reject];
802
+ }
803
+
718
804
  #pragma mark - Convenience passthroughs (optional)
719
805
 
720
806
  RCT_EXPORT_METHOD(startSpeech:(NSString *)locale