react-native-davoice-tts 1.0.24 → 1.0.26
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/ios/TTSRNBridge/DaVoiceTTSBridge.m +97 -27
- 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 +8 -2
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.abi.json +566 -245
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios.private.swiftinterface +7 -3
- 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 +7 -3
- 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 +16 -4
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.abi.json +566 -245
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +7 -3
- 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 +7 -3
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.abi.json +566 -245
- package/ios/TTSRNBridge/DavoiceTTS.xcframework/ios-arm64_x86_64-simulator/DavoiceTTS.framework/Modules/DavoiceTTS.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +7 -3
- 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 +7 -3
- 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/tts/DaVoiceTTSBridge.d.ts +10 -1
- package/tts/DaVoiceTTSBridge.js +41 -3
- package/tts/index.d.ts +1 -1
- package/LICENSE +0 -21
- package/README.md_wakew +0 -282
- package/ios/TTSRNBridge/TTSRNBridge.swift +0 -48
- package/phonemes_dir/en_dict +0 -0
- package/phonemes_dir/intonations +0 -0
- package/phonemes_dir/lang/gmw/en-US +0 -15
- package/phonemes_dir/phondata +0 -0
- package/phonemes_dir/phonindex +0 -0
- package/phonemes_dir/phontab +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
// DaVoiceTTSBridge.m
|
|
2
2
|
#import "DaVoiceTTSBridge.h"
|
|
3
3
|
#import <React/RCTLog.h>
|
|
4
|
+
#import <React/RCTConvert.h>
|
|
4
5
|
|
|
5
6
|
@interface DaVoiceTTSBridge()
|
|
6
|
-
|
|
7
|
-
@property (nonatomic,
|
|
8
|
-
|
|
7
|
+
@property (nonatomic, strong, nullable) DaVoiceTTS *ttsInstance;
|
|
8
|
+
@property (nonatomic, assign) BOOL hasListeners;
|
|
9
9
|
@end
|
|
10
10
|
|
|
11
11
|
@implementation DaVoiceTTSBridge
|
|
@@ -19,6 +19,34 @@ RCT_EXPORT_MODULE();
|
|
|
19
19
|
return YES;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
#pragma mark - RCTEventEmitter
|
|
23
|
+
|
|
24
|
+
- (NSArray<NSString *> *)supportedEvents
|
|
25
|
+
{
|
|
26
|
+
// Single event exposed to JS.
|
|
27
|
+
return @[@"onFinishedSpeaking"];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
- (void)startObserving
|
|
31
|
+
{
|
|
32
|
+
self.hasListeners = YES;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (void)stopObserving
|
|
36
|
+
{
|
|
37
|
+
self.hasListeners = NO;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
- (void)dealloc
|
|
41
|
+
{
|
|
42
|
+
if (_ttsInstance) {
|
|
43
|
+
[_ttsInstance destroy];
|
|
44
|
+
_ttsInstance = nil;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#pragma mark - API
|
|
49
|
+
|
|
22
50
|
- (instancetype)init {
|
|
23
51
|
self = [super init];
|
|
24
52
|
if (self) {
|
|
@@ -28,13 +56,6 @@ RCT_EXPORT_MODULE();
|
|
|
28
56
|
return self;
|
|
29
57
|
}
|
|
30
58
|
|
|
31
|
-
// Declare events if needed (empty if none)
|
|
32
|
-
- (NSArray<NSString *> *)supportedEvents {
|
|
33
|
-
RCTLogInfo(@"[DaVoiceTTSBridge] supportedEvents called.");
|
|
34
|
-
NSLog(@"[DaVoiceTTSBridge] supportedEvents called.");
|
|
35
|
-
return @[]; // If you don't have events, leave empty.
|
|
36
|
-
}
|
|
37
|
-
|
|
38
59
|
RCT_EXPORT_METHOD(initTTS:(NSDictionary *)configDict
|
|
39
60
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
40
61
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
@@ -51,27 +72,76 @@ RCT_EXPORT_METHOD(initTTS:(NSDictionary *)configDict
|
|
|
51
72
|
NSURL *modelURL = [NSURL fileURLWithPath:modelPath];
|
|
52
73
|
|
|
53
74
|
NSError *error = nil;
|
|
54
|
-
|
|
75
|
+
// Ensure we touch AVAudio/ORT from main.
|
|
76
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
77
|
+
NSError *error = nil;
|
|
78
|
+
self.ttsInstance = [[DaVoiceTTS alloc] initWithModel:modelURL error:&error];
|
|
79
|
+
if (error || !self.ttsInstance) {
|
|
80
|
+
reject(@"init_failed", error.localizedDescription ?: @"Failed to initialize", error);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
__weak typeof(self) weakSelf = self;
|
|
85
|
+
// Bridge Swift callback -> RN event
|
|
86
|
+
self.ttsInstance.onLastUtteranceFinished = ^{
|
|
87
|
+
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
88
|
+
if (!strongSelf) return;
|
|
89
|
+
if (!strongSelf.hasListeners) return;
|
|
90
|
+
|
|
91
|
+
// Send on main just to be extra safe for JS listeners doing UI work.
|
|
92
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
93
|
+
[strongSelf sendEventWithName:@"onFinishedSpeaking" body:@{}];
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
resolve(@"TTS initialized");
|
|
98
|
+
});
|
|
99
|
+
}
|
|
55
100
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
101
|
+
RCT_EXPORT_METHOD(speak:(NSString *)text
|
|
102
|
+
speakerId:(nonnull NSNumber *)speakerId
|
|
103
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
104
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
105
|
+
{
|
|
106
|
+
if (!self.ttsInstance) {
|
|
107
|
+
reject(@"no_instance", @"TTS not initialized", nil);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
112
|
+
[self.ttsInstance speak:text sid:speakerId.intValue];
|
|
113
|
+
resolve(@"Speaking");
|
|
114
|
+
});
|
|
60
115
|
}
|
|
61
|
-
}
|
|
62
116
|
|
|
63
|
-
RCT_EXPORT_METHOD(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
117
|
+
RCT_EXPORT_METHOD(stopSpeaking:(RCTPromiseResolveBlock)resolve
|
|
118
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
119
|
+
{
|
|
120
|
+
if (!self.ttsInstance) {
|
|
121
|
+
reject(@"no_instance", @"TTS not initialized", nil);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
126
|
+
[self.ttsInstance stopSpeaking];
|
|
127
|
+
resolve(@"Stopped");
|
|
128
|
+
});
|
|
71
129
|
}
|
|
72
130
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
131
|
+
RCT_EXPORT_METHOD(destroy:(RCTPromiseResolveBlock)resolve
|
|
132
|
+
rejecter:(RCTPromiseRejectBlock)reject)
|
|
133
|
+
{
|
|
134
|
+
if (!self.ttsInstance) {
|
|
135
|
+
// Idempotent: resolve anyway.
|
|
136
|
+
resolve(@"Already destroyed");
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
141
|
+
[self.ttsInstance destroy];
|
|
142
|
+
self.ttsInstance = nil;
|
|
143
|
+
resolve(@"Destroyed");
|
|
144
|
+
});
|
|
145
|
+
}
|
|
76
146
|
|
|
77
147
|
@end
|
|
Binary file
|
|
@@ -307,13 +307,19 @@ typedef unsigned int swift_uint4 __attribute__((__ext_vector_type__(4)));
|
|
|
307
307
|
|
|
308
308
|
@class NSURL;
|
|
309
309
|
@class NSString;
|
|
310
|
+
@class NSUUID;
|
|
310
311
|
@class AVAudioPCMBuffer;
|
|
311
312
|
SWIFT_CLASS("_TtC10DavoiceTTS10DaVoiceTTS")
|
|
312
313
|
@interface DaVoiceTTS : NSObject
|
|
314
|
+
@property (nonatomic, copy) void (^ _Nullable onLastUtteranceFinished)(void);
|
|
313
315
|
- (nullable instancetype)initWithModel:(NSURL * _Nonnull)model error:(NSError * _Nullable * _Nullable)error OBJC_DESIGNATED_INITIALIZER;
|
|
316
|
+
/// Immediately stop speaking: cancels future synthesis work and flushes all playback.
|
|
317
|
+
- (void)stopSpeaking;
|
|
318
|
+
/// Destroy the TTS instance resources; after this call, the object should not be used.
|
|
319
|
+
/// Effectively returns the instance to “pre-init” state.
|
|
320
|
+
- (void)destroy;
|
|
314
321
|
- (void)speak:(NSString * _Nonnull)txt sid:(int32_t)sid;
|
|
315
|
-
- (AVAudioPCMBuffer * _Nullable)
|
|
316
|
-
- (AVAudioPCMBuffer * _Nullable)synthesize_top:(NSString * _Nonnull)text speakerId:(int32_t)speakerId error:(NSError * _Nullable * _Nullable)error SWIFT_WARN_UNUSED_RESULT;
|
|
322
|
+
- (AVAudioPCMBuffer * _Nullable)synthesize_top:(NSString * _Nonnull)text speakerId:(int32_t)speakerId token:(NSUUID * _Nonnull)token error:(NSError * _Nullable * _Nullable)error SWIFT_WARN_UNUSED_RESULT;
|
|
317
323
|
- (nonnull instancetype)init SWIFT_UNAVAILABLE;
|
|
318
324
|
+ (nonnull instancetype)new SWIFT_UNAVAILABLE_MSG("-init is unavailable");
|
|
319
325
|
@end
|