react-native-wakeword-sid 1.1.55

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.
Files changed (77) hide show
  1. package/KeyWordRNBridge.podspec +58 -0
  2. package/LICENSE +21 -0
  3. package/README.md +281 -0
  4. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  5. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  6. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  7. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  8. package/android/.gradle/8.9/gc.properties +0 -0
  9. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  10. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  11. package/android/.gradle/vcs-1/gc.properties +0 -0
  12. package/android/build.gradle +48 -0
  13. package/android/libs/com/davoice/keyworddetection/1.0.0/keyworddetection-1.0.0.aar +0 -0
  14. package/android/libs/com/davoice/keyworddetection/1.0.0/keyworddetection-1.0.0.aar.md5 +1 -0
  15. package/android/libs/com/davoice/keyworddetection/1.0.0/keyworddetection-1.0.0.aar.sha1 +1 -0
  16. package/android/libs/com/davoice/keyworddetection/1.0.0/keyworddetection-1.0.0.pom +10 -0
  17. package/android/libs/com/davoice/keyworddetection/1.0.0/keyworddetection-1.0.0.pom.md5 +1 -0
  18. package/android/libs/com/davoice/keyworddetection/1.0.0/keyworddetection-1.0.0.pom.sha1 +1 -0
  19. package/android/settings.gradle +2 -0
  20. package/android/src/main/AndroidManifest.xml +13 -0
  21. package/android/src/main/assets/hey_lookdeep.dm +0 -0
  22. package/android/src/main/assets/layer1.dm +0 -0
  23. package/android/src/main/assets/need_help_now.dm +0 -0
  24. package/android/src/main/java/com/davoice/DaVoiceUnifiedPackage.java +29 -0
  25. package/android/src/main/java/com/davoice/keywordspotting/KeyWordRNBridge.java +335 -0
  26. package/android/src/main/java/com/davoice/speakeridrn/SpeakerIdRNBridge.java_not_used_yet +588 -0
  27. package/android/src/main/libs/MyLibrary-release.aar +0 -0
  28. package/app.plugin.js +60 -0
  29. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/Info.plist +44 -0
  30. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Headers/KeyWordDetection-Swift.h +386 -0
  31. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Headers/KeyWordDetection.h +18 -0
  32. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Info.plist +0 -0
  33. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/KeyWordDetection +0 -0
  34. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios.abi.json +5758 -0
  35. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios.private.swiftinterface +159 -0
  36. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  37. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios.swiftinterface +159 -0
  38. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64/KeyWordDetection.framework/Modules/module.modulemap +11 -0
  39. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Headers/KeyWordDetection-Swift.h +768 -0
  40. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Headers/KeyWordDetection.h +18 -0
  41. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Info.plist +0 -0
  42. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/KeyWordDetection +0 -0
  43. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios-simulator.abi.json +5758 -0
  44. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +159 -0
  45. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  46. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/arm64-apple-ios-simulator.swiftinterface +159 -0
  47. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/x86_64-apple-ios-simulator.abi.json +5758 -0
  48. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +159 -0
  49. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  50. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/KeyWordDetection.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +159 -0
  51. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/Modules/module.modulemap +11 -0
  52. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/_CodeSignature/CodeDirectory +0 -0
  53. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/_CodeSignature/CodeRequirements +0 -0
  54. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/_CodeSignature/CodeRequirements-1 +0 -0
  55. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/_CodeSignature/CodeResources +297 -0
  56. package/ios/KeyWordRNBridge/KeyWordDetection.xcframework/ios-arm64_x86_64-simulator/KeyWordDetection.framework/_CodeSignature/CodeSignature +0 -0
  57. package/ios/KeyWordRNBridge/KeyWordRNBridge.h +19 -0
  58. package/ios/KeyWordRNBridge/KeyWordRNBridge.m +642 -0
  59. package/ios/KeyWordRNBridge/KeyWordRNBridge.mm +416 -0
  60. package/ios/KeyWordRNBridge/models/coca_cola_model_28_05052025.onnx +0 -0
  61. package/ios/KeyWordRNBridge/models/embedding_model.onnx +0 -0
  62. package/ios/KeyWordRNBridge/models/hey_lookdeep.onnx +0 -0
  63. package/ios/KeyWordRNBridge/models/melspectrogram.onnx +0 -0
  64. package/ios/KeyWordRNBridge/models/need_help_now.onnx +0 -0
  65. package/ios/KeyWordRNBridge/models/silero_vad.onnx +0 -0
  66. package/package.json +74 -0
  67. package/react-native.config.js +10 -0
  68. package/wakewords/KeyWordRNBridge.d.ts +38 -0
  69. package/wakewords/KeyWordRNBridge.js +228 -0
  70. package/wakewords/SpeakerVerificationRNBridge.d.ts +32 -0
  71. package/wakewords/SpeakerVerificationRNBridge.js +124 -0
  72. package/wakewords/audioRoutingConfig.d.ts +17 -0
  73. package/wakewords/audioRoutingConfig.ts +28 -0
  74. package/wakewords/index.d.ts +16 -0
  75. package/wakewords/index.js +34 -0
  76. package/wakewords/useModel.d.ts +19 -0
  77. package/wakewords/useModel.tsx +235 -0
