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.
- package/TTSRNBridge.podspec +1 -1
- package/android/libs/com/davoice/tts/1.0.0/tts-1.0.0.aar +0 -0
- package/android/libs/com/davoice/tts/1.0.0/tts-1.0.0.aar.md5 +1 -1
- package/android/libs/com/davoice/tts/1.0.0/tts-1.0.0.aar.sha1 +1 -1
- package/ios/TTSRNBridge/DaVoiceTTSBridge.m +75 -24
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DavoiceTTS +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Headers/DavoiceTTS-Swift.h +23 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.abi.json +1299 -380
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.private.swiftinterface +19 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.swiftinterface +19 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/DavoiceTTS +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Headers/DavoiceTTS-Swift.h +46 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.abi.json +1299 -380
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +19 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftinterface +19 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.abi.json +1299 -380
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +19 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +19 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeDirectory +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeRequirements-1 +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/_CodeSignature/CodeResources +33 -33
- package/package.json +1 -1
- package/speech/index.d.ts +263 -0
- 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
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
53
|
-
|
|
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(
|
|
64
|
+
resolve({ ok: false, reason: 'timeout', elapsedMs: Date.now() - startedAt });
|
|
60
65
|
}, timeoutMs);
|
|
61
66
|
try {
|
|
62
|
-
invoke((
|
|
67
|
+
invoke((ok) => {
|
|
63
68
|
if (settled) return;
|
|
64
69
|
settled = true;
|
|
65
70
|
clearTimeout(timer);
|
|
66
|
-
resolve(
|
|
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(
|
|
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<
|
|
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.
|
|
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
|
|
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(
|
|
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<
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1003
|
+
resolve({ ok: false, reason: 'native_exception', elapsedMs: Date.now() - startedAt });
|
|
984
1004
|
}
|
|
985
1005
|
});
|
|
986
|
-
return;
|
|
987
1006
|
}
|
|
988
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
|
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
|
});
|