@picovoice/eagle-web 2.0.0 → 3.0.0
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/.babelrc +4 -4
- package/.eslintrc.js +469 -469
- package/.prettierignore +1 -1
- package/.prettierrc +8 -8
- package/README.md +234 -236
- package/dist/esm/index.js +3656 -11290
- package/dist/esm/index.min.js +1 -1
- package/dist/iife/index.js +3655 -11289
- package/dist/iife/index.min.js +1 -1
- package/dist/types/eagle.d.ts +237 -245
- package/dist/types/eagle.d.ts.map +1 -1
- package/dist/types/eagle_errors.d.ts +47 -47
- package/dist/types/eagle_profiler_worker.d.ts +112 -113
- package/dist/types/eagle_profiler_worker.d.ts.map +1 -1
- package/dist/types/eagle_profiler_worker_handler.d.ts +3 -3
- package/dist/types/eagle_worker.d.ts +88 -93
- package/dist/types/eagle_worker.d.ts.map +1 -1
- package/dist/types/eagle_worker_handler.d.ts +3 -3
- package/dist/types/index.d.ts +6 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +142 -140
- package/dist/types/types.d.ts.map +1 -1
- package/module.d.ts +16 -16
- package/package.json +73 -73
- package/rollup.config.js +75 -75
- package/src/eagle.ts +1546 -1508
- package/src/eagle_errors.ts +252 -252
- package/src/eagle_profiler_worker.ts +443 -405
- package/src/eagle_profiler_worker_handler.ts +246 -208
- package/src/eagle_worker.ts +307 -346
- package/src/eagle_worker_handler.ts +138 -170
- package/src/index.ts +94 -98
- package/src/types.ts +224 -218
- package/tsconfig.json +22 -22
|
@@ -1,208 +1,246 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2023-
|
|
3
|
-
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
4
|
-
file accompanying this source.
|
|
5
|
-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
6
|
-
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
7
|
-
specific language governing permissions and limitations under the License.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/// <reference no-default-lib="false"/>
|
|
11
|
-
/// <reference lib="webworker" />
|
|
12
|
-
|
|
13
|
-
import { EagleProfiler } from './eagle';
|
|
14
|
-
import {
|
|
15
|
-
EagleProfilerWorkerEnrollRequest,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
EagleProfiler.
|
|
37
|
-
EagleProfiler.
|
|
38
|
-
EagleProfiler.
|
|
39
|
-
EagleProfiler.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
request.
|
|
43
|
-
request.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023-2026 Picovoice Inc.
|
|
3
|
+
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
4
|
+
file accompanying this source.
|
|
5
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
6
|
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
7
|
+
specific language governing permissions and limitations under the License.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/// <reference no-default-lib="false"/>
|
|
11
|
+
/// <reference lib="webworker" />
|
|
12
|
+
|
|
13
|
+
import { EagleProfiler } from './eagle';
|
|
14
|
+
import {
|
|
15
|
+
EagleProfilerWorkerEnrollRequest,
|
|
16
|
+
EagleProfilerWorkerFlushRequest,
|
|
17
|
+
EagleProfilerWorkerInitRequest,
|
|
18
|
+
EagleProfilerWorkerRequest,
|
|
19
|
+
PvStatus,
|
|
20
|
+
} from './types';
|
|
21
|
+
import { EagleError } from "./eagle_errors";
|
|
22
|
+
|
|
23
|
+
let profiler: EagleProfiler | null = null;
|
|
24
|
+
|
|
25
|
+
const initRequest = async (
|
|
26
|
+
request: EagleProfilerWorkerInitRequest
|
|
27
|
+
): Promise<any> => {
|
|
28
|
+
if (profiler !== null) {
|
|
29
|
+
return {
|
|
30
|
+
command: 'error',
|
|
31
|
+
status: PvStatus.INVALID_STATE,
|
|
32
|
+
shortMessage: 'Eagle profiler already initialized',
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
EagleProfiler.setWasmSimd(request.wasmSimd);
|
|
37
|
+
EagleProfiler.setWasmSimdLib(request.wasmSimdLib);
|
|
38
|
+
EagleProfiler.setWasmPThread(request.wasmPThread);
|
|
39
|
+
EagleProfiler.setWasmPThreadLib(request.wasmPThreadLib);
|
|
40
|
+
EagleProfiler.setSdk(request.sdk);
|
|
41
|
+
profiler = await EagleProfiler._init(
|
|
42
|
+
request.accessKey,
|
|
43
|
+
request.modelPath,
|
|
44
|
+
request.options
|
|
45
|
+
);
|
|
46
|
+
return {
|
|
47
|
+
command: 'ok',
|
|
48
|
+
frameLength: profiler.frameLength,
|
|
49
|
+
sampleRate: profiler.sampleRate,
|
|
50
|
+
version: profiler.version,
|
|
51
|
+
};
|
|
52
|
+
} catch (e: any) {
|
|
53
|
+
if (e instanceof EagleError) {
|
|
54
|
+
return {
|
|
55
|
+
command: 'error',
|
|
56
|
+
status: e.status,
|
|
57
|
+
shortMessage: e.shortMessage,
|
|
58
|
+
messageStack: e.messageStack
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
return {
|
|
62
|
+
command: 'error',
|
|
63
|
+
status: PvStatus.RUNTIME_ERROR,
|
|
64
|
+
shortMessage: e.message
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const enrollRequest = async (
|
|
71
|
+
request: EagleProfilerWorkerEnrollRequest
|
|
72
|
+
): Promise<any> => {
|
|
73
|
+
if (profiler === null) {
|
|
74
|
+
return {
|
|
75
|
+
command: 'error',
|
|
76
|
+
status: PvStatus.INVALID_STATE,
|
|
77
|
+
shortMessage: 'Eagle profiler not initialized',
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
const result = await profiler.enroll(request.inputFrame);
|
|
82
|
+
return {
|
|
83
|
+
command: 'ok',
|
|
84
|
+
result,
|
|
85
|
+
};
|
|
86
|
+
} catch (e: any) {
|
|
87
|
+
if (e instanceof EagleError) {
|
|
88
|
+
return {
|
|
89
|
+
command: 'error',
|
|
90
|
+
status: e.status,
|
|
91
|
+
shortMessage: e.shortMessage,
|
|
92
|
+
messageStack: e.messageStack
|
|
93
|
+
};
|
|
94
|
+
} else {
|
|
95
|
+
return {
|
|
96
|
+
command: 'error',
|
|
97
|
+
status: PvStatus.RUNTIME_ERROR,
|
|
98
|
+
shortMessage: e.message
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const flushRequest = async (
|
|
105
|
+
request: EagleProfilerWorkerFlushRequest
|
|
106
|
+
): Promise<any> => {
|
|
107
|
+
if (profiler === null) {
|
|
108
|
+
return {
|
|
109
|
+
command: 'error',
|
|
110
|
+
status: PvStatus.INVALID_STATE,
|
|
111
|
+
shortMessage: 'Eagle profiler not initialized',
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const result = await profiler.flush();
|
|
116
|
+
return {
|
|
117
|
+
command: 'ok',
|
|
118
|
+
result,
|
|
119
|
+
};
|
|
120
|
+
} catch (e: any) {
|
|
121
|
+
if (e instanceof EagleError) {
|
|
122
|
+
return {
|
|
123
|
+
command: 'error',
|
|
124
|
+
status: e.status,
|
|
125
|
+
shortMessage: e.shortMessage,
|
|
126
|
+
messageStack: e.messageStack
|
|
127
|
+
};
|
|
128
|
+
} else {
|
|
129
|
+
return {
|
|
130
|
+
command: 'error',
|
|
131
|
+
status: PvStatus.RUNTIME_ERROR,
|
|
132
|
+
shortMessage: e.message
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const exportRequest = async (): Promise<any> => {
|
|
139
|
+
if (profiler === null) {
|
|
140
|
+
return {
|
|
141
|
+
command: 'error',
|
|
142
|
+
status: PvStatus.INVALID_STATE,
|
|
143
|
+
shortMessage: 'Eagle profiler not initialized',
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const profile = await profiler.export();
|
|
148
|
+
return {
|
|
149
|
+
command: 'ok',
|
|
150
|
+
profile,
|
|
151
|
+
};
|
|
152
|
+
} catch (e: any) {
|
|
153
|
+
if (e instanceof EagleError) {
|
|
154
|
+
return {
|
|
155
|
+
command: 'error',
|
|
156
|
+
status: e.status,
|
|
157
|
+
shortMessage: e.shortMessage,
|
|
158
|
+
messageStack: e.messageStack
|
|
159
|
+
};
|
|
160
|
+
} else {
|
|
161
|
+
return {
|
|
162
|
+
command: 'error',
|
|
163
|
+
status: PvStatus.RUNTIME_ERROR,
|
|
164
|
+
shortMessage: e.message
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const resetRequest = async (): Promise<any> => {
|
|
171
|
+
if (profiler === null) {
|
|
172
|
+
return {
|
|
173
|
+
command: 'error',
|
|
174
|
+
status: PvStatus.INVALID_STATE,
|
|
175
|
+
shortMessage: 'Eagle profiler not initialized',
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
try {
|
|
179
|
+
await profiler.reset();
|
|
180
|
+
return {
|
|
181
|
+
command: 'ok',
|
|
182
|
+
};
|
|
183
|
+
} catch (e: any) {
|
|
184
|
+
if (e instanceof EagleError) {
|
|
185
|
+
return {
|
|
186
|
+
command: 'error',
|
|
187
|
+
status: e.status,
|
|
188
|
+
shortMessage: e.shortMessage,
|
|
189
|
+
messageStack: e.messageStack
|
|
190
|
+
};
|
|
191
|
+
} else {
|
|
192
|
+
return {
|
|
193
|
+
command: 'error',
|
|
194
|
+
status: PvStatus.RUNTIME_ERROR,
|
|
195
|
+
shortMessage: e.message
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const releaseRequest = async (): Promise<any> => {
|
|
202
|
+
if (profiler !== null) {
|
|
203
|
+
await profiler.release();
|
|
204
|
+
profiler = null;
|
|
205
|
+
close();
|
|
206
|
+
}
|
|
207
|
+
return {
|
|
208
|
+
command: 'ok',
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Eagle profiler worker handler.
|
|
214
|
+
*/
|
|
215
|
+
self.onmessage = async function (
|
|
216
|
+
event: MessageEvent<EagleProfilerWorkerRequest>
|
|
217
|
+
): Promise<void> {
|
|
218
|
+
switch (event.data.command) {
|
|
219
|
+
case 'init':
|
|
220
|
+
self.postMessage(await initRequest(event.data));
|
|
221
|
+
break;
|
|
222
|
+
case 'enroll':
|
|
223
|
+
self.postMessage(await enrollRequest(event.data));
|
|
224
|
+
break;
|
|
225
|
+
case 'flush':
|
|
226
|
+
self.postMessage(await flushRequest(event.data));
|
|
227
|
+
break;
|
|
228
|
+
case 'export': {
|
|
229
|
+
const exportMsg = await exportRequest();
|
|
230
|
+
self.postMessage(exportMsg, [exportMsg.profile.bytes.buffer]);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
case 'reset':
|
|
234
|
+
self.postMessage(await resetRequest());
|
|
235
|
+
break;
|
|
236
|
+
case 'release':
|
|
237
|
+
self.postMessage(await releaseRequest());
|
|
238
|
+
break;
|
|
239
|
+
default:
|
|
240
|
+
self.postMessage({
|
|
241
|
+
command: 'failed',
|
|
242
|
+
// @ts-ignore
|
|
243
|
+
message: `Unrecognized command: ${event.data.command}`,
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
};
|