react-native-wakeword 1.0.29 → 1.0.31

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/README.md CHANGED
@@ -3,11 +3,7 @@ DaVoice.io Voice commands / Wake words / Voice to Intent / keyword detection npm
3
3
 
4
4
  Contact us at info@DaVoice.io
5
5
 
6
- ## What's in this package
7
-
8
- ### This package includes
9
- 1. "Wake Word" (also known as: "keyword detection" and "phrase spotting") api to enable ios and android applications.
10
- 2. "Speech to Intent" (also known as: "voice commands" and "phrase spotting") very similar to "Wake Word" however mainly used to use speech command to control the application rather than waking up the application.
6
+ # IOS and Android Package
11
7
 
12
8
  ## Installation
13
9
  npm install react-native-wakeword
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-wakeword",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Voice/Wake-word detection library for React Native",
5
5
  "main": "wakewords/index.js",
6
6
  "types": "wakewords/index.d.ts",
@@ -31,8 +31,12 @@
31
31
  "react-native",
32
32
  "voice commands",
33
33
  "wake word",
34
+ "wakeword",
35
+ "wake words",
34
36
  "keyword detection",
35
37
  "keyword spotting",
38
+ "speech to intent",
39
+ "voice to intent",
36
40
  "phrase spotting"
37
41
  ],
38
42
  "author": "Davoice.io",
@@ -4,13 +4,13 @@ export class KeyWordRNBridgeInstance {
4
4
  listeners: any[];
5
5
  isFirstInstance: boolean;
6
6
  isSticky: any;
7
- createInstance(modelName: any, threshold: any, bufferCnt: any): any;
8
- setKeywordDetectionLicense(license: any): any;
9
- replaceKeywordDetectionModel(modelName: any, threshold: any, bufferCnt: any): any;
10
- setKeywordLicense(license: any): any;
11
- startKeywordDetection(threshold: any): any;
12
- stopKeywordDetection(): any;
13
- destroyInstance(): any;
7
+ createInstance(modelName: any, threshold: any, bufferCnt: any): Promise<any>;
8
+ setKeywordDetectionLicense(license: any): Promise<any>;
9
+ replaceKeywordDetectionModel(modelName: any, threshold: any, bufferCnt: any): Promise<any>;
10
+ setKeywordLicense(license: any): Promise<any>;
11
+ startKeywordDetection(threshold: any): Promise<any>;
12
+ stopKeywordDetection(): Promise<any>;
13
+ destroyInstance(): Promise<any>;
14
14
  onKeywordDetectionEvent(callback: any): void;
15
15
  removeListeners(): void;
16
16
  }
@@ -20,30 +20,25 @@ export class KeyWordRNBridgeInstance {
20
20
  this.isSticky = isSticky;
21
21
  }
22
22
 
