react-native-wakeword 1.1.78 → 1.1.79

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.
@@ -1,6 +1,7 @@
1
1
  //ios/KeyWordRNBridge.m
2
2
 
3
3
  #import "KeyWordRNBridge.h"
4
+ #import <AVFoundation/AVFoundation.h>
4
5
  #import <React/RCTBridge.h>
5
6
  #import <React/RCTLog.h>
6
7
  #import <React/RCTEventEmitter.h>
@@ -383,6 +384,11 @@ static NSDictionary * _Nullable SVVerifyWav(id engine, NSString *wavPath, BOOL r
383
384
  return msgSend(c, sel, engine, wavPath, reset, error);
384
385
  }
385
386
 
387
+ static BOOL KWRNBHasMicPermission(void) {
388
+ AVAudioSessionRecordPermission permission = [[AVAudioSession sharedInstance] recordPermission];
389
+ return permission == AVAudioSessionRecordPermissionGranted;
390
+ }
391
+
386
392
  @interface KeyWordRNBridge () <RCTBridgeModule>
387
393
 
388
394
  @property (nonatomic, strong) NSMutableDictionary *instances;
@@ -913,6 +919,54 @@ RCT_EXPORT_METHOD(disableDuckingAndCleanup:(RCTPromiseResolveBlock)resolve rejec
913
919
  resolve(@"disabled");
914
920
  }
915
921
 
