react-native-davoice-tts 1.0.395 → 1.0.397

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 (27) 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/ios/TTSRNBridge/DaVoiceTTSBridge.m +75 -24
  6. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DavoiceTTS +0 -0
  7. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Headers/DavoiceTTS-Swift.h +23 -0
  8. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.abi.json +1299 -380
  9. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.private.swiftinterface +19 -0
  10. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  11. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftinterface +19 -0
  12. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DavoiceTTS +0 -0
  13. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Headers/DavoiceTTS-Swift.h +46 -0
  14. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.abi.json +1299 -380
  15. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +19 -0
  16. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  17. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftinterface +19 -0
  18. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.abi.json +1299 -380
  19. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +19 -0
  20. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  21. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +19 -0
  22. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeDirectory +0 -0
  23. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeRequirements-1 +0 -0
  24. package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeResources +33 -33
  25. package/package.json +1 -1
  26. package/speech/index.d.ts +263 -0
  27. package/speech/index.ts +50 -29
package/speech/index.ts CHANGED
@@ -41,36 +41,45 @@ function sleep(ms: number) {
41
41
 
42
42
  // Android's pauseSpeechRecognitionLite/unPauseSpeechRecognitionLite native callbacks have
43
43
  // no native-JS-visible timeout contract of their own (unlike iOS's ...LiteAsync). This
44
- // guarantees the wrapping promise always settles: on timeout it logs and resolves with
45
- // undefined rather than rejecting, so callers that never expected this call to throw don't
46
- // suddenly start seeing exceptions - the only change is a bounded wait instead of an
47
- // unbounded one.
48
- function androidCallbackWithTimeout<T>(
49
- invoke: (done: (value: T) => void) => void,
44
+ // guarantees the wrapping promise always settles with the same structured result used by
45
+ // the iOS async bridge.
46
+ export type SpeechTransitionResult = {
47
+ ok: boolean;
48
+ reason: string;
49
+ elapsedMs: number;
50
+ };
51
+
52
+ function androidCallbackWithTimeout(
53
+ invoke: (done: (ok: boolean) => void) => void,
50
54
  timeoutMs: number,
51
55
  label: string,
52
- ): Promise<T | undefined> {
53
- return new Promise<T | undefined>((resolve) => {
56
+ startedAt: number,
57
+ ): Promise<SpeechTransitionResult> {
58
+ return new Promise<SpeechTransitionResult>((resolve) => {
54
59
  let settled = false;
55
60
  const timer = setTimeout(() => {
56
61
  if (settled) return;
57
62
  settled = true;
58
63
  dbgNotice(`IMPORTANT: ${label} reached timeout - please note this is not a bug`, { timeoutMs });
59
- resolve(undefined);
64
+ resolve({ ok: false, reason: 'timeout', elapsedMs: Date.now() - startedAt });
60
65
  }, timeoutMs);
61
66
  try {
62
- invoke((value) => {
67
+ invoke((ok) => {
63
68
  if (settled) return;
64
69
  settled = true;
65
70
  clearTimeout(timer);
66
- resolve(value);
71
+ resolve({
72
+ ok: ok !== false,
73
+ reason: ok === false ? 'native_reported_failure' : '',
74
+ elapsedMs: Date.now() - startedAt,
75
+ });
67
76
  });
68
77
  } catch (e) {
69
78
  if (settled) return;
70
79
  settled = true;
71
80
  clearTimeout(timer);
72
81
  dbgErr(`${label} threw before native callback`, String(e));
73
- resolve(undefined);
82
+ resolve({ ok: false, reason: 'native_exception', elapsedMs: Date.now() - startedAt });
74
83
  }
75
84
  });
76
85
  }
@@ -319,19 +328,20 @@ class Speech {
319
328
  return nativeTtsSpeak();
320
329
  }
321
330
 
322
- private enqueueSttTransition(opId: string, kind: 'pause' | 'unpause', work: () => Promise<void>): Promise<void> {
331
+ private enqueueSttTransition<T>(opId: string, kind: 'pause' | 'unpause', work: () => Promise<T>): Promise<T> {
323
332
  const previous = this.sttTransitionChain.catch(() => {});
324
333
  const run = previous.then(async () => {
325
334
  dbg('[sttTransition] begin', { opId, kind });
326
335
  try {
327
- await work();
336
+ const result = await work();
328
337
  dbg('[sttTransition] end', { opId, kind });
338
+ return result;
329
339
  } catch (e) {
330
340
  dbgErr('[sttTransition] failed', { opId, kind, error: String(e) });
331
341
  throw e;
332
342
  }
333
343
  });
334
- this.sttTransitionChain = run.catch(() => {});
344
+ this.sttTransitionChain = run.then(() => undefined, () => undefined);
335
345
  return run;
336
346
  }
337
347
 
@@ -893,15 +903,16 @@ class Speech {
893
903
  return;
894
904
  }
895
905
 
896
- await androidCallbackWithTimeout<void>(
906
+ await androidCallbackWithTimeout(
897
907
  (done) => {
898
908
  fn.call(mod, (ok: boolean) => {
899
909
  if (!ok) dbgNotice('IMPORTANT: pauseSpeechRecognitionLite reached timeout - please note this is not a bug');
900
- done(undefined);
910
+ done(ok);
901
911
  });
902
912
  },
903
913
  effectiveTimeoutMs,
904
914
  'pauseSpeechRecognitionLite',
915
+ startedAt,
905
916
  );
906
917
  };
907
918
 
@@ -918,7 +929,7 @@ class Speech {
918
929
  times: number,
919
930
  preFetchMs: number = 0,
920
931
  timeoutMs: number = 500,
921
- ): Promise<{ ok: boolean; reason: string; elapsedMs: number } | undefined> {
932
+ ): Promise<SpeechTransitionResult> {
922
933
  this.logCall('unPauseSpeechRecognitionLite', { times, preFetchMs });
923
934
  const startedAt = Date.now();
924
935
  // Previously hard-capped at 500ms regardless of the caller's requested timeoutMs, so the
@@ -934,12 +945,17 @@ class Speech {
934
945
  const work = async (opId?: string) => {
935
946
  if (!fn) {
936
947
  dbg(`unPauseSpeechRecognitionLite(times) not available on ${Platform.OS === 'ios' ? 'NativeSpeech' : 'NativeSTT'}`);
937
- return;
948
+ return { ok: false, reason: 'unsupported', elapsedMs: Date.now() - startedAt };
938
949
  }
939
950
 
940
951
  if (Platform.OS === 'ios' && typeof mod?.unPauseSpeechRecognitionLiteAsync === 'function') {
941
952
  dbg('[unPauseSpeechRecognitionLiteAsync] begin', { ...(opId ? { opId } : {}), times, preFetchMs, timeoutMs: effectiveTimeoutMs });
942
- const result = await mod.unPauseSpeechRecognitionLiteAsync(times, preFetchMs, effectiveTimeoutMs);
953
+ let result: any;
954
+ try {
955
+ result = await mod.unPauseSpeechRecognitionLiteAsync(times, preFetchMs, effectiveTimeoutMs);
956
+ } catch {
957
+ return { ok: false, reason: 'native_exception', elapsedMs: Date.now() - startedAt };
958
+ }
943
959
  dbg('[unPauseSpeechRecognitionLiteAsync] resolved', {
944
960
  ...(opId ? { opId } : {}),
945
961
  times,
@@ -963,12 +979,16 @@ class Speech {
963
979
  }
964
980
 
965
981
  if (Platform.OS === 'ios') {
966
- await new Promise<void>((resolve, reject) => {
982
+ return new Promise<SpeechTransitionResult>((resolve) => {
967
983
  try {
968
984
  const done = (ok: boolean) => {
969
985
  if (!ok) dbgNotice('IMPORTANT: unPauseSpeechRecognitionLite reached timeout - please note this is not a bug');
970
986
  dbg('[CALL unPauseSpeechRecognitionLite] native callback fired', { times, preFetchMs, ok });
971
- resolve();
987
+ resolve({
988
+ ok: ok !== false,
989
+ reason: ok === false ? 'native_reported_failure' : '',
990
+ elapsedMs: Date.now() - startedAt,
991
+ });
972
992
  };
973
993
  if (preFetchMs > 0 && typeof mod?.unPauseSpeechRecognitionLiteWithPreFetch === 'function') {
974
994
  dbg('[CALL unPauseSpeechRecognitionLite] invoking iOS prefetch bridge', { times, preFetchMs });
@@ -980,16 +1000,15 @@ class Speech {
980
1000
  dbg('[CALL unPauseSpeechRecognitionLite] returned from JS->native invocation', { times, preFetchMs });
981
1001
  } catch (e) {
982
1002
  dbgErr('[CALL unPauseSpeechRecognitionLite] exception before native callback', String(e));
983
- reject(e as any);
1003
+ resolve({ ok: false, reason: 'native_exception', elapsedMs: Date.now() - startedAt });
984
1004
  }
985
1005
  });
986
- return;
987
1006
  }
988
- await androidCallbackWithTimeout<void>(
1007
+ return androidCallbackWithTimeout(
989
1008
  (done) => {
990
1009
  const nativeDone = (ok: boolean) => {
991
1010
  if (!ok) dbgNotice('IMPORTANT: unPauseSpeechRecognitionLite reached timeout - please note this is not a bug');
992
- done(undefined);
1011
+ done(ok);
993
1012
  };
994
1013
  if (Platform.OS === 'android' && preFetchMs > 0 && typeof mod?.unPauseSpeechRecognitionLiteWithPreFetch === 'function') {
995
1014
  mod.unPauseSpeechRecognitionLiteWithPreFetch(times, preFetchMs, nativeDone);
@@ -999,13 +1018,13 @@ class Speech {
999
1018
  },
1000
1019
  effectiveTimeoutMs,
1001
1020
  'unPauseSpeechRecognitionLite',
1021
+ startedAt,
1002
1022
  );
1003
1023
  };
1004
1024
 
1005
1025
  if (PROBABLY_GPT_MISTAKE) {
1006
1026
  const opId = nextSpeechOpId('unpause-stt');
1007
- await this.enqueueSttTransition(opId, 'unpause', () => work(opId).then(() => undefined));
1008
- return undefined;
1027
+ return this.enqueueSttTransition(opId, 'unpause', () => work(opId));
1009
1028
  }
1010
1029
 
1011
1030
  return work();
@@ -1506,7 +1525,9 @@ class Speech {
1506
1525
  };
1507
1526
  (Object.keys(sttMap) as (keyof typeof sttMap)[]).forEach((name) => {
1508
1527
  try {
1509
- const sub = this.sttEmitter!.addListener(name, sttMap[name]);
1528
+ const handler = sttMap[name];
1529
+ if (!handler) return;
1530
+ const sub = this.sttEmitter!.addListener(name, handler);
1510
1531
  this.subs.push(sub);
1511
1532
  } catch {}
1512
1533
  });