23
- createInstance(
24
- modelName,
25
- threshold,
26
- bufferCnt)
27
- {
28
- instance = KeyWordRNBridge.createInstance(
23
+ async createInstance(modelName, threshold, bufferCnt) {
24
+ instance = await KeyWordRNBridge.createInstance(
29
25
  this.instanceId,
30
26
  modelName,
31
27
  threshold,
32
- bufferCnt
33
- );
28
+ bufferCnt);
34
29
  if (instance && this.isFirstInstance)
35
30
  {
36
31
  this.isFirstInstance = false;
37
- KeyWordRNBridge.startForegroundService(this.instanceId);
32
+ await KeyWordRNBridge.startForegroundService(this.instanceId);
38
33
  }
39
34
  return instance;
40
35
  }
41
36
 
42
- setKeywordDetectionLicense(license) {
37
+ async setKeywordDetectionLicense(license) {
43
38
  return KeyWordRNBridge.setKeywordDetectionLicense(this.instanceId, license);
44
39
  }
45
40
 
46
- replaceKeywordDetectionModel(modelName, threshold, bufferCnt) {
41
+ async replaceKeywordDetectionModel(modelName, threshold, bufferCnt) {
47
42
  return KeyWordRNBridge.replaceKeywordDetectionModel(this.instanceId, modelName, threshold, bufferCnt);
48
43
  }
49
44
  /*startForegroundService() {
@@ -53,19 +48,19 @@ export class KeyWordRNBridgeInstance {
53
48
  stopForegroundService() {
54
49
  return KeyWordRNBridge.stopForegroundService(this.instanceId);
55
50
  }*/
56
- setKeywordLicense(license) {
51
+ async setKeywordLicense(license) {
57
52
  return KeyWordRNBridge.setKeywordLicense(this.instanceId, license);
58
53
  }
59
54
 
60
- startKeywordDetection(threshold) {
55
+ async startKeywordDetection(threshold) {
61
56
  return KeyWordRNBridge.startKeywordDetection(this.instanceId, threshold);
62
57
  }
63
58
 
64
- stopKeywordDetection() {
59
+ async stopKeywordDetection() {
65
60
  return KeyWordRNBridge.stopKeywordDetection(this.instanceId);
66
61
  }
67
62
 
68
- destroyInstance() {
63
+ async destroyInstance() {
69
64
  return KeyWordRNBridge.destroyInstance(this.instanceId);
70
65
  }
71
66
 
@@ -1,3 +1,10 @@
1
+ interface instanceConfig {
2
+ id: string;
3
+ modelName: string;
4
+ threshold: number;
5
+ bufferCnt: number;
6
+ sticky: boolean;
7
+ }
1
8
  /**
2
9
  * Custom hook for handling keyword detection using KeyWordRNBridge
3
10
  * @returns An object with functions and state for keyword detection
@@ -5,7 +12,7 @@
5
12
  export declare const useModel: () => {
6
13
  isListening: boolean;
7
14
  startListening: () => Promise<void>;
8
- loadModel: (models: [string], callback: (phrase: string) => void) => Promise<void>;
15
+ loadModel: (useConfigs: instanceConfig[], callback: (phrase: string) => void) => Promise<void>;
9
16
  setKeywordDetectionLicense: (licenseKey: string) => Promise<void>;
10
17
  stopListening: () => Promise<void>;
11
18
  };
@@ -27,9 +27,8 @@ function findInstanceById(id: string): keyWordRNBridgeInstanceConfig | undefined
27
27
  }
28
28
 
29
29
  // Create an array of instance configurations
30
- const instanceConfigs:instanceConfig[] = [
30
+ var instanceConfigs:instanceConfig[] = [
31
31
  { id: 'need_help_now', modelName: 'need_help_now.onnx', threshold: 0.9999, bufferCnt: 3 , sticky: false },
32
- { id: 'default', modelName: "", threshold: 0.9999, bufferCnt: 2 , sticky: false }
33
32
  ];
34
33
 
35
34
  // Function to add a new instance dynamically
@@ -44,7 +43,7 @@ async function addInstance(
44
43
  if (instanceConf != null) {
45
44
  console.log("Found Instance: ", id, "starting to listen");
46
45
  const instance = instanceConf.instance;
47
- instance.startKeywordDetection(conf.threshold);
46
+ await instance.startKeywordDetection(conf.threshold);
48
47
  return instance;
49
48
  }
50
49
  const instance = await createKeyWordRNBridgeInstance(id, conf.sticky);
@@ -69,7 +68,7 @@ async function addInstance(
69
68
  callback(id);
70
69
  });
71
70
  console.log(`Instance ${id} calling startKeywordDetection()`);
72
- instance.startKeywordDetection(conf.threshold);
71
+ await instance.startKeywordDetection(conf.threshold);
73
72
  console.log(`Instance ${id} started Keyword Detection`);
74
73
  return instance;
75
74
  }
@@ -134,27 +133,16 @@ export const useModel = () => {
134
133
  * @param bufferCount - The number of audio buffers
135
134
  */
136
135
  const loadModel = useCallback(
137
- async (models: [string], callback: (phrase: string) => void): Promise<void> => {
136
+ async (useConfigs: instanceConfig[], callback: (phrase: string) => void): Promise<void> => {
138
137
 
139
138
  console.log("loadModel()");
140
- let searchIds = models;
139
+ instanceConfigs = useConfigs;
141
140
  let element:any = null;
142
- console.log("loadModel() - models == ", models)
141
+ console.log("loadModel() - instanceConfigs == ", instanceConfigs)
143
142
  try {
144
- stopListening();
145
- searchIds.forEach(sId => {
146
- element = instanceConfigs.find(element => element.id === sId.split(".")[0]);
147
- if (element == null || element == undefined) {
148
- //console.error('element id' + sId + " not found in instanceConfigs");
149
- //return;
150
- }
151
- else {
152
- element = Object.assign({}, instanceConfigs.find(element => element.id === 'default'));
153
- element.modelName = sId;
154
- element.id = sId.split(".")[0];
155
- }
156
- console.log('element:', element);
157
- const id = addInstance(element, callback);
143
+ instanceConfigs.forEach(async element => {
144
+ console.log('Adding element:', element);
145
+ const id = await addInstance(element, callback);
158
146
  });
159
147
  } catch (error) {
160
148
  console.error("[useModel] Error loading model:", error);
@@ -166,9 +154,14 @@ export const useModel = () => {
166
154
  */
167
155
  const startListening = useCallback(async () => {
168
156
  try {
169
- keyWordRNBridgeInstances.forEach(element => {
157
+ keyWordRNBridgeInstances.forEach(async element => {
170
158
  const instance = element.instance;
171
- instance.startKeywordDetection();
159
+ const conf = instanceConfigs.find(element => element.id === instance.instanceId);
160
+ if (conf) {
161
+ await instance.startKeywordDetection(conf.threshold);
162
+ } else {
163
+ console.error(`No configuration found for instance ID: ${instance.instanceId}`);
164
+ }
172
165
  /*if (instance.isSticky == false) {
173
166
  instance.stopKeywordDetection();
174
167
  } else if (Platform.OS != 'ios') {
@@ -186,9 +179,9 @@ export const useModel = () => {
186
179
  */
187
180
  const stopListening = useCallback(async () => {
188
181
  try {
189
- keyWordRNBridgeInstances.forEach(element => {
182
+ keyWordRNBridgeInstances.forEach(async element => {
190
183
  const instance = element.instance;
191
- instance.stopKeywordDetection();
184
+ await instance.stopKeywordDetection();
192
185
  /*if (instance.isSticky == false) {
193
186
  instance.stopKeywordDetection();
194
187
  } else if (Platform.OS != 'ios') {