@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/.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,236 +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, 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 at
97
- least `eagleProfiler.minEnrollSamples` to ensure sufficient data for enrollment. The percentage value
98
- returned from this process indicates the progress of enrollment, while the feedback value can be utilized to determine the status of the enrollment process.
99
-
100
- ```typescript
101
- function getAudioData(numSamples): Int16Array {
102
- // get audio frame of size `numSamples`
103
- }
104
-
105
- let percentage = 0;
106
- while (percentage < 100) {
107
- const audioData = getAudioData(eagleProfiler.minEnrollSamples);
108
-
109
- const result: EagleProfilerEnrollResult = await eagleProfiler.enroll(audioData);
110
- if (result.feedback === EagleProfilerEnrollFeedback.AUDIO_OK) {
111
- // audio is good!
112
- } else {
113
- // feedback code will tell you why audio was not used in enrollment
114
- }
115
- percentage = result.percentage;
116
- }
117
- ```
118
-
119
- After the percentage reaches 100%, the enrollment process is considered complete. While it is possible to continue
120
- providing additional audio data to the profiler to improve the accuracy of the voiceprint, it is not necessary to do so.
121
- Moreover, if the audio data submitted is unsuitable for enrollment, the feedback value will indicate the reason, and the
122
- enrollment progress will remain unchanged.
123
-
124
- ```typescript
125
- const speakerProfile: EagleProfile = eagleProfiler.export();
126
- ```
127
-
128
- The `eagleProfiler.export()` function produces a binary array, which can be saved to a file.
129
-
130
- To reset the profiler and enroll a new speaker, the `eagleProfiler.reset()` method can be used. This method clears all
131
- previously stored data, making it possible to start a new enrollment session with a different speaker.
132
-
133
- Finally, when done be sure to explicitly release the resources:
134
-
135
- ```typescript
136
- eagleProfiler.release();
137
-
138
- // if on worker thread
139
- eagleProfiler.terminate();
140
- ```
141
-
142
- ### Speaker Recognition
143
-
144
- Create an instance of the engine with one or more speaker profiles created by the `EagleProfiler`:
145
-
146
- ```typescript
147
- // Main thread
148
- const eagle = await Eagle.create(
149
- ${ACCESS_KEY},
150
- eagleModel,
151
- speakerProfile);
152
-
153
- // or, on a worker thread
154
- const eagle = await EagleWorker.create(
155
- ${ACCESS_KEY},
156
- eagleModel,
157
- speakerProfile);
158
- ```
159
-
160
- When initialized, `eagle.sampleRate` specifies the valid sample rate for Eagle. The expected length of a frame, or the
161
- number of audio samples in an input array, is defined by `eagle.frameLength`.
162
-
163
- Like the profiler, Eagle is designed to work with single-channel audio that is encoded using 16-bit linear PCM.
164
-
165
- ```typescript
166
- function getAudioData(numSamples): Int16Array {
167
- // get audio frame of size `numSamples`
168
- }
169
-
170
- while (true) {
171
- const audioData = getAudioData(eagle.frameLength);
172
- const scores: number[] = await eagle.process(audioData);
173
- }
174
- ```
175
-
176
- The return value `scores` represents the degree of similarity between the input audio frame and the enrolled speakers.
177
- Each value is a floating-point number ranging from 0 to 1, with higher values indicating a greater degree of similarity.
178
-
179
- Finally, when done be sure to explicitly release the resources:
180
-
181
- ```typescript
182
- eagle.release();
183
-
184
- // if on worker thread
185
- eagle.terminate();
186
- ```
187
-
188
- ### Eagle Model
189
-
190
- The default model is located in [lib/common](../../lib/common). Use it with the `EagleModel` type:
191
-
192
- ```typescript
193
- const eagleModel = {
194
- publicPath: ${MODEL_RELATIVE_PATH},
195
- // or
196
- base64: ${MODEL_BASE64_STRING},
197
-
198
- // Optionals
199
- customWritePath: "eagle_model",
200
- forceWrite: false,
201
- version: 1,
202
- }
203
- ```
204
-
205
- Eagle saves and caches your model file in IndexedDB to be used by WebAssembly. Use a different `customWritePath` variable
206
- to hold multiple models and set the `forceWrite` value to true to force re-save a model file.
207
-
208
- Either `base64` or `publicPath` must be set to instantiate Eagle. If both are set, Eagle will use the `base64` model.
209
-
210
- #### Public Directory
211
-
212
- **NOTE**: Due to modern browser limitations of using a file URL, this method does __not__ work if used without hosting a server.
213
-
214
- This method fetches the model file from the public directory and passes it to Eagle. Copy the model file into the public directory.
215
-
216
- #### Base64
217
-
218
- **NOTE**: This method works without hosting a server, but increases the size of the model file roughly by 33%.
219
-
220
- This method uses a base64 string of the model file and passes it to Eagle. Use the built-in script `pvbase64` to
221
- base64 your model file:
222
-
223
- ```console
224
- npx pvbase64 -i ${EAGLE_MODEL_PATH} -o ${BASE64_MODEL_PATH}.js
225
- ```
226
-
227
- The output will be a js file which you can import into any file of your project. For detailed information about `pvbase64`,
228
- run:
229
-
230
- ```console
231
- npx pvbase64 -h
232
- ```
233
-
234
- ## Demos
235
-
236
- 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).