react-native-davoice-tts 1.0.74 → 1.0.76
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 +2 -1
- package/ios/SpeechBridge/SpeechBridge.h +7 -0
- package/ios/SpeechBridge/SpeechBridge.m +220 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/Info.plist +5 -5
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/DavoiceTTS +0 -0
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.abi.json +191 -191
- 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/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.abi.json +1952 -1952
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +19 -19
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.swiftinterface +19 -19
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.abi.json +1952 -1952
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +19 -19
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +19 -19
- 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 +24 -24
- package/package.json +2 -1
- package/speech/index.ts +314 -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.9" # 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 .
|
|
@@ -20,6 +20,7 @@ Pod::Spec.new do |s|
|
|
|
20
20
|
s.source_files = [
|
|
21
21
|
"ios/TTSRNBridge/DaVoiceTTSBridge.{h,m}",
|
|
22
22
|
"ios/STTRNBridge/STTBridge.{h,m}",
|
|
23
|
+
"ios/SpeechBridge/SpeechBridge.{h,m}",
|
|
23
24
|
"ios/STT/**/*.{swift}"
|
|
24
25
|
]
|
|
25
26
|
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
// SpeechBridge.m
|
|
2
|
+
#import "SpeechBridge.h"
|
|
3
|
+
#import <React/RCTLog.h>
|
|
4
|
+
#import <React/RCTConvert.h>
|
|
5
|
+
|
|
6
|
+
// Import your Swift classes (names as in your project)
|
|
7
|
+
#import <DaVoiceTTS/DaVoiceTTS-Swift.h> // DaVoiceTTS + STT live here in your setup
|
|
8
|
+
|
|
9
|
+
@interface SpeechBridge () <STTDelegate>
|
|
10
|
+
@property (nonatomic, strong, nullable) STT *stt;
|
|
11
|
+
@property (nonatomic, strong, nullable) DaVoiceTTS *tts;
|
|
12
|
+
@property (nonatomic, assign) BOOL hasListeners;
|
|
13
|
+
@property (atomic, assign) BOOL initializing;
|
|
14
|
+
@property (atomic, assign) BOOL initialized;
|
|
15
|
+
|
|
16
|
+
// used only to gate TTS init until STT engine is “hot”
|
|
17
|
+
@property (atomic, assign) BOOL sttEngineHot;
|
|
18
|
+
@end
|
|
19
|
+
|
|
20
|
+
@implementation SpeechBridge
|
|
21
|
+
|
|
22
|
+
RCT_EXPORT_MODULE(SpeechBridge)
|
|
23
|
+
|
|
24
|
+
// We emit the union of STT + TTS events
|
|
25
|
+
- (NSArray<NSString *> *)supportedEvents
|
|
26
|
+
{
|
|
27
|
+
return @[
|
|
28
|
+
// STT events
|
|
29
|
+
@"onSpeechResults",
|
|
30
|
+
@"onSpeechStart",
|
|
31
|
+
@"onSpeechPartialResults",
|
|
32
|
+
@"onSpeechError",
|
|
33
|
+
@"onSpeechEnd",
|
|
34
|
+
@"onSpeechRecognized",
|
|
35
|
+
@"onSpeechVolumeChanged",
|
|
36
|
+
// TTS event
|
|
37
|
+
@"onFinishedSpeaking"
|
|
38
|
+
];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
+ (BOOL)requiresMainQueueSetup { return YES; }
|
|
42
|
+
- (dispatch_queue_t)methodQueue { return dispatch_get_main_queue(); }
|
|
43
|
+
- (void)startObserving { self.hasListeners = YES; }
|
|
44
|
+
- (void)stopObserving { self.hasListeners = NO; }
|
|
45
|
+
|
|
46
|
+
- (void)dealloc
|
|
47
|
+
{
|
|
48
|
+
// destroy in the safe order: TTS → STT
|
|
49
|
+
if (_tts) { [_tts destroy]; _tts = nil; }
|
|
50
|
+
if (_stt) { [_stt destroySpeech:nil]; _stt = nil; }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#pragma mark - STTDelegate (forward all events)
|
|
54
|
+
|
|
55
|
+
- (void)stt:(STT *)stt didEmitEvent:(NSString *)name body:(NSDictionary *)body
|
|
56
|
+
{
|
|
57
|
+
// Use the first onSpeechStart as the “engine hot” latch.
|
|
58
|
+
if ([name isEqualToString:@"onSpeechStart"] && !self.sttEngineHot) {
|
|
59
|
+
self.sttEngineHot = YES;
|
|
60
|
+
}
|
|
61
|
+
if (self.hasListeners) {
|
|
62
|
+
[self sendEventWithName:name body:body ?: @{}];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#pragma mark - Helpers
|
|
67
|
+
|
|
68
|
+
- (void)ensureSTT
|
|
69
|
+
{
|
|
70
|
+
if (!self.stt) {
|
|
71
|
+
self.stt = [STT new];
|
|
72
|
+
self.stt.delegate = self;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
- (void)wireTTSFinishedCallback
|
|
77
|
+
{
|
|
78
|
+
if (!self.tts) return;
|
|
79
|
+
__weak typeof(self) weakSelf = self;
|
|
80
|
+
self.tts.onLastUtteranceFinished = ^{
|
|
81
|
+
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
82
|
+
if (!strongSelf || !strongSelf.hasListeners) return;
|
|
83
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
84
|
+
[strongSelf sendEventWithName:@"onFinishedSpeaking" body:@{}];
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#pragma mark - Unified API
|
|
90
|
+
|
|
91
|
+
/// initAll({ locale: "en-US", model: "/path/model.onnx", timeoutMs?: 8000 })
|
|
92
|
+
RCT_EXPORT_METHOD(initAll:(NSDictionary *)opts
|
|
93
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
94
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
95
|
+
{
|
|
96
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
97
|
+
if (self.initializing) { resolve(@"already_initializing"); return; }
|
|
98
|
+
if (self.initialized) { resolve(@"already_initialized"); return; }
|
|
99
|
+
|
|
100
|
+
self.initializing = YES;
|
|
101
|
+
|
|
102
|
+
NSString *locale = opts[@"locale"] ?: @"en-US";
|
|
103
|
+
NSString *modelPath = opts[@"model"];
|
|
104
|
+
if (modelPath.length == 0) {
|
|
105
|
+
self.initializing = NO;
|
|
106
|
+
reject(@"invalid_args", @"Missing 'model' in initAll()", nil);
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 1) STT first
|
|
111
|
+
if (!self.stt) {
|
|
112
|
+
self.stt = [STT new];
|
|
113
|
+
self.stt.delegate = self;
|
|
114
|
+
}
|
|
115
|
+
[self.stt startSpeechWithLocaleStr:locale];
|
|
116
|
+
|
|
117
|
+
// 2) TTS next
|
|
118
|
+
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
|
|
119
|
+
NSError *err = nil;
|
|
120
|
+
self.tts = [[DaVoiceTTS alloc] initWithModel:modelURL error:&err];
|
|
121
|
+
if (err || !self.tts) {
|
|
122
|
+
self.initializing = NO;
|
|
123
|
+
[self.stt destroySpeech:nil];
|
|
124
|
+
self.stt = nil;
|
|
125
|
+
reject(@"tts_init_failed", err.localizedDescription ?: @"TTS init failed", err);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
__weak typeof(self) wself = self;
|
|
130
|
+
self.tts.onLastUtteranceFinished = ^{
|
|
131
|
+
__strong typeof(wself) sself = wself;
|
|
132
|
+
if (!sself || !sself.hasListeners) return;
|
|
133
|
+
[sself sendEventWithName:@"onFinishedSpeaking" body:@{}];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
self.initialized = YES;
|
|
137
|
+
self.initializing = NO;
|
|
138
|
+
resolve(@"initialized");
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
RCT_EXPORT_METHOD(destroyAll:(RCTPromiseResolveBlock)resolve
|
|
143
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
144
|
+
{
|
|
145
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
146
|
+
if (!self.initialized && !self.initializing) {
|
|
147
|
+
resolve(@"already_destroyed");
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
// prevent re-entry during destroy
|
|
151
|
+
self.initializing = YES;
|
|
152
|
+
|
|
153
|
+
// Destroy in reverse order: TTS -> STT
|
|
154
|
+
@try { [self.tts stopSpeaking]; [self.tts destroy]; } @catch (__unused id e) {}
|
|
155
|
+
self.tts = nil;
|
|
156
|
+
|
|
157
|
+
@try { [self.stt destroySpeech:nil]; } @catch (__unused id e) {}
|
|
158
|
+
self.stt = nil;
|
|
159
|
+
|
|
160
|
+
self.initialized = NO;
|
|
161
|
+
self.initializing = NO;
|
|
162
|
+
resolve(@"destroyed");
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
#pragma mark - Convenience passthroughs (optional)
|
|
167
|
+
|
|
168
|
+
RCT_EXPORT_METHOD(startSpeech:(NSString *)locale
|
|
169
|
+
callback:(RCTResponseSenderBlock)callback)
|
|
170
|
+
{
|
|
171
|
+
[self ensureSTT];
|
|
172
|
+
[self.stt startSpeechWithLocaleStr:locale];
|
|
173
|
+
if (callback) callback(@[@(NO)]);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
RCT_EXPORT_METHOD(stopSpeech:(RCTResponseSenderBlock)callback)
|
|
177
|
+
{
|
|
178
|
+
if (!self.stt) { if (callback) callback(@[@(NO)]); return; }
|
|
179
|
+
[self.stt stopSpeech:^(BOOL ok) { if (callback) callback(@[@(NO)]); }];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
RCT_EXPORT_METHOD(cancelSpeech:(RCTResponseSenderBlock)callback)
|
|
183
|
+
{
|
|
184
|
+
if (!self.stt) { if (callback) callback(@[@(NO)]); return; }
|
|
185
|
+
[self.stt cancelSpeech:^(BOOL ok) { if (callback) callback(@[@(NO)]); }];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
RCT_EXPORT_METHOD(isSpeechAvailable:(RCTResponseSenderBlock)callback)
|
|
189
|
+
{
|
|
190
|
+
[self ensureSTT];
|
|
191
|
+
[self.stt isSpeechAvailable:^(BOOL ok){
|
|
192
|
+
if (callback) callback(@[@(ok ? 1 : 0), [NSNull null]]);
|
|
193
|
+
}];
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
RCT_EXPORT_METHOD(isRecognizing:(RCTResponseSenderBlock)callback)
|
|
197
|
+
{
|
|
198
|
+
BOOL running = self.stt ? [self.stt isRecognizing] : NO;
|
|
199
|
+
if (callback) callback(@[@(running ? 1 : 0)]);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
RCT_EXPORT_METHOD(speak:(NSString *)text
|
|
203
|
+
speakerId:(nonnull NSNumber *)speakerId
|
|
204
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
205
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
206
|
+
{
|
|
207
|
+
if (!self.tts) { reject(@"no_tts", @"Call initAll first", nil); return; }
|
|
208
|
+
[self.tts speak:text sid:speakerId.intValue];
|
|
209
|
+
resolve(@"Speaking");
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
RCT_EXPORT_METHOD(stopSpeaking:(RCTPromiseResolveBlock)resolve
|
|
213
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
214
|
+
{
|
|
215
|
+
if (!self.tts) { reject(@"no_tts", @"Call initAll first", nil); return; }
|
|
216
|
+
[self.tts stopSpeaking];
|
|
217
|
+
resolve(@"Stopped");
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
@end
|
|
@@ -8,32 +8,32 @@
|
|
|
8
8
|
<key>BinaryPath</key>
|
|
9
9
|
<string>DavoiceTTS.framework/DavoiceTTS</string>
|
|
10
10
|
<key>LibraryIdentifier</key>
|
|
11
|
-
<string>ios-
|
|
11
|
+
<string>ios-arm64</string>
|
|
12
12
|
<key>LibraryPath</key>
|
|
13
13
|
<string>DavoiceTTS.framework</string>
|
|
14
14
|
<key>SupportedArchitectures</key>
|
|
15
15
|
<array>
|
|
16
16
|
<string>arm64</string>
|
|
17
|
-
<string>x86_64</string>
|
|
18
17
|
</array>
|
|
19
18
|
<key>SupportedPlatform</key>
|
|
20
19
|
<string>ios</string>
|
|
21
|
-
<key>SupportedPlatformVariant</key>
|
|
22
|
-
<string>simulator</string>
|
|
23
20
|
</dict>
|
|
24
21
|
<dict>
|
|
25
22
|
<key>BinaryPath</key>
|
|
26
23
|
<string>DavoiceTTS.framework/DavoiceTTS</string>
|
|
27
24
|
<key>LibraryIdentifier</key>
|
|
28
|
-
<string>ios-
|
|
25
|
+
<string>ios-arm64_x86_64-simulator</string>
|
|
29
26
|
<key>LibraryPath</key>
|
|
30
27
|
<string>DavoiceTTS.framework</string>
|
|
31
28
|
<key>SupportedArchitectures</key>
|
|
32
29
|
<array>
|
|
33
30
|
<string>arm64</string>
|
|
31
|
+
<string>x86_64</string>
|
|
34
32
|
</array>
|
|
35
33
|
<key>SupportedPlatform</key>
|
|
36
34
|
<string>ios</string>
|
|
35
|
+
<key>SupportedPlatformVariant</key>
|
|
36
|
+
<string>simulator</string>
|
|
37
37
|
</dict>
|
|
38
38
|
</array>
|
|
39
39
|
<key>CFBundlePackageType</key>
|