@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,405 +1,443 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright 2023-
|
|
3
|
-
|
|
4
|
-
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
5
|
-
file accompanying this source.
|
|
6
|
-
|
|
7
|
-
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
8
|
-
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
9
|
-
specific language governing permissions and limitations under the License.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import PvWorker from 'web-worker:./eagle_profiler_worker_handler.ts';
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
EagleModel,
|
|
16
|
-
EagleProfile,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
EagleProfilerWorkerExportResponse,
|
|
21
|
-
EagleProfilerWorkerInitResponse,
|
|
22
|
-
EagleProfilerWorkerReleaseResponse,
|
|
23
|
-
EagleProfilerWorkerResetResponse,
|
|
24
|
-
PvStatus,
|
|
25
|
-
} from './types';
|
|
26
|
-
import { loadModel } from '@picovoice/web-utils';
|
|
27
|
-
import { pvStatusToException } from "./eagle_errors";
|
|
28
|
-
|
|
29
|
-
export class EagleProfilerWorker {
|
|
30
|
-
private readonly _worker: Worker;
|
|
31
|
-
private readonly
|
|
32
|
-
private readonly _sampleRate: number;
|
|
33
|
-
private readonly _version: string;
|
|
34
|
-
|
|
35
|
-
private static _wasmSimd: string;
|
|
36
|
-
private static _wasmSimdLib: string;
|
|
37
|
-
private static _wasmPThread: string;
|
|
38
|
-
private static _wasmPThreadLib: string;
|
|
39
|
-
|
|
40
|
-
private static _sdk: string = 'web';
|
|
41
|
-
|
|
42
|
-
private constructor(
|
|
43
|
-
worker: Worker,
|
|
44
|
-
|
|
45
|
-
sampleRate: number,
|
|
46
|
-
version: string
|
|
47
|
-
) {
|
|
48
|
-
this._worker = worker;
|
|
49
|
-
this.
|
|
50
|
-
this._sampleRate = sampleRate;
|
|
51
|
-
this._version = version;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* The
|
|
56
|
-
*/
|
|
57
|
-
get
|
|
58
|
-
return this.
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Audio sample rate required by Eagle.
|
|
63
|
-
*/
|
|
64
|
-
get sampleRate(): number {
|
|
65
|
-
return this._sampleRate;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Version of Eagle.
|
|
70
|
-
*/
|
|
71
|
-
get version(): string {
|
|
72
|
-
return this._version;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Set base64 wasm file with SIMD feature.
|
|
77
|
-
* @param wasmSimd Base64'd wasm SIMD file to use to initialize wasm.
|
|
78
|
-
*/
|
|
79
|
-
public static setWasmSimd(wasmSimd: string): void {
|
|
80
|
-
if (this._wasmSimd === undefined) {
|
|
81
|
-
this._wasmSimd = wasmSimd;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Set base64 wasm file with SIMD feature in text format.
|
|
87
|
-
* @param wasmSimdLib Base64'd wasm SIMD file in text format.
|
|
88
|
-
*/
|
|
89
|
-
public static setWasmSimdLib(wasmSimdLib: string): void {
|
|
90
|
-
if (this._wasmSimdLib === undefined) {
|
|
91
|
-
this._wasmSimdLib = wasmSimdLib;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Set base64 wasm file with SIMD and pthread feature.
|
|
97
|
-
* @param wasmPThread Base64'd wasm file to use to initialize wasm.
|
|
98
|
-
*/
|
|
99
|
-
public static setWasmPThread(wasmPThread: string): void {
|
|
100
|
-
if (this._wasmPThread === undefined) {
|
|
101
|
-
this._wasmPThread = wasmPThread;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Set base64 SIMD and thread wasm file in text format.
|
|
107
|
-
* @param wasmPThreadLib Base64'd wasm file in text format.
|
|
108
|
-
*/
|
|
109
|
-
public static setWasmPThreadLib(wasmPThreadLib: string): void {
|
|
110
|
-
if (this._wasmPThreadLib === undefined) {
|
|
111
|
-
this._wasmPThreadLib = wasmPThreadLib;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
public static setSdk(sdk: string): void {
|
|
116
|
-
EagleProfilerWorker._sdk = sdk;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Creates an instance of profiler component of the Eagle Speaker Recognition Engine.
|
|
121
|
-
*
|
|
122
|
-
* @param accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).
|
|
123
|
-
* @param model Eagle model options.
|
|
124
|
-
* @param model.base64 The model in base64 string to initialize Eagle.
|
|
125
|
-
* @param model.publicPath The model path relative to the public directory.
|
|
126
|
-
* @param model.customWritePath Custom path to save the model in storage.
|
|
127
|
-
* Set to a different name to use multiple models across `eagle` instances.
|
|
128
|
-
* @param model.forceWrite Flag to overwrite the model in storage even if it exists.
|
|
129
|
-
* @param model.version Version of the model file. Increment to update the model file in storage.
|
|
130
|
-
* @param options Optional configuration arguments.
|
|
131
|
-
* @param options.device String representation of the device (e.g., CPU or GPU) to use. If set to `best`, the most
|
|
132
|
-
* suitable device is selected automatically. If set to `gpu`, the engine uses the first available GPU device. To select a specific
|
|
133
|
-
* GPU device, set this argument to `gpu:${GPU_INDEX}`, where `${GPU_INDEX}` is the index of the target GPU. If set to
|
|
134
|
-
* `cpu`, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this
|
|
135
|
-
* argument to `cpu:${NUM_THREADS}`, where `${NUM_THREADS}` is the desired number of threads.
|
|
136
|
-
*
|
|
137
|
-
* @
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
event.data.
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
event.data.
|
|
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
|
-
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* -
|
|
215
|
-
* -
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
event
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
event.data.
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2023-2026 Picovoice Inc.
|
|
3
|
+
|
|
4
|
+
You may not use this file except in compliance with the license. A copy of the license is located in the "LICENSE"
|
|
5
|
+
file accompanying this source.
|
|
6
|
+
|
|
7
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
|
8
|
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
9
|
+
specific language governing permissions and limitations under the License.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import PvWorker from 'web-worker:./eagle_profiler_worker_handler.ts';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
EagleModel,
|
|
16
|
+
EagleProfile,
|
|
17
|
+
EagleProfilerOptions,
|
|
18
|
+
EagleProfilerWorkerEnrollResponse,
|
|
19
|
+
EagleProfilerWorkerFlushResponse,
|
|
20
|
+
EagleProfilerWorkerExportResponse,
|
|
21
|
+
EagleProfilerWorkerInitResponse,
|
|
22
|
+
EagleProfilerWorkerReleaseResponse,
|
|
23
|
+
EagleProfilerWorkerResetResponse,
|
|
24
|
+
PvStatus,
|
|
25
|
+
} from './types';
|
|
26
|
+
import { loadModel } from '@picovoice/web-utils';
|
|
27
|
+
import { pvStatusToException } from "./eagle_errors";
|
|
28
|
+
|
|
29
|
+
export class EagleProfilerWorker {
|
|
30
|
+
private readonly _worker: Worker;
|
|
31
|
+
private readonly _frameLength: number;
|
|
32
|
+
private readonly _sampleRate: number;
|
|
33
|
+
private readonly _version: string;
|
|
34
|
+
|
|
35
|
+
private static _wasmSimd: string;
|
|
36
|
+
private static _wasmSimdLib: string;
|
|
37
|
+
private static _wasmPThread: string;
|
|
38
|
+
private static _wasmPThreadLib: string;
|
|
39
|
+
|
|
40
|
+
private static _sdk: string = 'web';
|
|
41
|
+
|
|
42
|
+
private constructor(
|
|
43
|
+
worker: Worker,
|
|
44
|
+
frameLength: number,
|
|
45
|
+
sampleRate: number,
|
|
46
|
+
version: string
|
|
47
|
+
) {
|
|
48
|
+
this._worker = worker;
|
|
49
|
+
this._frameLength = frameLength;
|
|
50
|
+
this._sampleRate = sampleRate;
|
|
51
|
+
this._version = version;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The length of the input pcm required by `.enroll()`.
|
|
56
|
+
*/
|
|
57
|
+
get frameLength(): number {
|
|
58
|
+
return this._frameLength;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Audio sample rate required by Eagle.
|
|
63
|
+
*/
|
|
64
|
+
get sampleRate(): number {
|
|
65
|
+
return this._sampleRate;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Version of Eagle.
|
|
70
|
+
*/
|
|
71
|
+
get version(): string {
|
|
72
|
+
return this._version;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Set base64 wasm file with SIMD feature.
|
|
77
|
+
* @param wasmSimd Base64'd wasm SIMD file to use to initialize wasm.
|
|
78
|
+
*/
|
|
79
|
+
public static setWasmSimd(wasmSimd: string): void {
|
|
80
|
+
if (this._wasmSimd === undefined) {
|
|
81
|
+
this._wasmSimd = wasmSimd;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Set base64 wasm file with SIMD feature in text format.
|
|
87
|
+
* @param wasmSimdLib Base64'd wasm SIMD file in text format.
|
|
88
|
+
*/
|
|
89
|
+
public static setWasmSimdLib(wasmSimdLib: string): void {
|
|
90
|
+
if (this._wasmSimdLib === undefined) {
|
|
91
|
+
this._wasmSimdLib = wasmSimdLib;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Set base64 wasm file with SIMD and pthread feature.
|
|
97
|
+
* @param wasmPThread Base64'd wasm file to use to initialize wasm.
|
|
98
|
+
*/
|
|
99
|
+
public static setWasmPThread(wasmPThread: string): void {
|
|
100
|
+
if (this._wasmPThread === undefined) {
|
|
101
|
+
this._wasmPThread = wasmPThread;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Set base64 SIMD and thread wasm file in text format.
|
|
107
|
+
* @param wasmPThreadLib Base64'd wasm file in text format.
|
|
108
|
+
*/
|
|
109
|
+
public static setWasmPThreadLib(wasmPThreadLib: string): void {
|
|
110
|
+
if (this._wasmPThreadLib === undefined) {
|
|
111
|
+
this._wasmPThreadLib = wasmPThreadLib;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public static setSdk(sdk: string): void {
|
|
116
|
+
EagleProfilerWorker._sdk = sdk;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Creates an instance of profiler component of the Eagle Speaker Recognition Engine.
|
|
121
|
+
*
|
|
122
|
+
* @param accessKey AccessKey obtained from Picovoice Console (https://console.picovoice.ai/).
|
|
123
|
+
* @param model Eagle model options.
|
|
124
|
+
* @param model.base64 The model in base64 string to initialize Eagle.
|
|
125
|
+
* @param model.publicPath The model path relative to the public directory.
|
|
126
|
+
* @param model.customWritePath Custom path to save the model in storage.
|
|
127
|
+
* Set to a different name to use multiple models across `eagle` instances.
|
|
128
|
+
* @param model.forceWrite Flag to overwrite the model in storage even if it exists.
|
|
129
|
+
* @param model.version Version of the model file. Increment to update the model file in storage.
|
|
130
|
+
* @param options Optional configuration arguments.
|
|
131
|
+
* @param options.device String representation of the device (e.g., CPU or GPU) to use. If set to `best`, the most
|
|
132
|
+
* suitable device is selected automatically. If set to `gpu`, the engine uses the first available GPU device. To select a specific
|
|
133
|
+
* GPU device, set this argument to `gpu:${GPU_INDEX}`, where `${GPU_INDEX}` is the index of the target GPU. If set to
|
|
134
|
+
* `cpu`, the engine will run on the CPU with the default number of threads. To specify the number of threads, set this
|
|
135
|
+
* argument to `cpu:${NUM_THREADS}`, where `${NUM_THREADS}` is the desired number of threads.
|
|
136
|
+
* @param options.minEnrollmentChunks Minimum number of chunks to be processed before enroll returns 100%
|
|
137
|
+
* @param options.voiceThreshold Sensitivity threshold for detecting voice.
|
|
138
|
+
*
|
|
139
|
+
* @return An instance of the Eagle Profiler.
|
|
140
|
+
*/
|
|
141
|
+
public static async create(
|
|
142
|
+
accessKey: string,
|
|
143
|
+
model: EagleModel,
|
|
144
|
+
options: EagleProfilerOptions = {}
|
|
145
|
+
): Promise<EagleProfilerWorker> {
|
|
146
|
+
const customWritePath = model.customWritePath
|
|
147
|
+
? model.customWritePath
|
|
148
|
+
: 'eagle_model';
|
|
149
|
+
const modelPath = await loadModel({ ...model, customWritePath });
|
|
150
|
+
|
|
151
|
+
const worker = new PvWorker();
|
|
152
|
+
const returnPromise: Promise<EagleProfilerWorker> = new Promise(
|
|
153
|
+
(resolve, reject) => {
|
|
154
|
+
// @ts-ignore - block from GC
|
|
155
|
+
this.worker = worker;
|
|
156
|
+
worker.onmessage = (
|
|
157
|
+
event: MessageEvent<EagleProfilerWorkerInitResponse>
|
|
158
|
+
): void => {
|
|
159
|
+
switch (event.data.command) {
|
|
160
|
+
case 'ok':
|
|
161
|
+
resolve(
|
|
162
|
+
new EagleProfilerWorker(
|
|
163
|
+
worker,
|
|
164
|
+
event.data.frameLength,
|
|
165
|
+
event.data.sampleRate,
|
|
166
|
+
event.data.version
|
|
167
|
+
)
|
|
168
|
+
);
|
|
169
|
+
break;
|
|
170
|
+
case 'failed':
|
|
171
|
+
case 'error':
|
|
172
|
+
reject(
|
|
173
|
+
pvStatusToException(
|
|
174
|
+
event.data.status,
|
|
175
|
+
event.data.shortMessage,
|
|
176
|
+
event.data.messageStack
|
|
177
|
+
)
|
|
178
|
+
);
|
|
179
|
+
break;
|
|
180
|
+
default:
|
|
181
|
+
reject(
|
|
182
|
+
pvStatusToException(
|
|
183
|
+
PvStatus.RUNTIME_ERROR,
|
|
184
|
+
// @ts-ignore
|
|
185
|
+
`Unrecognized command: ${event.data.command}`
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
worker.postMessage({
|
|
194
|
+
command: 'init',
|
|
195
|
+
accessKey: accessKey,
|
|
196
|
+
modelPath: modelPath,
|
|
197
|
+
options: options,
|
|
198
|
+
wasmSimd: this._wasmSimd,
|
|
199
|
+
wasmSimdLib: this._wasmSimdLib,
|
|
200
|
+
wasmPThread: this._wasmPThread,
|
|
201
|
+
wasmPThreadLib: this._wasmPThreadLib,
|
|
202
|
+
sdk: this._sdk,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return returnPromise;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Enrolls a speaker. This function should be called multiple times with different utterances of the same speaker
|
|
210
|
+
* until `percentage` reaches `100.0`, at which point a speaker voice profile can be exported using `.export()`.
|
|
211
|
+
* Any further enrollment can be used to improve the speaker profile. The minimum length of the input pcm to
|
|
212
|
+
* `.enroll()` can be obtained by calling `.minEnrollSamples`.
|
|
213
|
+
* The audio data used for enrollment should satisfy the following requirements:
|
|
214
|
+
* - only one speaker should be present in the audio
|
|
215
|
+
* - the speaker should be speaking in a normal voice
|
|
216
|
+
* - the audio should contain no speech from other speakers and no other sounds (e.g. music)
|
|
217
|
+
* - it should be captured in a quiet environment with no background noise
|
|
218
|
+
* @param pcm Audio data for enrollment. The audio needs to have a sample rate equal to `.sampleRate` and be
|
|
219
|
+
* 16-bit linearly-encoded. EagleProfiler operates on single-channel audio.
|
|
220
|
+
*
|
|
221
|
+
* @return The percentage of completeness of the speaker enrollment process.
|
|
222
|
+
*/
|
|
223
|
+
public enroll(pcm: Int16Array): Promise<number> {
|
|
224
|
+
const returnPromise: Promise<number> = new Promise(
|
|
225
|
+
(resolve, reject) => {
|
|
226
|
+
this._worker.onmessage = (
|
|
227
|
+
event: MessageEvent<EagleProfilerWorkerEnrollResponse>
|
|
228
|
+
): void => {
|
|
229
|
+
switch (event.data.command) {
|
|
230
|
+
case 'ok':
|
|
231
|
+
resolve(event.data.result);
|
|
232
|
+
break;
|
|
233
|
+
case 'failed':
|
|
234
|
+
case 'error':
|
|
235
|
+
reject(
|
|
236
|
+
pvStatusToException(
|
|
237
|
+
event.data.status,
|
|
238
|
+
event.data.shortMessage,
|
|
239
|
+
event.data.messageStack
|
|
240
|
+
)
|
|
241
|
+
);
|
|
242
|
+
break;
|
|
243
|
+
default:
|
|
244
|
+
reject(
|
|
245
|
+
pvStatusToException(
|
|
246
|
+
PvStatus.RUNTIME_ERROR,
|
|
247
|
+
// @ts-ignore
|
|
248
|
+
`Unrecognized command: ${event.data.command}`
|
|
249
|
+
)
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
this._worker.postMessage({
|
|
257
|
+
command: 'enroll',
|
|
258
|
+
inputFrame: pcm,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
return returnPromise;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Marks the end of the audio stream, flushes internal state of the object, and returns the percentage of enrollment
|
|
266
|
+
* completed.
|
|
267
|
+
*
|
|
268
|
+
* @return The percentage of completeness of the speaker enrollment process.
|
|
269
|
+
*/
|
|
270
|
+
public flush(): Promise<number> {
|
|
271
|
+
const returnPromise: Promise<number> = new Promise(
|
|
272
|
+
(resolve, reject) => {
|
|
273
|
+
this._worker.onmessage = (
|
|
274
|
+
event: MessageEvent<EagleProfilerWorkerFlushResponse>
|
|
275
|
+
): void => {
|
|
276
|
+
switch (event.data.command) {
|
|
277
|
+
case 'ok':
|
|
278
|
+
resolve(event.data.result);
|
|
279
|
+
break;
|
|
280
|
+
case 'failed':
|
|
281
|
+
case 'error':
|
|
282
|
+
reject(
|
|
283
|
+
pvStatusToException(
|
|
284
|
+
event.data.status,
|
|
285
|
+
event.data.shortMessage,
|
|
286
|
+
event.data.messageStack
|
|
287
|
+
)
|
|
288
|
+
);
|
|
289
|
+
break;
|
|
290
|
+
default:
|
|
291
|
+
reject(
|
|
292
|
+
pvStatusToException(
|
|
293
|
+
PvStatus.RUNTIME_ERROR,
|
|
294
|
+
// @ts-ignore
|
|
295
|
+
`Unrecognized command: ${event.data.command}`
|
|
296
|
+
)
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
this._worker.postMessage({
|
|
304
|
+
command: 'flush',
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
return returnPromise;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Exports the speaker profile of the current session.
|
|
312
|
+
* Will throw error if the profile is not ready.
|
|
313
|
+
*
|
|
314
|
+
* @return An EagleProfile object.
|
|
315
|
+
*/
|
|
316
|
+
public async export(): Promise<EagleProfile> {
|
|
317
|
+
const returnPromise: Promise<EagleProfile> = new Promise(
|
|
318
|
+
(resolve, reject) => {
|
|
319
|
+
this._worker.onmessage = (
|
|
320
|
+
event: MessageEvent<EagleProfilerWorkerExportResponse>
|
|
321
|
+
): void => {
|
|
322
|
+
switch (event.data.command) {
|
|
323
|
+
case 'ok':
|
|
324
|
+
resolve(event.data.profile);
|
|
325
|
+
break;
|
|
326
|
+
case 'failed':
|
|
327
|
+
case 'error':
|
|
328
|
+
reject(
|
|
329
|
+
pvStatusToException(
|
|
330
|
+
event.data.status,
|
|
331
|
+
event.data.shortMessage,
|
|
332
|
+
event.data.messageStack
|
|
333
|
+
)
|
|
334
|
+
);
|
|
335
|
+
break;
|
|
336
|
+
default:
|
|
337
|
+
reject(
|
|
338
|
+
pvStatusToException(
|
|
339
|
+
PvStatus.RUNTIME_ERROR,
|
|
340
|
+
// @ts-ignore
|
|
341
|
+
`Unrecognized command: ${event.data.command}`
|
|
342
|
+
)
|
|
343
|
+
);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
);
|
|
348
|
+
this._worker.postMessage({
|
|
349
|
+
command: 'export',
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
return returnPromise;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
/**
|
|
356
|
+
* Resets the internal state of Eagle Profiler.
|
|
357
|
+
* It should be called before starting a new enrollment session.
|
|
358
|
+
*/
|
|
359
|
+
public async reset(): Promise<void> {
|
|
360
|
+
const returnPromise: Promise<void> = new Promise((resolve, reject) => {
|
|
361
|
+
this._worker.onmessage = (
|
|
362
|
+
event: MessageEvent<EagleProfilerWorkerResetResponse>
|
|
363
|
+
): void => {
|
|
364
|
+
switch (event.data.command) {
|
|
365
|
+
case 'ok':
|
|
366
|
+
resolve();
|
|
367
|
+
break;
|
|
368
|
+
case 'failed':
|
|
369
|
+
case 'error':
|
|
370
|
+
reject(
|
|
371
|
+
pvStatusToException(
|
|
372
|
+
event.data.status,
|
|
373
|
+
event.data.shortMessage,
|
|
374
|
+
event.data.messageStack
|
|
375
|
+
)
|
|
376
|
+
);
|
|
377
|
+
break;
|
|
378
|
+
default:
|
|
379
|
+
reject(
|
|
380
|
+
pvStatusToException(
|
|
381
|
+
PvStatus.RUNTIME_ERROR,
|
|
382
|
+
// @ts-ignore
|
|
383
|
+
`Unrecognized command: ${event.data.command}`
|
|
384
|
+
)
|
|
385
|
+
);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
});
|
|
389
|
+
this._worker.postMessage({
|
|
390
|
+
command: 'reset',
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
return returnPromise;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Releases resources acquired by Eagle Profiler
|
|
398
|
+
*/
|
|
399
|
+
public release(): Promise<void> {
|
|
400
|
+
const returnPromise: Promise<void> = new Promise((resolve, reject) => {
|
|
401
|
+
this._worker.onmessage = (
|
|
402
|
+
event: MessageEvent<EagleProfilerWorkerReleaseResponse>
|
|
403
|
+
): void => {
|
|
404
|
+
switch (event.data.command) {
|
|
405
|
+
case 'ok':
|
|
406
|
+
resolve();
|
|
407
|
+
break;
|
|
408
|
+
case 'failed':
|
|
409
|
+
case 'error':
|
|
410
|
+
reject(
|
|
411
|
+
pvStatusToException(
|
|
412
|
+
event.data.status,
|
|
413
|
+
event.data.shortMessage,
|
|
414
|
+
event.data.messageStack
|
|
415
|
+
)
|
|
416
|
+
);
|
|
417
|
+
break;
|
|
418
|
+
default:
|
|
419
|
+
reject(
|
|
420
|
+
pvStatusToException(
|
|
421
|
+
PvStatus.RUNTIME_ERROR,
|
|
422
|
+
// @ts-ignore
|
|
423
|
+
`Unrecognized command: ${event.data.command}`
|
|
424
|
+
)
|
|
425
|
+
);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
this._worker.postMessage({
|
|
431
|
+
command: 'release',
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
return returnPromise;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Terminates the active worker. Stops all requests being handled by worker.
|
|
439
|
+
*/
|
|
440
|
+
public terminate(): void {
|
|
441
|
+
this._worker.terminate();
|
|
442
|
+
}
|
|
443
|
+
}
|