@@ -0,0 +1,235 @@
1
+ import { useState, useEffect, useCallback } from "react";
2
+ import {
3
+ createKeyWordRNBridgeInstance,
4
+ removeAllRNBridgeListeners,
5
+ KeyWordRNBridgeInstance,
6
+ } from './KeyWordRNBridge';
7
+ import { Platform } from "react-native";
8
+
9
+ type DetectionCallback = (event: any) => void;
10
+
11
+ var license = "MTczODEwMTYwMDAwMA==-Vmv1jwEG+Fbog9LoblZnVT4TzAXDhZs7l9O18A+8ul8=";
12
+ interface keyWordRNBridgeInstanceConfig {
13
+ id: string;
14
+ instance: KeyWordRNBridgeInstance;
15
+ }
16
+
17
+ interface instanceConfig {
18
+ id: string;
19
+ modelName: string;
20
+ threshold: number;
21
+ bufferCnt: number;
22
+ sticky: boolean;
23
+ }
24
+
25
+ const keyWordRNBridgeInstances: keyWordRNBridgeInstanceConfig[] = [];
26
+ function findInstanceById(id: string): keyWordRNBridgeInstanceConfig | undefined {
27
+ return keyWordRNBridgeInstances.find(config => config.id === id);
28
+ }
29
+
30
+ // Create an array of instance configurations
31
+ var instanceConfigs:instanceConfig[] = [
32
+ { id: 'need_help_now', modelName: 'need_help_now.onnx', threshold: 0.9999, bufferCnt: 3 , sticky: false },
33
+ ];
34
+
35
+ // Helper function to format the ONNX file name
36
+ const formatWakeWord = (fileName) => {
37
+ return fileName
38
+ .replace(/_/g, ' ') // Use global flag to replace all underscores
39
+ .replace('.onnx', '')
40
+ .replace(/\b\w/g, (char) => char.toUpperCase()); // Capitalize each word
41
+ };
42
+
43
+ // Function to add a new instance dynamically
44
+ //async function addInstance(
45
+ // conf: instanceConfig)
46
+ async function addInstance(
47
+ conf: instanceConfig,
48
+ callback: (phrase: string) => void
49
+ ): Promise<KeyWordRNBridgeInstance | null> {
50
+ const id = conf.id;
51
+ const instanceConf = findInstanceById(id);
52
+ if (instanceConf != null) {
53
+ console.log("Found Instance: ", id, "starting to listen");
54
+ const instance = instanceConf.instance;
55
+ await instance.startKeywordDetection(conf.threshold);
56
+ return instance;
57
+ }
58
+ const instance = await createKeyWordRNBridgeInstance(id, conf.sticky);
59
+ let isLicesed = false;
60
+
61
+ if (!instance) {
62
+ console.error(`Failed to create instance ${id}`);
63
+ return null;
64
+ }
65
+ console.log(`Instance ${id} created ${instance}`);
66
+ await instance.createInstance(conf.modelName, conf.threshold, conf.bufferCnt);
67
+ console.log(`Instance ${id} createInstance() called`);
68
+
69
+ isLicesed = await instance.setKeywordDetectionLicense(license);
70
+ console.log(`Instance ${id} created ${instance} and licensed ${isLicesed}`);
71
+
72
+ keyWordRNBridgeInstances.push({ id, instance });
73
+
74
+ // Set up event listener
75
+ // Clean all listeners keywordRNBridgeEmitter.removeAllListeners('onKeywordDetectionEvent');
76
+
77
+ const eventListener = instance.onKeywordDetectionEvent((phrase: string) => {
78
+ phrase = formatWakeWord(id);
79
+ console.log(`Instance ${id} detected: ${id} with phrase`, phrase);
80
+ // callback(phrase); Does not work on IOS
81
+ callback(phrase);
82
+ });
83
+ console.log(`Instance ${id} calling startKeywordDetection()`);
84
+ await instance.startKeywordDetection(conf.threshold);
85
+ console.log(`Instance ${id} started Keyword Detection`);
86
+ return instance;
87
+ }
88
+
89
+ // Function to remove an instance dynamically
90
+ function removeInstance(id: string): void {
91
+ const instanceIndex = keyWordRNBridgeInstances.findIndex((item) => item.id === id);
92
+
93
+ if (instanceIndex !== -1) {
94
+ const { instance } = keyWordRNBridgeInstances[instanceIndex];
95
+
96
+ instance
97
+ .stopKeywordDetection()
98
+ .then(() => instance.destroyInstance())
99
+ .then(() => {
100
+ instance.removeListeners();
101
+ console.log(`Instance ${id} stopped and destroyed`);
102
+ keyWordRNBridgeInstances.splice(instanceIndex, 1);
103
+ })
104
+ .catch((error: Error) =>
105
+ console.error(`Error stopping instance ${id}: ${error.message}`)
106
+ );
107
+ } else {
108
+ console.error(`Instance ${id} not found`);
109
+ }
110
+ }
111
+
112
+ /**
113
+ * Custom hook for handling keyword detection using KeyWordRNBridge
114
+ * @returns An object with functions and state for keyword detection
115
+ */
116
+ export const useModel = () => {
117
+ // State to track whether the keyword detection is currently active
118
+ const [isListening, setIsListening] = useState(false);
119
+ let currentEventListener: any[] = [];
120
+ /**
121
+ * Set the keyword detection license
122
+ * @param licenseKey - The license key
123
+ */
124
+ // const setLicense = useCallback(async (licenseKey: any) => {
125
+ // try {
126
+ // await KeyWordRNBridge.setKeywordDetectionLicense(licenseKey);
127
+ // } catch (error) {
128
+ // console.error("[useModel] Error setting license:", error);
129
+ // }
130
+ // }, []);
131
+
132
+ /**
133
+ * Sets the keyword detection license
134
+ * @param licenseKey - The linceseKey
135
+ */
136
+ const setKeywordDetectionLicense = useCallback(
137
+ async (licenseKey: string): Promise<void> => {
138
+ license = licenseKey;
139
+ }, []);
140
+
141
+
142
+ /**
143
+ * Load the keyword detection model
144
+ * @param modelFileName - The name of the model file to load
145
+ * @param threshold - The detection threshold
146
+ * @param bufferCount - The number of audio buffers
147
+ */
148
+ const loadModel = useCallback(
149
+ async (useConfigs: instanceConfig[], callback: (phrase: string) => void): Promise<void> => {
150
+
151
+ console.log("loadModel()");
152
+ instanceConfigs = useConfigs;
153
+ let element:any = null;
154
+ console.log("loadModel() - instanceConfigs == ", instanceConfigs)
155
+ try {
156
+ instanceConfigs.forEach(async element => {
157
+ console.log('Adding element:', element);
158
+ const id = await addInstance(element, callback);
159
+ });
160
+ } catch (error) {
161
+ console.error("[useModel] Error loading model:", error);
162
+ }
163
+ }, []);
164
+
165
+ /**
166
+ * Stop listening for the keyword
167
+ */
168
+ const startListening = useCallback(async () => {
169
+ try {
170
+ keyWordRNBridgeInstances.forEach(async element => {
171
+ const instance = element.instance;
172
+ const conf = instanceConfigs.find(element => element.id === instance.instanceId);
173
+ if (conf) {
174
+ await instance.startKeywordDetection(conf.threshold);
175
+ } else {
176
+ console.error(`No configuration found for instance ID: ${instance.instanceId}`);
177
+ }
178
+ /*if (instance.isSticky == false) {
179
+ instance.stopKeywordDetection();
180
+ } else if (Platform.OS != 'ios') {
181
+ instance.stopKeywordDetection();
182
+ }*/
183
+ });
184
+ setIsListening(true);
185
+ } catch (error) {
186
+ console.error("Error starting keyword detection:", error);
187
+ }
188
+ }, []);
189
+
190
+ /**
191
+ * Stop listening for the keyword
192
+ */
193
+ const stopListening = useCallback(async () => {
194
+ try {
195
+ keyWordRNBridgeInstances.forEach(async element => {
196
+ const instance = element.instance;
197
+ await instance.stopKeywordDetection();
198
+ /*if (instance.isSticky == false) {
199
+ instance.stopKeywordDetection();
200
+ } else if (Platform.OS != 'ios') {
201
+ instance.stopKeywordDetection();
202
+ }*/
203
+ });
204
+ setIsListening(false);
205
+ } catch (error) {
206
+ console.error("Error stopping keyword detection:", error);
207
+ }
208
+ }, []);
209
+
210
+ /**
211
+ * Cleanup effect to stop listening when the component unmounts
212
+ * or when the isListening state changes
213
+ */
214
+ useEffect(() => {
215
+ console.log("isListening updated:", isListening);
216
+ return () => {
217
+ if (isListening) {
218
+ stopListening();
219
+ // Clean all listeners keywordRNBridgeEmitter.removeAllListeners('onKeywordDetectionEvent');
220
+ removeAllRNBridgeListeners();
221
+ }
222
+ };
223
+ }, [isListening, stopListening]);
224
+
225
+ // Return an object with the necessary functions and state
226
+ return {
227
+ isListening,
228
+ startListening,
229
+ loadModel,
230
+ setKeywordDetectionLicense,
231
+ stopListening,
232
+ };
233
+ };
234
+
235
+ export default useModel; // Add this line to allow default import