react-native-davoice-tts 1.0.211 → 1.0.213
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/package.json +1 -1
- package/speech/index.ts +58 -13
- package/tts/models/model.onnx +0 -0
package/TTSRNBridge.podspec
CHANGED
|
@@ -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.
|
|
5
|
+
s.version = "1.0.86" # 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 .
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
aeea7f64bd90800fcca62e0b0222cebf tts-1.0.0.aar
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
b25da2ba5b760b30110d1cfe9200b99465565f0f tts-1.0.0.aar
|
package/package.json
CHANGED
package/speech/index.ts
CHANGED
|
@@ -46,6 +46,10 @@ class Speech {
|
|
|
46
46
|
private unifiedEmitter: NativeEventEmitter | null = null;
|
|
47
47
|
private subs: Array<{ remove: () => void }> = [];
|
|
48
48
|
private handlers: Required<UnifiedEvents>;
|
|
49
|
+
// top of file (new state)
|
|
50
|
+
private lastLocale: string | null = null;
|
|
51
|
+
private lastModel: string | null = null;
|
|
52
|
+
private iosTtsOnly = false; // when true, use NativeTTS directly on iOS
|
|
49
53
|
|
|
50
54
|
constructor() {
|
|
51
55
|
this.handlers = {
|
|
@@ -77,14 +81,37 @@ class Speech {
|
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
|
|
84
|
+
// NEW: tiny helper to (re)wire listeners depending on mode
|
|
85
|
+
private rewireListenersForMode() {
|
|
86
|
+
this.teardownListeners();
|
|
87
|
+
// if iOS unified + NOT tts-only -> use unified emitter
|
|
88
|
+
if (Platform.OS === 'ios' && NativeSpeech && !this.iosTtsOnly) {
|
|
89
|
+
this.unifiedEmitter = new NativeEventEmitter(NativeSpeech);
|
|
90
|
+
// unified handles both STT + TTS events
|
|
91
|
+
} else {
|
|
92
|
+
// fallback: separate emitters
|
|
93
|
+
if (NativeSTT) this.sttEmitter = new NativeEventEmitter(NativeSTT);
|
|
94
|
+
if (Platform.OS === 'android') this.ttsEmitter = DeviceEventEmitter;
|
|
95
|
+
else if (NativeTTS) this.ttsEmitter = new NativeEventEmitter(NativeTTS);
|
|
96
|
+
}
|
|
97
|
+
this.ensureListeners();
|
|
98
|
+
}
|
|
99
|
+
|
|
80
100
|
// ---------- Init / Destroy ----------
|
|
81
101
|
/**
|
|
82
102
|
* iOS: initialize STT then TTS via native SpeechBridge if available.
|
|
83
103
|
* Android: no special init needed; optionally preload TTS (if you want).
|
|
84
104
|
*/
|
|
85
105
|
async initAll(opts: { locale: string; model: string; timeoutMs?: number }) {
|
|
106
|
+
this.lastLocale = opts.locale;
|
|
107
|
+
this.lastModel = opts.model;
|
|
108
|
+
|
|
86
109
|
if (Platform.OS === 'ios' && NativeSpeech?.initAll) {
|
|
87
|
-
|
|
110
|
+
this.iosTtsOnly = false; // full unified mode
|
|
111
|
+
this.teardownListeners(); // re-wire listeners for unified
|
|
112
|
+
const r = await NativeSpeech.initAll(opts);
|
|
113
|
+
this.ensureListeners();
|
|
114
|
+
return r;
|
|
88
115
|
}
|
|
89
116
|
|
|
90
117
|
// Fallback (Android or iOS w/o SpeechBridge):
|
|
@@ -135,6 +162,8 @@ class Speech {
|
|
|
135
162
|
// iOS unified
|
|
136
163
|
if (Platform.OS === 'ios' && NativeSpeech?.destroyAll) {
|
|
137
164
|
const r = await NativeSpeech.destroyAll();
|
|
165
|
+
this.iosTtsOnly = false;
|
|
166
|
+
this.lastLocale = this.lastLocale ?? null;
|
|
138
167
|
this.teardownListeners();
|
|
139
168
|
return r;
|
|
140
169
|
}
|
|
@@ -190,13 +219,20 @@ class Speech {
|
|
|
190
219
|
}
|
|
191
220
|
|
|
192
221
|
/** Pause mic/STT (Android native; iOS unified if present) */
|
|
193
|
-
pauseMicrophone(): Promise<void> {
|
|
222
|
+
async pauseMicrophone(): Promise<void> {
|
|
194
223
|
// Prefer unified iOS if available (safe even if you add iOS later)
|
|
195
|
-
if (Platform.OS === 'ios' &&
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
224
|
+
if (Platform.OS === 'ios' && NativeSpeech) {
|
|
225
|
+
// 1) destroy unified stack (STT+TTS)
|
|
226
|
+
try { await NativeSpeech.destroyAll?.(); } catch {}
|
|
227
|
+
|
|
228
|
+
// 2) init TTS-only using cached model
|
|
229
|
+
if (!this.lastModel) return;
|
|
230
|
+
await NativeTTS.initTTS({ model: this.lastModel });
|
|
231
|
+
|
|
232
|
+
// 3) switch to TTS-only mode and rewire events
|
|
233
|
+
this.iosTtsOnly = true;
|
|
234
|
+
this.rewireListenersForMode();
|
|
235
|
+
return;
|
|
200
236
|
}
|
|
201
237
|
// Android
|
|
202
238
|
if (!(NativeSTT as any)?.pauseMicrophone) return Promise.resolve();
|
|
@@ -207,13 +243,22 @@ class Speech {
|
|
|
207
243
|
}
|
|
208
244
|
|
|
209
245
|
/** Resume mic/STT (Android native; iOS unified if present) */
|
|
210
|
-
|
|
211
|
-
if (Platform.OS === 'ios' &&
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
246
|
+
async unPauseMicrophone(): Promise<void> {
|
|
247
|
+
if (Platform.OS === 'ios' && NativeSpeech) {
|
|
248
|
+
// 1) stop/destroy TTS-only (ignore errors if not present)
|
|
249
|
+
try { await NativeTTS?.stopSpeaking?.(); } catch {}
|
|
250
|
+
try { await NativeTTS?.destroy?.(); } catch {}
|
|
251
|
+
|
|
252
|
+
// 2) re-init full unified stack with cached opts
|
|
253
|
+
if (!this.lastLocale || !this.lastModel) return;
|
|
254
|
+
await NativeSpeech.initAll({ locale: this.lastLocale, model: this.lastModel });
|
|
255
|
+
|
|
256
|
+
// 3) switch back to unified mode and rewire events
|
|
257
|
+
this.iosTtsOnly = false;
|
|
258
|
+
this.rewireListenersForMode();
|
|
259
|
+
return;
|
|
216
260
|
}
|
|
261
|
+
|
|
217
262
|
if (!(NativeSTT as any)?.unPauseMicrophone) return Promise.resolve();
|
|
218
263
|
return new Promise((resolve, reject) => {
|
|
219
264
|
try { (NativeSTT as any).unPauseMicrophone(() => resolve()); }
|
package/tts/models/model.onnx
CHANGED
|
Binary file
|