@iternio/react-native-tts 4.1.3 → 4.1.4
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.
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
|
|
13
13
|
#import "TextToSpeech.h"
|
|
14
14
|
|
|
15
|
+
// Singleton instance for New Architecture compatibility
|
|
16
|
+
static TextToSpeech *_sharedInstance = nil;
|
|
17
|
+
|
|
15
18
|
@implementation TextToSpeech {
|
|
16
19
|
NSString * _ignoreSilentSwitch;
|
|
17
20
|
}
|
|
@@ -20,6 +23,11 @@
|
|
|
20
23
|
|
|
21
24
|
RCT_EXPORT_MODULE()
|
|
22
25
|
|
|
26
|
+
+ (instancetype)sharedInstance
|
|
27
|
+
{
|
|
28
|
+
return _sharedInstance;
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
-(NSArray<NSString *> *)supportedEvents
|
|
24
32
|
{
|
|
25
33
|
return @[@"tts-start", @"tts-finish", @"tts-pause", @"tts-resume", @"tts-progress", @"tts-cancel"];
|
|
@@ -27,12 +35,19 @@ RCT_EXPORT_MODULE()
|
|
|
27
35
|
|
|
28
36
|
-(instancetype)init
|
|
29
37
|
{
|
|
38
|
+
// If we already have a shared instance, return it instead of creating a new one
|
|
39
|
+
// This ensures singleton behavior in React Native New Architecture
|
|
40
|
+
if (_sharedInstance != nil) {
|
|
41
|
+
return _sharedInstance;
|
|
42
|
+
}
|
|
43
|
+
|
|
30
44
|
self = [super init];
|
|
31
45
|
if (self) {
|
|
32
46
|
_synthesizer = [AVSpeechSynthesizer new];
|
|
33
47
|
_synthesizer.delegate = self;
|
|
34
48
|
_ducking = false;
|
|
35
49
|
_ignoreSilentSwitch = @"inherit"; // inherit, ignore, obey
|
|
50
|
+
_sharedInstance = self;
|
|
36
51
|
}
|
|
37
52
|
|
|
38
53
|
return self;
|
|
@@ -79,11 +94,16 @@ RCT_EXPORT_METHOD(speak:(NSString *)text
|
|
|
79
94
|
}
|
|
80
95
|
|
|
81
96
|
if([_ignoreSilentSwitch isEqualToString:@"ignore"]) {
|
|
97
|
+
// Build options based on ducking setting
|
|
98
|
+
AVAudioSessionCategoryOptions options = AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers;
|
|
99
|
+
if (_ducking) {
|
|
100
|
+
options |= AVAudioSessionCategoryOptionDuckOthers;
|
|
101
|
+
}
|
|
102
|
+
|
|
82
103
|
[[AVAudioSession sharedInstance]
|
|
83
104
|
setCategory:AVAudioSessionCategoryPlayback
|
|
84
105
|
mode:AVAudioSessionModeVoicePrompt
|
|
85
|
-
|
|
86
|
-
options:AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
|
|
106
|
+
options:options
|
|
87
107
|
error:nil
|
|
88
108
|
];
|
|
89
109
|
} else if([_ignoreSilentSwitch isEqualToString:@"obey"]) {
|
|
@@ -132,11 +152,11 @@ RCT_EXPORT_METHOD(resume:(RCTPromiseResolveBlock)resolve reject:(__unused RCTPro
|
|
|
132
152
|
}
|
|
133
153
|
|
|
134
154
|
|
|
135
|
-
RCT_EXPORT_METHOD(setDucking:(
|
|
155
|
+
RCT_EXPORT_METHOD(setDucking:(BOOL)ducking
|
|
136
156
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
137
157
|
reject:(__unused RCTPromiseRejectBlock)reject)
|
|
138
158
|
{
|
|
139
|
-
_ducking = ducking;
|
|
159
|
+
_ducking = (bool)ducking;
|
|
140
160
|
|
|
141
161
|
if(ducking) {
|
|
142
162
|
AVAudioSession *session = [AVAudioSession sharedInstance];
|