react-native-davoice 1.0.11 → 1.0.13

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 (22) hide show
  1. package/TTSRNBridge.podspec +1 -1
  2. package/android/libs/com/davoice/tts/1.0.0/tts-1.0.0.aar +0 -0
  3. package/android/libs/com/davoice/tts/1.0.0/tts-1.0.0.aar.md5 +1 -1
  4. package/android/libs/com/davoice/tts/1.0.0/tts-1.0.0.aar.sha1 +1 -1
  5. package/android/src/main/java/com/davoice/stt/rn/STTModule.kt +35 -12
  6. package/ios/SpeechBridge/SpeechBridge.m +148 -1
  7. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DavoiceTTS +0 -0
  8. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.abi.json +5586 -5523
  9. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.private.swiftinterface +39 -39
  10. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftinterface +39 -39
  11. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DavoiceTTS +0 -0
  12. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.abi.json +7793 -7730
  13. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +82 -82
  14. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftinterface +82 -82
  15. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.abi.json +7793 -7730
  16. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +82 -82
  17. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +82 -82
  18. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeDirectory +0 -0
  19. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeRequirements-1 +0 -0
  20. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeResources +24 -24
  21. package/package.json +1 -1
  22. package/speech/index.ts +137 -3
package/speech/index.ts CHANGED
@@ -34,6 +34,12 @@ function sleep(ms: number) {
34
34
  return new Promise<void>((r) => setTimeout(r, ms));
35
35
  }
36
36
 
37
+ let speechOpSeq = 0;
38
+ function nextSpeechOpId(prefix: string) {
39
+ speechOpSeq += 1;
40
+ return `${prefix}-${speechOpSeq}-${Date.now()}`;
41
+ }
42
+
37
43
  // If you use typed-array -> base64, Buffer is convenient (works in RN)
38
44
  let toBase64: (u8: Uint8Array) => string;
