@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/.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, 3) and NVIDIA Jetson Nano
15
-
16
- ## Compatibility
17
-
18
- - Chrome / Edge
19
- - Firefox
20
- - Safari
21
-
22
- ### Restrictions
23
-
24
- IndexedDB is required to use `Eagle` in a worker thread. Browsers without IndexedDB support
25
- (i.e. Firefox Incognito Mode) should use `Eagle` in the main thread.
26
-
27
- ## Installation
28
-
29
- Using `yarn`:
30
-
31
- ```console
32
- yarn add @picovoice/eagle-web
33
- ```
34
-
35
- or using `npm`:
36
-
37
- ```console
38
- npm install --save @picovoice/eagle-web
39
- ```
40
-
41
- ## AccessKey
42
-
43
- Eagle requires a valid Picovoice `AccessKey` at initialization. `AccessKey` acts as your credentials when using Eagle
44
- SDKs. You can get your `AccessKey` for free. Make sure to keep your `AccessKey` secret.
45
- Signup or Login to [Picovoice Console](https://console.picovoice.ai/) to get your `AccessKey`.
46
-
47
- ## Usage
48
-
49
- Eagle has two distinct steps: Enrollment and Recognition. In the enrollment step, Eagle analyzes a series of
50
- utterances from a particular speaker to learn their unique voiceprint. This step produces a profile object,
51
- which can be stored and utilized during inference. During the Recognition step, Eagle compares the incoming frames of
52
- audio to the voiceprints of all enrolled speakers in real-time to determine the similarity between them.
53
-
54
- ### Speaker Enrollment
55
-
56
- Create an instance of the `EagleProfiler`:
57
-
58
- ```typescript
59
- const eagleModel = {
60
- publicPath: ${MODEL_RELATIVE_PATH},
61
- // or
62
- base64: ${MODEL_BASE64_STRING},
63
- }
64
-
65
- // Main thread
66
- const eagleProfiler = await EagleProfiler.create(
67
- ${ACCESS_KEY},
68
- eagleModel);
69
-
70
- // or on worker thread
71
- const eagleProfiler = await EagleProfilerWorker.create(
72
- ${ACCESS_KEY},
73
- eagleModel);
74
- ```
75
-
76
- `EagleProfiler` is responsible for processing and enrolling PCM audio data, with the valid audio sample rate determined
77
- by `eagleProfiler.sampleRate`. The audio data must be 16-bit linearly-encoded and single-channel.
78
-
79
- When passing samples to `eagleProfiler.enroll`, the number of samples must be at
80
- least `eagleProfiler.minEnrollSamples` to ensure sufficient data for enrollment. The percentage value
81
- returned from this process indicates the progress of enrollment, while the feedback value can be utilized to determine the status of the enrollment process.
82
-
83
- ```typescript
84
- function getAudioData(numSamples): Int16Array {
85
- // get audio frame of size `numSamples`
86
- }
87
-
88
- let percentage = 0;
89
- while (percentage < 100) {
90
- const audioData = getAudioData(eagleProfiler.minEnrollSamples);
91
-
92
- const result: EagleProfilerEnrollResult = await eagleProfiler.enroll(audioData);
93
- if (result.feedback === EagleProfilerEnrollFeedback.AUDIO_OK) {
94
- // audio is good!
95
- } else {
96
- // feedback code will tell you why audio was not used in enrollment
97
- }
98
- percentage = result.percentage;
99
- }
100
- ```
101
-
102
- After the percentage reaches 100%, the enrollment process is considered complete. While it is possible to continue
103
- providing additional audio data to the profiler to improve the accuracy of the voiceprint, it is not necessary to do so.
104
- Moreover, if the audio data submitted is unsuitable for enrollment, the feedback value will indicate the reason, and the
105
- enrollment progress will remain unchanged.
106
-
107
- ```typescript
108
- const speakerProfile: EagleProfile = eagleProfiler.export();
109
- ```
110
-
111
- The `eagleProfiler.export()` function produces a binary array, which can be saved to a file.
112
-
113
- To reset the profiler and enroll a new speaker, the `eagleProfiler.reset()` method can be used. This method clears all
114
- previously stored data, making it possible to start a new enrollment session with a different speaker.
115
-
116
- Finally, when done be sure to explicitly release the resources:
117
-
118
- ```typescript
119
- eagleProfiler.release();
120
-
121
- // if on worker thread
122
- eagleProfiler.terminate();
123
- ```
124
-
125
- ### Speaker Recognition
126
-
127
- Create an instance of the engine with one or more speaker profiles created by the `EagleProfiler`:
128
-
129
- ```typescript
130
- // Main thread
131
- const eagle = await Eagle.create(
132
- ${ACCESS_KEY},
133
- eagleModel,
134
- speakerProfile);
135
-
136
- // or, on a worker thread
137
- const eagle = await EagleWorker.create(
138
- ${ACCESS_KEY},
139
- eagleModel,
140
- speakerProfile);
141
- ```
142
-
143
- When initialized, `eagle.sampleRate` specifies the valid sample rate for Eagle. The expected length of a frame, or the
144
- number of audio samples in an input array, is defined by `eagle.frameLength`.
145
-
146
- Like the profiler, Eagle is designed to work with single-channel audio that is encoded using 16-bit linear PCM.
147
-
148
- ```typescript
149
- function getAudioData(numSamples): Int16Array {
150
- // get audio frame of size `numSamples`
151
- }
152
-
153
- while (true) {
154
- const audioData = getAudioData(eagle.frameLength);
155
- const scores: number[] = await eagle.process(audioData);
156
- }
157
- ```
158
-
159
- The return value `scores` represents the degree of similarity between the input audio frame and the enrolled speakers.
160
- Each value is a floating-point number ranging from 0 to 1, with higher values indicating a greater degree of similarity.
161
-
162
- Finally, when done be sure to explicitly release the resources:
163
-
164
- ```typescript
165
- eagle.release();
166
-
167
- // if on worker thread
168
- eagle.terminate();
169
- ```
170
-
171
- ### Eagle Model
172
-
173
- The default model is located in [lib/common](../../lib/common). Use it with the `EagleModel` type:
174
-
175
- ```typescript
176
- const eagleModel = {
177
- publicPath: ${MODEL_RELATIVE_PATH},
178
- // or
179
- base64: ${MODEL_BASE64_STRING},
180
-
181
- // Optionals
182
- customWritePath: "eagle_model",
183
- forceWrite: false,
184
- version: 1,
185
- }
186
- ```
187
-
188
- Eagle saves and caches your model file in IndexedDB to be used by WebAssembly. Use a different `customWritePath` variable
189
- to hold multiple models and set the `forceWrite` value to true to force re-save a model file.
190
-
191
- Either `base64` or `publicPath` must be set to instantiate Eagle. If both are set, Eagle will use the `base64` model.
192
-
193
- #### Public Directory
194
-
195
- **NOTE**: Due to modern browser limitations of using a file URL, this method does __not__ work if used without hosting a server.
196
-
197
- This method fetches the model file from the public directory and passes it to Eagle. Copy the model file into the public directory.
198
-
199
- #### Base64
200
-
201
- **NOTE**: This method works without hosting a server, but increases the size of the model file roughly by 33%.
202
-
203
- This method uses a base64 string of the model file and passes it to Eagle. Use the built-in script `pvbase64` to
204
- base64 your model file:
205
-
206
- ```console
207
- npx pvbase64 -i ${EAGLE_MODEL_PATH} -o ${BASE64_MODEL_PATH}.js
208
- ```
209
-
210
- The output will be a js file which you can import into any file of your project. For detailed information about `pvbase64`,
211
- run:
212
-
213
- ```console
214
- npx pvbase64 -h
215
- ```
216
-
217
- ## Demos
218
-
219
- For example usage refer to our [Web demo application](https://github.com/Picovoice/eagle/tree/main/demo/web).
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).