react-native-davoice 1.0.15 → 1.0.16

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.217" # Update to your package version
5
+ s.version = "1.0.218" # 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 .
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-davoice",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
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
@@ -126,6 +126,7 @@ class Speech {
126
126
  private ttsChain: Promise<void> = Promise.resolve();
127
127
  private ttsPendingResolve: (() => void) | null = null;
128
128
  private ttsPendingTimeout: any = null;
129
+ private sttTransitionChain: Promise<void> = Promise.resolve();
129
130
 
130
131
  private dbgAsset(label: string, x: any) {
131
132
  try {
@@ -161,6 +162,22 @@ class Speech {
161
162
  return (NativeTTS as any).speak(text, speakerId, s);
162
163
  }
163
164
 
165
+ private enqueueSttTransition(opId: string, kind: 'pause' | 'unpause', work: () => Promise<void>): Promise<void> {
166
+ const previous = this.sttTransitionChain.catch(() => {});
167
+ const run = previous.then(async () => {
168
+ dbg('[sttTransition] begin', { opId, kind });
169
+ try {
170
+ await work();
171
+ dbg('[sttTransition] end', { opId, kind });
172
+ } catch (e) {
173
+ dbgErr('[sttTransition] failed', { opId, kind, error: String(e) });
174
+ throw e;
175
+ }
176
+ });
177
+ this.sttTransitionChain = run.catch(() => {});
178
+ return run;
179
+ }
180
+
164
181
  private _speakAndWait(text: string, speakerId: number, s: number, timeoutMs = 600000) {
165
182
  return new Promise<void>((resolve, reject) => {
166
183
  this.ttsPendingResolve = resolve;
@@ -632,43 +649,45 @@ class Speech {
632
649
  const mod: any = Platform.OS === 'ios' ? NativeSpeech : NativeSTT;
633
650
  const fn = mod?.pauseSpeechRecognitionLite;
634
651
 
635
- if (!fn) {
636
- dbg(`pauseSpeechRecognitionLite not available on ${Platform.OS === 'ios' ? 'NativeSpeech' : 'NativeSTT'}`);
637
- return;
638
- }
652
+ await this.enqueueSttTransition(opId, 'pause', async () => {
653
+ if (!fn) {
654
+ dbg(`pauseSpeechRecognitionLite not available on ${Platform.OS === 'ios' ? 'NativeSpeech' : 'NativeSTT'}`);
655
+ return;
656
+ }
657
+
658
+ if (Platform.OS === 'ios' && typeof mod?.pauseSpeechRecognitionLiteAsync === 'function') {
659
+ dbg('[pauseSpeechRecognitionLiteAsync] begin', { opId, timeoutMs: 1500 });
660
+ const result = await mod.pauseSpeechRecognitionLiteAsync(1500);
661
+ dbg('[pauseSpeechRecognitionLiteAsync] resolved', { opId, elapsedMs: Date.now() - startedAt, result });
662
+ if (result?.ok === false) dbgErr('pauseSpeechRecognitionLiteAsync failed', result?.reason);
663
+ return;
664
+ }
665
+ if (Platform.OS === 'ios') {
666
+ await new Promise<void>((resolve, reject) => {
667
+ try {
668
+ fn.call(mod, (ok: boolean) => {
669
+ if (!ok) dbgErr('pauseSpeechRecognitionLite returned false');
670
+ resolve();
671
+ });
672
+ } catch (e) {
673
+ reject(e as any);
674
+ }
675
+ });
676
+ return;
677
+ }
639
678
 
640
- if (Platform.OS === 'ios' && typeof mod?.pauseSpeechRecognitionLiteAsync === 'function') {
641
- dbg('[pauseSpeechRecognitionLiteAsync] begin', { opId, timeoutMs: 1500 });
642
- const result = await mod.pauseSpeechRecognitionLiteAsync(1500);
643
- dbg('[pauseSpeechRecognitionLiteAsync] resolved', { opId, elapsedMs: Date.now() - startedAt, result });
644
- if (result?.ok === false) dbgErr('pauseSpeechRecognitionLiteAsync failed', result?.reason);
645
- return;
646
- }
647
- if (Platform.OS === 'ios') {
648
679
  await new Promise<void>((resolve, reject) => {
649
680
  try {
650
- fn.call(mod, (ok: boolean) => {
681
+ fn.call(mod, async (ok: boolean) => {
651
682
  if (!ok) dbgErr('pauseSpeechRecognitionLite returned false');
683
+ // ✅ ANDROID: small delay before resolving
684
+ if (Platform.OS === 'android') await sleep(500);
652
685
  resolve();
653
686
  });
654
687
  } catch (e) {
655
688
  reject(e as any);
656
689
  }
657
690
  });
658
- return;
659
- }
660
-
661
- await new Promise<void>((resolve, reject) => {
662
- try {
663
- fn.call(mod, async (ok: boolean) => {
664
- if (!ok) dbgErr('pauseSpeechRecognitionLite returned false');
665
- // ✅ ANDROID: small delay before resolving
666
- if (Platform.OS === 'android') await sleep(500);
667
- resolve();
668
- });
669
- } catch (e) {
670
- reject(e as any);
671
- }
672
691
  });
673
692
  }
674
693
 
@@ -684,64 +703,66 @@ class Speech {
684
703
  const mod: any = Platform.OS === 'ios' ? NativeSpeech : NativeSTT;
685
704
  const fn = mod?.unPauseSpeechRecognitionLite;
686
705
 
687
- if (!fn) {
688
- dbg(`unPauseSpeechRecognitionLite(times) not available on ${Platform.OS === 'ios' ? 'NativeSpeech' : 'NativeSTT'}`);
689
- return;
690
- }
706
+ await this.enqueueSttTransition(opId, 'unpause', async () => {
707
+ if (!fn) {
708
+ dbg(`unPauseSpeechRecognitionLite(times) not available on ${Platform.OS === 'ios' ? 'NativeSpeech' : 'NativeSTT'}`);
709
+ return;
710
+ }
691
711
 
692
- if (Platform.OS === 'ios' && typeof mod?.unPauseSpeechRecognitionLiteAsync === 'function') {
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
- });
702
- if (result?.ok === false) dbgErr('unPauseSpeechRecognitionLiteAsync failed', result?.reason);
703
- return;
704
- }
712
+ if (Platform.OS === 'ios' && typeof mod?.unPauseSpeechRecognitionLiteAsync === 'function') {
713
+ dbg('[unPauseSpeechRecognitionLiteAsync] begin', { opId, times, preFetchMs, timeoutMs });
714
+ const result = await mod.unPauseSpeechRecognitionLiteAsync(times, preFetchMs, timeoutMs);
715
+ dbg('[unPauseSpeechRecognitionLiteAsync] resolved', {
716
+ opId,
717
+ times,
718
+ preFetchMs,
719
+ elapsedMs: Date.now() - startedAt,
720
+ result,
721
+ });
722
+ if (result?.ok === false) dbgErr('unPauseSpeechRecognitionLiteAsync failed', result?.reason);
723
+ return;
724
+ }
705
725
 
706
- if (Platform.OS === 'ios') {
726
+ if (Platform.OS === 'ios') {
727
+ await new Promise<void>((resolve, reject) => {
728
+ try {
729
+ const done = (ok: boolean) => {
730
+ if (!ok) dbgErr('unPauseSpeechRecognitionLite(times) returned false');
731
+ dbg('[CALL unPauseSpeechRecognitionLite] native callback fired', { times, preFetchMs, ok });
732
+ resolve();
733
+ };
734
+ if (preFetchMs > 0 && typeof mod?.unPauseSpeechRecognitionLiteWithPreFetch === 'function') {
735
+ dbg('[CALL unPauseSpeechRecognitionLite] invoking iOS prefetch bridge', { times, preFetchMs });
736
+ mod.unPauseSpeechRecognitionLiteWithPreFetch(times, preFetchMs, done);
737
+ return;
738
+ }
739
+ dbg('[CALL unPauseSpeechRecognitionLite] invoking iOS legacy bridge', { times, preFetchMs });
740
+ fn.call(mod, times, done);
741
+ dbg('[CALL unPauseSpeechRecognitionLite] returned from JS->native invocation', { times, preFetchMs });
742
+ } catch (e) {
743
+ dbgErr('[CALL unPauseSpeechRecognitionLite] exception before native callback', String(e));
744
+ reject(e as any);
745
+ }
746
+ });
747
+ return;
748
+ }
707
749
  await new Promise<void>((resolve, reject) => {
708
750
  try {
709
- const done = (ok: boolean) => {
751
+ const done = async (ok: boolean) => {
710
752
  if (!ok) dbgErr('unPauseSpeechRecognitionLite(times) returned false');
711
- dbg('[CALL unPauseSpeechRecognitionLite] native callback fired', { times, preFetchMs, ok });
753
+ // ANDROID: small delay before resolving
754
+ if (Platform.OS === 'android') await sleep(500);
712
755
  resolve();
713
756
  };
714
- if (preFetchMs > 0 && typeof mod?.unPauseSpeechRecognitionLiteWithPreFetch === 'function') {
715
- dbg('[CALL unPauseSpeechRecognitionLite] invoking iOS prefetch bridge', { times, preFetchMs });
757
+ if (Platform.OS === 'android' && preFetchMs > 0 && typeof mod?.unPauseSpeechRecognitionLiteWithPreFetch === 'function') {
716
758
  mod.unPauseSpeechRecognitionLiteWithPreFetch(times, preFetchMs, done);
717
759
  return;
718
760
  }
719
- dbg('[CALL unPauseSpeechRecognitionLite] invoking iOS legacy bridge', { times, preFetchMs });
720
761
  fn.call(mod, times, done);
721
- dbg('[CALL unPauseSpeechRecognitionLite] returned from JS->native invocation', { times, preFetchMs });
722
762
  } catch (e) {
723
- dbgErr('[CALL unPauseSpeechRecognitionLite] exception before native callback', String(e));
724
763
  reject(e as any);
725
764
  }
726
765
  });
727
- return;
728
- }
729
- await new Promise<void>((resolve, reject) => {
730
- try {
731
- const done = async (ok: boolean) => {
732
- if (!ok) dbgErr('unPauseSpeechRecognitionLite(times) returned false');
733
- // ✅ ANDROID: small delay before resolving
734
- if (Platform.OS === 'android') await sleep(500);
735
- resolve();
736
- };
737
- if (Platform.OS === 'android' && preFetchMs > 0 && typeof mod?.unPauseSpeechRecognitionLiteWithPreFetch === 'function') {
738
- mod.unPauseSpeechRecognitionLiteWithPreFetch(times, preFetchMs, done);
739
- return;
740
- }
741
- fn.call(mod, times, done);
742
- } catch (e) {
743
- reject(e as any);
744
- }
745
766
  });
746
767
  }
747
768
  /** Pause mic/STT (Android native; iOS unified if present) */