@picovoice/eagle-web 1.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 -219
- package/dist/esm/index.js +7102 -1659
- package/dist/esm/index.min.js +1 -1
- package/dist/iife/index.js +7101 -1658
- package/dist/iife/index.min.js +1 -1
- package/dist/types/eagle.d.ts +237 -200
- 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 -95
- 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 -75
- 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 -126
- package/dist/types/types.d.ts.map +1 -1
- package/module.d.ts +16 -11
- package/package.json +73 -72
- package/rollup.config.js +75 -75
- package/src/eagle.ts +1546 -1191
- package/src/eagle_errors.ts +252 -252
- package/src/eagle_profiler_worker.ts +443 -315
- package/src/eagle_profiler_worker_handler.ts +246 -202
- package/src/eagle_worker.ts +307 -267
- package/src/eagle_worker_handler.ts +138 -167
- package/src/index.ts +94 -83
- package/src/types.ts +224 -202
- package/tsconfig.json +22 -22
package/.prettierignore
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.eslintrc.js
|
|
1
|
+
.eslintrc.js
|
package/.prettierrc
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
{
|
|
2
|
-
"semi": true,
|
|
3
|
-
"trailingComma": "es5",
|
|
4
|
-
"singleQuote": true,
|
|
5
|
-
"printWidth": 80,
|
|
6
|
-
"tabWidth": 2,
|
|
7
|
-
"arrowParens": "avoid"
|
|
8
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"semi": true,
|
|
3
|
+
"trailingComma": "es5",
|
|
4
|
+
"singleQuote": true,
|
|
5
|
+
"printWidth": 80,
|
|
6
|
+
"tabWidth": 2,
|
|
7
|
+
"arrowParens": "avoid"
|
|
8
|
+
}
|
package/README.md
CHANGED
|
@@ -1,219 +1,234 @@
|
|
|
1
|
-
# Eagle Binding for Web
|
|
2
|
-
|
|
3
|
-
## Eagle Speaker Recognition Engine
|
|
4
|
-
|
|
5
|
-
Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)
|
|
6
|
-
|
|
7
|
-
Eagle is an on-device speaker recognition engine. Eagle is:
|
|
8
|
-
|
|
9
|
-
- Private; All voice processing runs locally.
|
|
10
|
-
- Cross-Platform:
|
|
11
|
-
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64)
|
|
12
|
-
- Android and iOS
|
|
13
|
-
- Chrome, Safari, Firefox, and Edge
|
|
14
|
-
- Raspberry Pi (4,
|
|
15
|
-
|
|
16
|
-
## Compatibility
|
|
17
|
-
|
|
18
|
-
- Chrome / Edge
|
|
19
|
-
- Firefox
|
|
20
|
-
- Safari
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
or using `
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
eagleProfiler.
|
|
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
|
-
The
|
|
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
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
1
|
+
# Eagle Binding for Web
|
|
2
|
+
|
|
3
|
+
## Eagle Speaker Recognition Engine
|
|
4
|
+
|
|
5
|
+
Made in Vancouver, Canada by [Picovoice](https://picovoice.ai)
|
|
6
|
+
|
|
7
|
+
Eagle is an on-device speaker recognition engine. Eagle is:
|
|
8
|
+
|
|
9
|
+
- Private; All voice processing runs locally.
|
|
10
|
+
- Cross-Platform:
|
|
11
|
+
- Linux (x86_64), macOS (x86_64, arm64), Windows (x86_64, arm64)
|
|
12
|
+
- Android and iOS
|
|
13
|
+
- Chrome, Safari, Firefox, and Edge
|
|
14
|
+
- Raspberry Pi (3, 4, 5)
|
|
15
|
+
|
|
16
|
+
## Compatibility
|
|
17
|
+
|
|
18
|
+
- Chrome / Edge
|
|
19
|
+
- Firefox
|
|
20
|
+
- Safari
|
|
21
|
+
|
|
22
|
+
## Requirements
|
|
23
|
+
|
|
24
|
+
The Eagle Web Binding uses [SharedArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer).
|
|
25
|
+
|
|
26
|
+
Include the following headers in the response to enable the use of `SharedArrayBuffers`:
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
30
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Refer to our [Web demo](../../demo/web) for an example on creating a server with the corresponding response headers.
|
|
34
|
+
|
|
35
|
+
Browsers that don't support `SharedArrayBuffers` or applications that don't include the required headers will fall back to using standard `ArrayBuffers`. This will disable multithreaded processing.
|
|
36
|
+
|
|
37
|
+
### Restrictions
|
|
38
|
+
|
|
39
|
+
IndexedDB is required to use `Eagle` in a worker thread. Browsers without IndexedDB support
|
|
40
|
+
(i.e. Firefox Incognito Mode) should use `Eagle` in the main thread.
|
|
41
|
+
|
|
42
|
+
Multi-threading is only enabled for Eagle when using on a web worker.
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
Using `yarn`:
|
|
47
|
+
|
|
48
|
+
```console
|
|
49
|
+
yarn add @picovoice/eagle-web
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
or using `npm`:
|
|
53
|
+
|
|
54
|
+
```console
|
|
55
|
+
npm install --save @picovoice/eagle-web
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## AccessKey
|
|
59
|
+
|
|
60
|
+
Eagle requires a valid Picovoice `AccessKey` at initialization. `AccessKey` acts as your credentials when using Eagle
|
|
61
|
+
SDKs. You can get your `AccessKey` for free. Make sure to keep your `AccessKey` secret.
|
|
62
|
+
Signup or Login to [Picovoice Console](https://console.picovoice.ai/) to get your `AccessKey`.
|
|
63
|
+
|
|
64
|
+
## Usage
|
|
65
|
+
|
|
66
|
+
Eagle has two distinct steps: Enrollment and Recognition. In the enrollment step, Eagle analyzes a series of
|
|
67
|
+
utterances from a particular speaker to learn their unique voiceprint. This step produces a profile object,
|
|
68
|
+
which can be stored and utilized during inference. During the Recognition step, Eagle compares the incoming frames of
|
|
69
|
+
audio to the voiceprints of all enrolled speakers in real-time to determine the similarity between them.
|
|
70
|
+
|
|
71
|
+
### Speaker Enrollment
|
|
72
|
+
|
|
73
|
+
Create an instance of the `EagleProfiler`:
|
|
74
|
+
|
|
75
|
+
```typescript
|
|
76
|
+
const eagleModel = {
|
|
77
|
+
publicPath: ${MODEL_RELATIVE_PATH},
|
|
78
|
+
// or
|
|
79
|
+
base64: ${MODEL_BASE64_STRING},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Main thread
|
|
83
|
+
const eagleProfiler = await EagleProfiler.create(
|
|
84
|
+
${ACCESS_KEY},
|
|
85
|
+
eagleModel);
|
|
86
|
+
|
|
87
|
+
// or on worker thread
|
|
88
|
+
const eagleProfiler = await EagleProfilerWorker.create(
|
|
89
|
+
${ACCESS_KEY},
|
|
90
|
+
eagleModel);
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
`EagleProfiler` is responsible for processing and enrolling PCM audio data, with the valid audio sample rate determined
|
|
94
|
+
by `eagleProfiler.sampleRate`. The audio data must be 16-bit linearly-encoded and single-channel.
|
|
95
|
+
|
|
96
|
+
When passing samples to `eagleProfiler.enroll`, the number of samples must be equal to `eagleProfiler.frameLength`. The
|
|
97
|
+
percentage value returned from this process indicates the progress of enrollment.
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
function getAudioData(numSamples): Int16Array {
|
|
101
|
+
// get audio frame of size `numSamples`
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
let percentage = 0;
|
|
105
|
+
while (percentage < 100) {
|
|
106
|
+
const audioData = getAudioData(eagleProfiler.frameLength);
|
|
107
|
+
|
|
108
|
+
percentage = EagleProfilerEnrollResult = await eagleProfiler.enroll(audioData);
|
|
109
|
+
}
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
After the percentage reaches 100%, the enrollment process is considered complete. While it is possible to continue
|
|
113
|
+
providing additional audio data to the profiler to improve the accuracy of the voiceprint, it is not necessary to do so.
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
const speakerProfile: EagleProfile = eagleProfiler.export();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The `eagleProfiler.export()` function produces a binary array, which can be saved to a file.
|
|
120
|
+
|
|
121
|
+
To reset the profiler and enroll a new speaker, the `eagleProfiler.reset()` method can be used. This method clears all
|
|
122
|
+
previously stored data, making it possible to start a new enrollment session with a different speaker.
|
|
123
|
+
|
|
124
|
+
Finally, when done be sure to explicitly release the resources:
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
eagleProfiler.release();
|
|
128
|
+
|
|
129
|
+
// if on worker thread
|
|
130
|
+
eagleProfiler.terminate();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Speaker Recognition
|
|
134
|
+
|
|
135
|
+
Create an instance of the engine:
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
// Main thread
|
|
139
|
+
const eagle = await Eagle.create(
|
|
140
|
+
${ACCESS_KEY},
|
|
141
|
+
eagleModel);
|
|
142
|
+
|
|
143
|
+
// or, on a worker thread
|
|
144
|
+
const eagle = await EagleWorker.create(
|
|
145
|
+
${ACCESS_KEY},
|
|
146
|
+
eagleModel);
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
When initialized, `eagle.sampleRate` specifies the valid sample rate for Eagle. The expected length of a frame, or the
|
|
150
|
+
minimum number of audio samples in an input array, is defined by `eagle.minProcessSamples`.
|
|
151
|
+
|
|
152
|
+
Like the profiler, Eagle is designed to work with single-channel audio that is encoded using 16-bit linear PCM.
|
|
153
|
+
|
|
154
|
+
Process the audio data with one or more speaker profiles created by the `EagleProfiler`:
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
function getAudioData(numSamples): Int16Array {
|
|
158
|
+
// get audio frame of size `numSamples`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
while (true) {
|
|
162
|
+
const audioData = getAudioData(eagle.minProcessSamples);
|
|
163
|
+
const scores: number[] | null = await eagle.process(
|
|
164
|
+
audioData,
|
|
165
|
+
speakerProfile
|
|
166
|
+
);
|
|
167
|
+
if (scores) {
|
|
168
|
+
// do something with the scores
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
The return value `scores` represents the degree of similarity between the input audio frame and the enrolled speakers.
|
|
174
|
+
Each value is a floating-point number ranging from 0 to 1, with higher values indicating a greater degree of similarity.
|
|
175
|
+
A return value of null indicates that there was not enough voice in the sample to detect a speaker.
|
|
176
|
+
|
|
177
|
+
Finally, when done be sure to explicitly release the resources:
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
eagle.release();
|
|
181
|
+
|
|
182
|
+
// if on worker thread
|
|
183
|
+
eagle.terminate();
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Eagle Model
|
|
187
|
+
|
|
188
|
+
The default model is located in [lib/common](../../lib/common). Use it with the `EagleModel` type:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
const eagleModel = {
|
|
192
|
+
publicPath: ${MODEL_RELATIVE_PATH},
|
|
193
|
+
// or
|
|
194
|
+
base64: ${MODEL_BASE64_STRING},
|
|
195
|
+
|
|
196
|
+
// Optionals
|
|
197
|
+
customWritePath: "eagle_model",
|
|
198
|
+
forceWrite: false,
|
|
199
|
+
version: 1,
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Eagle saves and caches your model file in IndexedDB to be used by WebAssembly. Use a different `customWritePath` variable
|
|
204
|
+
to hold multiple models and set the `forceWrite` value to true to force re-save a model file.
|
|
205
|
+
|
|
206
|
+
Either `base64` or `publicPath` must be set to instantiate Eagle. If both are set, Eagle will use the `base64` model.
|
|
207
|
+
|
|
208
|
+
#### Public Directory
|
|
209
|
+
|
|
210
|
+
**NOTE**: Due to modern browser limitations of using a file URL, this method does __not__ work if used without hosting a server.
|
|
211
|
+
|
|
212
|
+
This method fetches the model file from the public directory and passes it to Eagle. Copy the model file into the public directory.
|
|
213
|
+
|
|
214
|
+
#### Base64
|
|
215
|
+
|
|
216
|
+
**NOTE**: This method works without hosting a server, but increases the size of the model file roughly by 33%.
|
|
217
|
+
|
|
218
|
+
This method uses a base64 string of the model file and passes it to Eagle. Use the built-in script `pvbase64` to
|
|
219
|
+
base64 your model file:
|
|
220
|
+
|
|
221
|
+
```console
|
|
222
|
+
npx pvbase64 -i ${EAGLE_MODEL_PATH} -o ${BASE64_MODEL_PATH}.js
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
The output will be a js file which you can import into any file of your project. For detailed information about `pvbase64`,
|
|
226
|
+
run:
|
|
227
|
+
|
|
228
|
+
```console
|
|
229
|
+
npx pvbase64 -h
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Demos
|
|
233
|
+
|
|
234
|
+
For example usage refer to our [Web demo application](https://github.com/Picovoice/eagle/tree/main/demo/web).
|