39
45
  try {
@@ -184,6 +190,8 @@ class Speech {
184
190
  // top of file (new state)
185
191
  private lastLocale: string | null = null;
186
192
  private lastModel: string | null = null;
193
+ private lastOnboardingJsonPath: string | null = null;
194
+ private hasCompletedFullInit = false;
187
195
  private iosTtsOnly = false; // when true, use NativeTTS directly on iOS
188
196
 
189
197
 
@@ -386,11 +394,13 @@ class Speech {
386
394
 
387
395
  this.lastLocale = opts.locale;
388
396
  this.lastModel = modelPath;
397
+ this.lastOnboardingJsonPath = opts.onboardingJsonPath ?? null;
389
398
 
390
399
  if (Platform.OS === 'ios' && NativeSpeech?.initAll) {
391
400
  this.iosTtsOnly = false; // full unified mode
392
401
  this.teardownListeners(); // re-wire listeners for unified
393
402
  const r = await NativeSpeech.initAll({ ...opts, model: modelPath });
403
+ this.hasCompletedFullInit = true;
394
404
  this.ensureListeners();
395
405
  return r;
396
406
  }
@@ -440,6 +450,7 @@ class Speech {
440
450
  const modelExt = this.resolveModelExt(opts.model);
441
451
  console.log('[MODELDBG] initAll.modelExt (resolved)=', modelExt);
442
452
  await NativeTTS.initTTS({ model: modelPath, modelExt });
453
+ this.hasCompletedFullInit = true;
443
454
  }
444
455
 
445
456
  async destroyAll() {
@@ -450,6 +461,7 @@ class Speech {
450
461
  // iOS unified
451
462
  if (Platform.OS === 'ios' && NativeSpeech?.destroyAll) {
452
463
  const r = await NativeSpeech.destroyAll();
464
+ this.hasCompletedFullInit = false;
453
465
  this.iosTtsOnly = false;
454
466
  this.lastLocale = this.lastLocale ?? null;
455
467
  this.teardownListeners();
@@ -463,10 +475,97 @@ class Speech {
463
475
  NativeSTT.destroySpeech(() => res());
464
476
  });
465
477
  } catch {}
478
+ this.hasCompletedFullInit = false;
466
479
  this.teardownListeners();
467
480
  return 'Destroyed';
468
481
  }
469
482
 
483
+ async initWithoutModel() {
484
+ if (!this.hasCompletedFullInit || !this.lastLocale) {
485
+ throw new Error('initWithoutModel() requires a successful initAll() first.');
486
+ }
487
+
488
+ if (Platform.OS === 'ios' && NativeSpeech?.initWithoutModel) {
489
+ this.iosTtsOnly = false;
490
+ this.teardownListeners();
491
+ const r = await NativeSpeech.initWithoutModel({
492
+ locale: this.lastLocale,
493
+ onboardingJsonPath: this.lastOnboardingJsonPath,
494
+ });
495
+ this.ensureListeners();
496
+ return r;
497
+ }
498
+
499
+ if (!NativeSTT) {
500
+ throw new Error('Missing native STT bridge.');
501
+ }
502
+
503
+ this.ensureListeners();
504
+ return new Promise<void>((resolve, reject) => {
505
+ try {
506
+ if (typeof NativeSTT.initWithoutModel === 'function') {
507
+ NativeSTT.initWithoutModel(
508
+ this.lastLocale,
509
+ { onboardingJsonPath: this.lastOnboardingJsonPath ?? null },
510
+ (err: string) => (err ? reject(new Error(err)) : resolve()),
511
+ );
512
+ return;
513
+ }
514
+
515
+ if (Platform.OS === 'android') {
516
+ NativeSTT.startSpeech(
517
+ this.lastLocale,
518
+ {
519
+ EXTRA_LANGUAGE_MODEL: 'LANGUAGE_MODEL_FREE_FORM',
520
+ EXTRA_MAX_RESULTS: 5,
521
+ EXTRA_PARTIAL_RESULTS: true,
522
+ REQUEST_PERMISSIONS_AUTO: true,
523
+ onboardingJsonPath: this.lastOnboardingJsonPath ?? null,
524
+ },
525
+ (err: string) => (err ? reject(new Error(err)) : resolve()),
526
+ );
527
+ return;
528
+ }
529
+
530
+ NativeSTT.startSpeech(this.lastLocale, (err: string) =>
531
+ err ? reject(new Error(err)) : resolve(),
532
+ );
533
+ } catch (e) {
534
+ reject(e as any);
535
+ }
536
+ });
537
+ }
538
+
539
+ async destroyWihtouModel() {
540
+ if (!this.hasCompletedFullInit) {
541
+ throw new Error('destroyWihtouModel() requires a successful initAll() first.');
542
+ }
543
+
544
+ if (Platform.OS === 'ios' && NativeSpeech?.destroyWihtouModel) {
545
+ return NativeSpeech.destroyWihtouModel();
546
+ }
547
+
548
+ return new Promise<void>((resolve) => {
549
+ try {
550
+ if (typeof NativeSTT?.destroyWihtouModel === 'function') {
551
+ NativeSTT.destroyWihtouModel(() => resolve());
552
+ return;
553
+ }
554
+ if (!NativeSTT?.destroySpeech) {
555
+ resolve();
556
+ return;
557
+ }
558
+ NativeSTT.destroySpeech(() => resolve());
559
+ } catch {
560
+ resolve();
561
+ }
562
+ });
563
+ }
564
+
565
+ async destroyWithoutModel() {
566
+ return this.destroyWihtouModel();
567
+ }
568
+
470
569
  // ---------- STT ----------
471
570
  async start(locale: string, options: Record<string, any> = {}) {
472
571
  this.ensureListeners();
@@ -524,9 +623,11 @@ class Speech {
524
623
  return this.start(locale);
525
624
  }
526
625
 
527
- // XXX BUG THE NATIVE SIDE DOES NOT REALLY AWAITS
626
+ // TODO: CHECK THE NATIVE SIDE DOES NOT REALLY AWAITS
528
627
  async pauseSpeechRecognition(): Promise<void> {
529
628
  this.logCall('pauseSpeechRecognitionLite');
629
+ const opId = nextSpeechOpId('pause-stt');
630
+ const startedAt = Date.now();
530
631
 
531
632
  const mod: any = Platform.OS === 'ios' ? NativeSpeech : NativeSTT;
532
633
  const fn = mod?.pauseSpeechRecognitionLite;
@@ -537,7 +638,9 @@ class Speech {
537
638
  }
538
639
 
539
640
  if (Platform.OS === 'ios' && typeof mod?.pauseSpeechRecognitionLiteAsync === 'function') {
641
+ dbg('[pauseSpeechRecognitionLiteAsync] begin', { opId, timeoutMs: 1500 });
540
642
  const result = await mod.pauseSpeechRecognitionLiteAsync(1500);
643
+ dbg('[pauseSpeechRecognitionLiteAsync] resolved', { opId, elapsedMs: Date.now() - startedAt, result });
541
644
  if (result?.ok === false) dbgErr('pauseSpeechRecognitionLiteAsync failed', result?.reason);
542
645
  return;
543
646
  }
@@ -569,8 +672,14 @@ class Speech {
569
672
  });
570
673
  }
571
674
 
572
- async unPauseSpeechRecognition(times: number, preFetchMs: number = 0): Promise<void> {
675
+ async unPauseSpeechRecognition(
676
+ times: number,
677
+ preFetchMs: number = 0,
678
+ timeoutMs: number = 2500,
679
+ ): Promise<void> {
573
680
  this.logCall('unPauseSpeechRecognitionLite', { times, preFetchMs });
681
+ const opId = nextSpeechOpId('unpause-stt');
682
+ const startedAt = Date.now();
574
683
 
575
684
  const mod: any = Platform.OS === 'ios' ? NativeSpeech : NativeSTT;
576
685
  const fn = mod?.unPauseSpeechRecognitionLite;
@@ -581,7 +690,15 @@ class Speech {
581
690
  }
582
691
 
583
692
  if (Platform.OS === 'ios' && typeof mod?.unPauseSpeechRecognitionLiteAsync === 'function') {
584
- const result = await mod.unPauseSpeechRecognitionLiteAsync(times, preFetchMs, 2500);
693
+ dbg('[unPauseSpeechRecognitionLiteAsync] begin', { opId, times, preFetchMs, timeoutMs });
694
+ const result = await mod.unPauseSpeechRecognitionLiteAsync(times, preFetchMs, timeoutMs);
695
+ dbg('[unPauseSpeechRecognitionLiteAsync] resolved', {
696
+ opId,
697
+ times,
698
+ preFetchMs,
699
+ elapsedMs: Date.now() - startedAt,
700
+ result,
701
+ });
585
702
  if (result?.ok === false) dbgErr('unPauseSpeechRecognitionLiteAsync failed', result?.reason);
586
703
  return;
587
704
  }
@@ -790,6 +907,23 @@ class Speech {
790
907
  return results.every(Boolean);
791
908
  }
792
909
 
910
+ async setAECEnabled(enabled: boolean): Promise<void> {
911
+ const value = !!enabled;
912
+
913
+ if (Platform.OS === 'ios' && NativeSpeech?.setAECEnabled) {
914
+ await NativeSpeech.setAECEnabled(value);
915
+ return;
916
+ }
917
+
918
+ if (NativeSTT?.setAECEnabled) {
919
+ await NativeSTT.setAECEnabled(value);
920
+ return;
921
+ }
922
+ console.warn("AEC not supported on this platform");
923
+ return;
924
+ //throw new Error('setAECEnabled not available on this platform.');
925
+ }
926
+
793
927
  // ---------- TTS ----------
794
928
  async initTTS(modelOrConfig: ModelRef | { model: ModelRef }) {
795
929
  const cfg =