react-native-wakeword 1.0.30 → 1.0.32
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 +1 -5
- package/package.json +7 -2
- package/wakewords/KeyWordRNBridge.d.ts +7 -7
- package/wakewords/KeyWordRNBridge.js +10 -15
- package/wakewords/useModel.d.ts +8 -1
- package/wakewords/useModel.tsx +19 -10
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
|
-
|
|
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.
|
|
3
|
+
"version": "1.0.32",
|
|
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,10 +31,15 @@
|
|
|
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",
|
|
36
38
|
"speech to intent",
|
|
37
|
-
"
|
|
39
|
+
"voice to intent",
|
|
40
|
+
"phrase spotting",
|
|
41
|
+
"react native wake word",
|
|
42
|
+
"rn wake word"
|
|
38
43
|
],
|
|
39
44
|
"author": "Davoice.io",
|
|
40
45
|
"license": "MIT"
|
|
@@ -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
|
-
|
|
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
|
|
package/wakewords/useModel.d.ts
CHANGED
|
@@ -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: (
|
|
15
|
+
loadModel: (useConfigs: instanceConfig[], callback: (phrase: string) => void) => Promise<void>;
|
|
9
16
|
setKeywordDetectionLicense: (licenseKey: string) => Promise<void>;
|
|
10
17
|
stopListening: () => Promise<void>;
|
|
11
18
|
};
|
package/wakewords/useModel.tsx
CHANGED
|
@@ -31,6 +31,14 @@ var instanceConfigs:instanceConfig[] = [
|
|
|
31
31
|
{ id: 'need_help_now', modelName: 'need_help_now.onnx', threshold: 0.9999, bufferCnt: 3 , sticky: false },
|
|
32
32
|
];
|
|
33
33
|
|
|
34
|
+
// Helper function to format the ONNX file name
|
|
35
|
+
const formatWakeWord = (fileName) => {
|
|
36
|
+
return fileName
|
|
37
|
+
.replace(/_/g, ' ') // Use global flag to replace all underscores
|
|
38
|
+
.replace('.onnx', '')
|
|
39
|
+
.replace(/\b\w/g, (char) => char.toUpperCase()); // Capitalize each word
|
|
40
|
+
};
|
|
41
|
+
|
|
34
42
|
// Function to add a new instance dynamically
|
|
35
43
|
//async function addInstance(
|
|
36
44
|
// conf: instanceConfig)
|
|
@@ -43,7 +51,7 @@ async function addInstance(
|
|
|
43
51
|
if (instanceConf != null) {
|
|
44
52
|
console.log("Found Instance: ", id, "starting to listen");
|
|
45
53
|
const instance = instanceConf.instance;
|
|
46
|
-
instance.startKeywordDetection(conf.threshold);
|
|
54
|
+
await instance.startKeywordDetection(conf.threshold);
|
|
47
55
|
return instance;
|
|
48
56
|
}
|
|
49
57
|
const instance = await createKeyWordRNBridgeInstance(id, conf.sticky);
|
|
@@ -63,12 +71,13 @@ async function addInstance(
|
|
|
63
71
|
keyWordRNBridgeInstances.push({ id, instance });
|
|
64
72
|
// Set up event listener
|
|
65
73
|
instance.onKeywordDetectionEvent((phrase: string) => {
|
|
74
|
+
phrase = formatWakeWord(id);
|
|
66
75
|
console.log(`Instance ${id} detected: ${id} with phrase`, phrase);
|
|
67
76
|
// callback(phrase); Does not work on IOS
|
|
68
|
-
callback(
|
|
77
|
+
callback(phrase);
|
|
69
78
|
});
|
|
70
79
|
console.log(`Instance ${id} calling startKeywordDetection()`);
|
|
71
|
-
instance.startKeywordDetection(conf.threshold);
|
|
80
|
+
await instance.startKeywordDetection(conf.threshold);
|
|
72
81
|
console.log(`Instance ${id} started Keyword Detection`);
|
|
73
82
|
return instance;
|
|
74
83
|
}
|
|
@@ -140,9 +149,9 @@ export const useModel = () => {
|
|
|
140
149
|
let element:any = null;
|
|
141
150
|
console.log("loadModel() - instanceConfigs == ", instanceConfigs)
|
|
142
151
|
try {
|
|
143
|
-
instanceConfigs.forEach(element => {
|
|
144
|
-
|
|
145
|
-
|
|
152
|
+
instanceConfigs.forEach(async element => {
|
|
153
|
+
console.log('Adding element:', element);
|
|
154
|
+
const id = await addInstance(element, callback);
|
|
146
155
|
});
|
|
147
156
|
} catch (error) {
|
|
148
157
|
console.error("[useModel] Error loading model:", error);
|
|
@@ -154,11 +163,11 @@ export const useModel = () => {
|
|
|
154
163
|
*/
|
|
155
164
|
const startListening = useCallback(async () => {
|
|
156
165
|
try {
|
|
157
|
-
keyWordRNBridgeInstances.forEach(element => {
|
|
166
|
+
keyWordRNBridgeInstances.forEach(async element => {
|
|
158
167
|
const instance = element.instance;
|
|
159
168
|
const conf = instanceConfigs.find(element => element.id === instance.instanceId);
|
|
160
169
|
if (conf) {
|
|
161
|
-
instance.startKeywordDetection(conf.threshold);
|
|
170
|
+
await instance.startKeywordDetection(conf.threshold);
|
|
162
171
|
} else {
|
|
163
172
|
console.error(`No configuration found for instance ID: ${instance.instanceId}`);
|
|
164
173
|
}
|
|
@@ -179,9 +188,9 @@ export const useModel = () => {
|
|
|
179
188
|
*/
|
|
180
189
|
const stopListening = useCallback(async () => {
|
|
181
190
|
try {
|
|
182
|
-
keyWordRNBridgeInstances.forEach(element => {
|
|
191
|
+
keyWordRNBridgeInstances.forEach(async element => {
|
|
183
192
|
const instance = element.instance;
|
|
184
|
-
instance.stopKeywordDetection();
|
|
193
|
+
await instance.stopKeywordDetection();
|
|
185
194
|
/*if (instance.isSticky == false) {
|
|
186
195
|
instance.stopKeywordDetection();
|
|
187
196
|
} else if (Platform.OS != 'ios') {
|