922
+ RCT_EXPORT_METHOD(hasMicPermissions:(RCTPromiseResolveBlock)resolve
923
+ rejecter:(RCTPromiseRejectBlock)reject)
924
+ {
925
+ resolve(@(KWRNBHasMicPermission()));
926
+ }
927
+
928
+ RCT_EXPORT_METHOD(requestMicPermissions:(nonnull NSNumber *)wait_timeout
929
+ resolver:(RCTPromiseResolveBlock)resolve
930
+ rejecter:(RCTPromiseRejectBlock)reject)
931
+ {
932
+ dispatch_async(dispatch_get_main_queue(), ^{
933
+ AVAudioSession *audioSession = [AVAudioSession sharedInstance];
934
+ AVAudioSessionRecordPermission permission = audioSession.recordPermission;
935
+ if (permission == AVAudioSessionRecordPermissionGranted) {
936
+ resolve(@YES);
937
+ return;
938
+ }
939
+
940
+ if (permission == AVAudioSessionRecordPermissionDenied) {
941
+ resolve(@NO);
942
+ return;
943
+ }
944
+
945
+ NSTimeInterval timeoutSeconds = MAX(wait_timeout.doubleValue, 0.0) / 1000.0;
946
+ __block BOOL didResolve = NO;
947
+ void (^finish)(BOOL) = ^(BOOL granted) {
948
+ if (didResolve) {
949
+ return;
950
+ }
951
+ didResolve = YES;
952
+ resolve(@(granted));
953
+ };
954
+
955
+ if (timeoutSeconds > 0.0) {
956
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeoutSeconds * NSEC_PER_SEC)),
957
+ dispatch_get_main_queue(), ^{
958
+ finish(KWRNBHasMicPermission());
959
+ });
960
+ }
961
+
962
+ [audioSession requestRecordPermission:^(BOOL granted) {
963
+ dispatch_async(dispatch_get_main_queue(), ^{
964
+ finish(granted);
965
+ });
966
+ }];
967
+ });
968
+ }
969
+
916
970
  RCT_EXPORT_METHOD(setKeywordDetectionLicense:(NSString *)instanceId licenseKey:(NSString *)licenseKey resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
917
971
  {
918
972
  KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-wakeword",
3
- "version": "1.1.78",
3
+ "version": "1.1.79",
4
4
  "description": "Voice/Wake-word detection library for React Native",
5
5
  "main": "wakewords/index.js",
6
6
  "types": "wakewords/index.d.ts",
@@ -47,5 +47,7 @@ export function enableDucking(): Promise<void>;
47
47
  export function disableDucking(): Promise<void>;
48
48
  export function restartListeningAfterDucking(): Promise<void>;
49
49
  export function initAudioSessAndDuckManage(): Promise<void>;
50
+ export function hasIOSMicPermissions(): Promise<any>;
51
+ export function requestIOSMicPermissions(wait_timeout: any): Promise<any>;
50
52
  export function disableDuckingAndCleanup(): Promise<void>;
51
53
  export function setWakewordAudioRoutingConfig(config: any): Promise<any>;
@@ -275,6 +275,14 @@ export const initAudioSessAndDuckManage = async () => {
275
275
  }
276
276
  }
277
277
 
278
+ export const hasIOSMicPermissions = async () => {
279
+ return await KeyWordRNBridge.hasMicPermissions();
280
+ }
281
+
282
+ export const requestIOSMicPermissions = async (wait_timeout) => {
283
+ return await KeyWordRNBridge.requestMicPermissions(wait_timeout);
284
+ }
285
+
278
286
  export const disableDuckingAndCleanup = async () => {
279
287
  if (Platform.OS === 'ios') {
280
288
  await KeyWordRNBridge.disableDuckingAndCleanup();
@@ -1,416 +0,0 @@
1
- //ios/KeyWordRNBridge.m
2
-
3
- #import "KeyWordRNBridge.h"
4
- #import <React/RCTBridge.h>
5
- #import <React/RCTLog.h>
6
- #import <React/RCTEventEmitter.h>
7
- //#import "KeyWordsDetection.h" // Import your KeyWordsDetection library header
8
-
9
- // Ensure the protocol is correctly imported or declared
10
- // Assuming the protocol is named 'KeywordDetectionRNDelegate'
11
- @interface KeyWordsDetectionWrapper : NSObject <KeywordDetectionRNDelegate>
12
-
13
- @property (nonatomic, strong) KeyWordsDetection *keyWordsDetection;
14
- @property (nonatomic, strong) NSString *instanceId;
15
- @property (nonatomic, weak) KeyWordRNBridge *bridge;
16
-
17
- - (instancetype)initWithInstanceId:(NSString *)instanceId
18
- modelName:(NSString *)modelName
19
- threshold:(float)threshold
20
- bufferCnt:(NSInteger)bufferCnt
21
- bridge:(KeyWordRNBridge *)bridge
22
- error:(NSError **)error;
23
-
24
- - (instancetype)initWithInstanceId:(NSString *)instanceId
25
- modelNames:(NSArray<NSString *> *)modelNames
26
- thresholds:(NSArray<NSNumber *> *)thresholds
27
- bufferCnts:(NSArray<NSNumber *> *)bufferCnts
28
- msBetweenCallback:(NSArray<NSNumber *> *)msBetweenCallback
29
- bridge:(KeyWordRNBridge *)bridge
30
- error:(NSError **)error;
31
-
32
- @end
33
-
34
- @implementation KeyWordsDetectionWrapper
35
-
36
- - (instancetype)initWithInstanceId:(NSString *)instanceId
37
- modelName:(NSString *)modelName
38
- threshold:(float)threshold
39
- bufferCnt:(NSInteger)bufferCnt
40
- bridge:(KeyWordRNBridge *)bridge
41
- error:(NSError **)error
42
- {
43
- if (self = [super init]) {
44
- _instanceId = instanceId;
45
- _bridge = bridge;
46
- _keyWordsDetection = [[KeyWordsDetection alloc] initWithModelPath:modelName threshold:threshold bufferCnt:bufferCnt error:error];
47
- if (*error) {
48
- return nil;
49
- }
50
- _keyWordsDetection.delegate = self;
51
- }
52
- return self;
53
- }
54
-
55
- - (instancetype)initWithInstanceId:(NSString *)instanceId
56
- modelNames:(NSArray<NSString *> *)modelNames
57
- thresholds:(NSArray<NSNumber *> *)thresholds
58
- bufferCnts:(NSArray<NSNumber *> *)bufferCnts
59
- msBetweenCallback:(NSArray<NSNumber *> *)msBetweenCallback
60
- bridge:(KeyWordRNBridge *)bridge
61
- error:(NSError **)error {
62
- if (self = [super init]) {
63
- _instanceId = instanceId;
64
- _bridge = bridge;
65
-
66
- NSMutableArray<NSNumber *> *floatThresholds = [NSMutableArray array];
67
- for (NSNumber *num in thresholds) {
68
- [floatThresholds addObject:@(num.floatValue)];
69
- }
70
-
71
- _keyWordsDetection = [[KeyWordsDetection alloc] initWithModelPaths:modelNames
72
- thresholds:floatThresholds
73
- bufferCnts:bufferCnts
74
- msBetweenCallback:msBetweenCallback
75
- error:error];
76
- if (*error) return nil;
77
- _keyWordsDetection.delegate = self;
78
- }
79
- return self;
80
- }
81
-
82
- // Implement the delegate method
83
- - (void)KeywordDetectionDidDetectEvent:(NSDictionary *)eventInfo {
84
- NSMutableDictionary *mutableEventInfo = [eventInfo mutableCopy];
85
- mutableEventInfo[@"instanceId"] = self.instanceId;
86
- [_bridge sendEventWithName:@"onKeywordDetectionEvent" body:mutableEventInfo];
87
- }
88
-
89
- @end
90
-
91
- @interface KeyWordRNBridge () <RCTBridgeModule>
92
-
93
- @property (nonatomic, strong) NSMutableDictionary *instances;
94
-
95
- @end
96
-
97
- @implementation KeyWordRNBridge
98
-
99
- RCT_EXPORT_MODULE();
100
-
101
- - (instancetype)init {
102
- if (self = [super init]) {
103
- _instances = [NSMutableDictionary new];
104
- }
105
- return self;
106
- }
107
-
108
- + (BOOL)requiresMainQueueSetup
109
- {
110
- return YES;
111
- }
112
-
113
- - (NSArray<NSString *> *)supportedEvents {
114
- return @[@"onKeywordDetectionEvent",
115
- @"onVADDetectionEvent"]; // NEW
116
- }
117
-
118
- RCT_EXPORT_METHOD(createInstanceMulti:(NSString *)instanceId
119
- modelPaths:(NSArray<NSString *> *)modelPaths
120
- thresholds:(NSArray<NSNumber *> *)thresholds
121
- bufferCnts:(NSArray<NSNumber *> *)bufferCnts
122
- msBetweenCallback:(NSArray<NSNumber *> *)msBetweenCallback
123
- resolver:(RCTPromiseResolveBlock)resolve
124
- rejecter:(RCTPromiseRejectBlock)reject) {
125
- if (self.instances[instanceId]) {
126
- reject(@"InstanceExists", [NSString stringWithFormat:@"Instance already exists with ID: %@", instanceId], nil);
127
- return;
128
- }
129
-
130
- NSError *error = nil;
131
- KeyWordsDetectionWrapper *wrapper = [[KeyWordsDetectionWrapper alloc]
132
- initWithInstanceId:instanceId
133
- modelNames:modelPaths
134
- thresholds:thresholds
135
- bufferCnts:bufferCnts
136
- msBetweenCallback:msBetweenCallback
137
- bridge:self
138
- error:&error];
139
- if (error) {
140
- reject(@"CreateError", [NSString stringWithFormat:@"Failed to create multi-model instance: %@", error.localizedDescription], nil);
141
- } else {
142
- self.instances[instanceId] = wrapper;
143
- resolve([NSString stringWithFormat:@"Multi-model instance created with ID: %@", instanceId]);
144
- }
145
- }
146
-
147
- RCT_EXPORT_METHOD(createInstance:(NSString *)instanceId modelName:(NSString *)modelName threshold:(float)threshold bufferCnt:(NSInteger)bufferCnt resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
148
- {
149
- if (self.instances[instanceId]) {
150
- reject(@"InstanceExists", [NSString stringWithFormat:@"Instance already exists with ID: %@", instanceId], nil);
151
- return;
152
- }
153
-
154
- NSError *error = nil;
155
- KeyWordsDetectionWrapper *wrapper = [[KeyWordsDetectionWrapper alloc] initWithInstanceId:instanceId modelName:modelName threshold:threshold bufferCnt:bufferCnt bridge:self error:&error];
156
- if (error) {
157
- reject(@"CreateError", [NSString stringWithFormat:@"Failed to create instance: %@", error.localizedDescription], nil);
158
- } else {
159
- self.instances[instanceId] = wrapper;
160
- resolve([NSString stringWithFormat:@"Instance created with ID: %@", instanceId]);
161
- }
162
- }
163
-
164
- // NEW: receive global wakeword audio routing config from JS
165
- RCT_EXPORT_METHOD(setAudioRoutingConfig:(NSString *)jsonConfig
166
- resolver:(RCTPromiseResolveBlock)resolve
167
- rejecter:(RCTPromiseRejectBlock)reject)
168
- {
169
- @try {
170
- // Hand off to your audio/session manager (you implement this)
171
- // e.g. in AudioSessionAndDuckingManager:
172
- // - (void)setWakewordAudioRoutingConfigFromJSONString:(NSString *)jsonConfig;
173
- [AudioSessionAndDuckingManager.shared setWakewordAudioRoutingConfigFromJSONString:jsonConfig];
174
-
175
- NSLog(@"[KeyWordRNBridge] setAudioRoutingConfig JSON = %@", jsonConfig);
176
- resolve(@"ok");
177
- }
178
- @catch (NSException *e) {
179
- reject(@"AudioRoutingConfigError",
180
- [NSString stringWithFormat:@"Failed to set audio routing config: %@", e.reason],
181
- nil);
182
- }
183
- }
184
-
185
- RCT_EXPORT_METHOD(disableDucking:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
186
- {
187
- [AudioSessionAndDuckingManager.shared disableDucking];
188
- resolve(@"enabled");
189
- }
190
-
191
- RCT_EXPORT_METHOD(initAudioSessAndDuckManage:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
192
- {
193
- [AudioSessionAndDuckingManager.shared initAudioSessAndDuckManage];
194
- resolve(@"enabled");
195
- }
196
-
197
- RCT_EXPORT_METHOD(restartListeningAfterDucking:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
198
- {
199
- [AudioSessionAndDuckingManager.shared restartListeningAfterDucking];
200
- resolve(@"disabled");
201
- }
202
-
203
- RCT_EXPORT_METHOD(enableAggressiveDucking:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
204
- {
205
- [AudioSessionAndDuckingManager.shared enableAggressiveDucking];
206
- resolve(@"enabled");
207
- }
208
-
209
- RCT_EXPORT_METHOD(disableDuckingAndCleanup:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
210
- {
211
- [AudioSessionAndDuckingManager.shared disableDuckingAndCleanup];
212
- resolve(@"disabled");
213
- }
214
-
215
- RCT_EXPORT_METHOD(setKeywordDetectionLicense:(NSString *)instanceId licenseKey:(NSString *)licenseKey resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
216
- {
217
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
218
- KeyWordsDetection *instance = wrapper.keyWordsDetection;
219
- BOOL isLicensed = NO;
220
- if (instance) {
221
- isLicensed = [instance setLicenseWithLicenseKey:licenseKey];
222
- NSLog(@"License is valid?: %@", isLicensed ? @"YES" : @"NO");
223
- resolve(@(isLicensed)); // Wrap BOOL in NSNumber
224
- } else {
225
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
226
- }
227
- }
228
-
229
- RCT_EXPORT_METHOD(replaceKeywordDetectionModel:(NSString *)instanceId modelName:(NSString *)modelName threshold:(float)threshold bufferCnt:(NSInteger)bufferCnt resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
230
- {
231
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
232
- KeyWordsDetection *instance = wrapper.keyWordsDetection;
233
- if (instance) {
234
- NSError *error = nil;
235
- [instance replaceKeywordDetectionModelWithModelPath:modelName threshold:threshold bufferCnt:bufferCnt error:&error];
236
- if (error) {
237
- reject(@"ReplaceError", [NSString stringWithFormat:@"Failed to replace model: %@", error.localizedDescription], nil);
238
- } else {
239
- resolve([NSString stringWithFormat:@"Instance ID: %@ changed model to %@", instanceId, modelName]);
240
- }
241
- } else {
242
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
243
- }
244
- }
245
-
246
- RCT_EXPORT_METHOD(startKeywordDetection:(NSString *)instanceId
247
- threshold:(float)threshold
248
- noExternalActivation:(BOOL)noExternalActivation
249
- duckOthers:(BOOL)duckOthers
250
- mixWithOthers:(BOOL)mixWithOthers
251
- defaultToSpeaker:(BOOL)defaultToSpeaker
252
- resolver:(RCTPromiseResolveBlock)resolve
253
- rejecter:(RCTPromiseRejectBlock)reject)
254
- {
255
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
256
- KeyWordsDetection *instance = wrapper.keyWordsDetection;
257
- if (instance) {
258
- BOOL success = [instance startListeningWithNoExternalActivation:noExternalActivation
259
- duckOthers:duckOthers
260
- mixWithOthers:mixWithOthers
261
- defaultToSpeaker:defaultToSpeaker];
262
- if (success == false) {
263
- reject(@"StartError", [NSString stringWithFormat:@"Failed to start detection"], nil);
264
- } else {
265
- resolve([NSString stringWithFormat:@"Started detection for instance: %@", instanceId]);
266
- }
267
- } else {
268
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
269
- }
270
- }
271
-
272
- RCT_EXPORT_METHOD(stopKeywordDetection:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
273
- {
274
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
275
- KeyWordsDetection *instance = wrapper.keyWordsDetection;
276
- if (instance) {
277
- [instance stopListening];
278
- resolve([NSString stringWithFormat:@"Stopped detection for instance: %@", instanceId]);
279
- } else {
280
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
281
- }
282
- }
283
-
284
- RCT_EXPORT_METHOD(destroyInstance:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
285
- {
286
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
287
- if (wrapper) {
288
- [wrapper.keyWordsDetection stopListening];
289
- [self.instances removeObjectForKey:instanceId];
290
- resolve([NSString stringWithFormat:@"Destroyed instance: %@", instanceId]);
291
- } else {
292
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
293
- }
294
- }
295
-
296
- // Keeping all APIs even if not called in JS yet
297
-
298
- RCT_EXPORT_METHOD(getKeywordDetectionModel:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
299
- {
300
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
301
- KeyWordsDetection *instance = wrapper.keyWordsDetection;
302
- if (instance) {
303
- NSString *modelName = [instance getKeywordDetectionModel];
304
- resolve(modelName);
305
- } else {
306
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
307
- }
308
- }
309
-
310
- RCT_EXPORT_METHOD(getRecordingWav:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
311
- {
312
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
313
- KeyWordsDetection *instance = wrapper.keyWordsDetection;
314
- if (instance) {
315
- NSString *recWavPath = [instance getRecordingWav];
316
- resolve(recWavPath);
317
- } else {
318
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
319
- }
320
- }
321
-
322
- RCT_EXPORT_METHOD(getVoiceProps:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
323
- {
324
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
325
- KeyWordsDetection *instance = wrapper.keyWordsDetection;
326
- if (instance) {
327
- @try {
328
- NSDictionary *voiceProps = [instance getVoiceProps];
329
- NSMutableDictionary *result = [NSMutableDictionary dictionary];
330
- result[@"error"] = voiceProps[@"error"] ?: @"No Error";
331
- result[@"voiceProbability"] = @([voiceProps[@"voiceProbability"] floatValue]);
332
- result[@"lastTimeHumanVoiceHeard"] = @([voiceProps[@"lastTimeHumanVoiceHeard"] longLongValue]);
333
- resolve(result);
334
- } @catch (NSException *exception) {
335
- reject(@"VoicePropsError", [NSString stringWithFormat:@"Failed to get voice properties: %@", exception.reason], nil);
336
- }
337
- } else {
338
- reject(@"InstanceNotFound", [NSString stringWithFormat:@"No instance found with ID: %@", instanceId], nil);
339
- }
340
- }
341
-
342
- // Start/stop silent VAD (iOS only)
343
- RCT_EXPORT_METHOD(startSilentVADDetection:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
344
- {
345
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
346
- if (wrapper && wrapper.keyWordsDetection) {
347
- BOOL success = [wrapper.keyWordsDetection startSilentListening];
348
- success ? resolve(@"Started silent VAD detection") :
349
- reject(@"StartError", @"Failed to start silent VAD detection", nil);
350
- } else {
351
- reject(@"InstanceNotFound", @"No instance found", nil);
352
- }
353
- }
354
-
355
- RCT_EXPORT_METHOD(stopSilentVADDetection:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
356
- {
357
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
358
- if (wrapper && wrapper.keyWordsDetection) {
359
- [wrapper.keyWordsDetection stopSilentListening];
360
- resolve(@"Stopped silent VAD detection");
361
- } else {
362
- reject(@"InstanceNotFound", @"No instance found", nil);
363
- }
364
- }
365
-
366
- // Start/stop explicit VAD
367
- RCT_EXPORT_METHOD(startVADDetection:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
368
- {
369
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
370
- if (wrapper && wrapper.keyWordsDetection) {
371
- BOOL success = [wrapper.keyWordsDetection startVADListening];
372
- success ? resolve(@"Started VAD detection") :
373
- reject(@"StartError", @"Failed to start VAD detection", nil);
374
- } else {
375
- reject(@"InstanceNotFound", @"No instance found", nil);
376
- }
377
- }
378
-
379
- RCT_EXPORT_METHOD(stopVADDetection:(NSString *)instanceId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
380
- {
381
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
382
- if (wrapper && wrapper.keyWordsDetection) {
383
- [wrapper.keyWordsDetection stopVADListening];
384
- resolve(@"Stopped VAD detection");
385
- } else {
386
- reject(@"InstanceNotFound", @"No instance found", nil);
387
- }
388
- }
389
-
390
- RCT_EXPORT_METHOD(setVADParams:(NSString *)instanceId
391
- threshold:(float)threshold
392
- msWindow:(NSInteger)msWindow
393
- resolver:(RCTPromiseResolveBlock)resolve
394
- rejecter:(RCTPromiseRejectBlock)reject)
395
- {
396
- KeyWordsDetectionWrapper *wrapper = self.instances[instanceId];
397
- if (wrapper && wrapper.keyWordsDetection) {
398
- NSError *err = nil;
399
- BOOL ok = [wrapper.keyWordsDetection setVADParamsWithThreshold:threshold
400
- msWindow:msWindow
401
- error:&err];
402
- if (!ok || err) {
403
- reject(@"VADParamsError",
404
- err ? err.localizedDescription : @"Failed to set VAD params",
405
- err);
406
- } else {
407
- resolve(@"VAD params updated");
408
- }
409
- } else {
410
- reject(@"InstanceNotFound", @"No instance found", nil);
411
- }
412
- }
413
-
414
- // You can add more methods here as needed, ensuring they use the instanceId
415
-
416
- @end