@seams/voice-capture 0.0.0-stage → 0.67.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/LICENSE.md +201 -0
- package/README.md +174 -2
- package/dist/assets/NOTICE.txt +3 -0
- package/dist/assets/SILERO_LICENSE.txt +21 -0
- package/dist/assets/ort-wasm-simd-threaded.mjs +59 -0
- package/dist/assets/ort-wasm-simd-threaded.wasm +0 -0
- package/dist/assets/silero-vad.onnx +0 -0
- package/dist/assets/voice-activity-worklet.js +21 -0
- package/dist/browser/card.js +800 -0
- package/dist/browser/chunks/microphone-CU5gQG6w.js +1 -0
- package/dist/browser/chunks/ort.wasm.bundle.min-CWqlff_l.js +3 -0
- package/dist/browser/index.js +1 -0
- package/dist/esm/card/index.js +6 -0
- package/dist/esm/card/phraseCard.js +459 -0
- package/dist/esm/card/prompt.js +1074 -0
- package/dist/esm/card/ribbon.js +489 -0
- package/dist/esm/card/surface.js +224 -0
- package/dist/esm/card/types.js +0 -0
- package/dist/esm/card/visual.js +2 -0
- package/dist/esm/chunks/visual-Di3ojTED.js +1520 -0
- package/dist/esm/config.js +42 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/inference.js +193 -0
- package/dist/esm/microphone.js +428 -0
- package/dist/esm/microphoneInput.js +117 -0
- package/dist/esm/speechPause.js +33 -0
- package/dist/esm/voiceActivity.js +69 -0
- package/dist/esm/wav.js +36 -0
- package/dist/example/example.js +71 -0
- package/dist/example/index.html +29 -0
- package/dist/hosting.d.mts +4 -0
- package/dist/hosting.mjs +26 -0
- package/dist/types/card/index.d.ts +6 -0
- package/dist/types/card/phraseCard.d.ts +72 -0
- package/dist/types/card/prompt.d.ts +122 -0
- package/dist/types/card/ribbon.d.ts +62 -0
- package/dist/types/card/surface.d.ts +28 -0
- package/dist/types/card/types.d.ts +65 -0
- package/dist/types/card/visual.d.ts +25 -0
- package/dist/types/config.d.ts +47 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/inference.d.ts +47 -0
- package/dist/types/microphone.d.ts +81 -0
- package/dist/types/microphoneInput.d.ts +19 -0
- package/dist/types/speechPause.d.ts +8 -0
- package/dist/types/voiceActivity.d.ts +15 -0
- package/dist/types/wav.d.ts +9 -0
- package/package.json +57 -4
package/LICENSE.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
CHANGED
|
@@ -1,3 +1,175 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @seams/voice-capture
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Records one spoken sentence in the browser. It opens the microphone, finds the speech, stops at
|
|
4
|
+
the pause, checks the quality, and returns 16 kHz mono samples.
|
|
5
|
+
|
|
6
|
+
The core has no user interface, the phrase card is a second entry point, and neither depends on
|
|
7
|
+
a wallet. `@seams/voiceid` and Speak-to-Sign use
|
|
8
|
+
it, and any web page can use it alone.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pnpm add @seams/voice-capture
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Copy the asset files into a folder that your site serves:
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import { copyVoiceCaptureAssets } from '@seams/voice-capture/hosting';
|
|
20
|
+
|
|
21
|
+
await copyVoiceCaptureAssets('public/voice-capture');
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| File | Bytes | Needed for |
|
|
25
|
+
| --- | --- | --- |
|
|
26
|
+
| `voice-activity-worklet.js` | 587 | Every recording |
|
|
27
|
+
| `silero-vad.onnx` | 2,327,524 | The detector `model` |
|
|
28
|
+
| `ort-wasm-simd-threaded.wasm`, `ort-wasm-simd-threaded.mjs` | 14,264,278 | The detector `model` |
|
|
29
|
+
|
|
30
|
+
The browser keeps the model files in its cache after the first download. The package checks
|
|
31
|
+
the size and the SHA-256 of each model file.
|
|
32
|
+
|
|
33
|
+
## Record
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
import {
|
|
37
|
+
configureVoiceCapture,
|
|
38
|
+
expectedSpeechMs,
|
|
39
|
+
pcm16Wav,
|
|
40
|
+
recordVoice,
|
|
41
|
+
} from '@seams/voice-capture';
|
|
42
|
+
|
|
43
|
+
configureVoiceCapture({ assetBase: '/voice-capture/' });
|
|
44
|
+
|
|
45
|
+
const sentence = 'Send two NEAR to alice.testnet';
|
|
46
|
+
const stop = new AbortController();
|
|
47
|
+
const result = await recordVoice(
|
|
48
|
+
stop.signal,
|
|
49
|
+
(event) => {
|
|
50
|
+
// 'opening', 'listening', 'activity' (with the level), 'processing', 'measured'
|
|
51
|
+
},
|
|
52
|
+
{ expectedSpeechMs: expectedSpeechMs(sentence) },
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
if (result.kind === 'captured') {
|
|
56
|
+
const wav = pcm16Wav(result.samples); // 16 kHz mono PCM16, at most 8 s
|
|
57
|
+
} else {
|
|
58
|
+
// 'insufficient_audio': less than 0.6 s of speech, or too much noise. See result.quality.
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
- Call `recordVoice` from a click or a key press, on a page that is in front. The browser asks
|
|
63
|
+
the person for the microphone.
|
|
64
|
+
- The recording ends after a pause of 1.5 s, or 0.8 s once the voiced time covers the expected
|
|
65
|
+
sentence, or after 8 s.
|
|
66
|
+
- `stop.abort()` cancels the recording and stops the microphone. The promise then rejects.
|
|
67
|
+
- `pcm16Wav` gives the audio format of the Speak-to-Sign verifier.
|
|
68
|
+
|
|
69
|
+
## The phrase card
|
|
70
|
+
|
|
71
|
+
`@seams/voice-capture/card` has the card that the Seams Wallet shows: the sentence, a Record
|
|
72
|
+
button, the voice line, and then your check and your result on the same card. It needs no
|
|
73
|
+
React: the package brings its own small renderer.
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
import { openPhraseCard } from '@seams/voice-capture/card';
|
|
77
|
+
|
|
78
|
+
const surface = openPhraseCard({
|
|
79
|
+
sentence: 'Send two NEAR to alice.testnet',
|
|
80
|
+
signal: new AbortController().signal,
|
|
81
|
+
frame: { parent: document.querySelector('#card') },
|
|
82
|
+
});
|
|
83
|
+
try {
|
|
84
|
+
const recording = await surface.record(); // the person selects Record and speaks
|
|
85
|
+
if (recording.kind === 'recorded') {
|
|
86
|
+
void surface.show({
|
|
87
|
+
kind: 'check',
|
|
88
|
+
label: 'Checking',
|
|
89
|
+
caption: 'Checking your voice',
|
|
90
|
+
details: ['One moment.'],
|
|
91
|
+
segments: ['done', 'run'],
|
|
92
|
+
});
|
|
93
|
+
const answer = await yourCheck(pcm16Wav(recording.samples));
|
|
94
|
+
await surface.show({
|
|
95
|
+
kind: 'result',
|
|
96
|
+
label: '',
|
|
97
|
+
headline: answer.ok ? 'Approved' : 'Not approved',
|
|
98
|
+
caption: 'Send two NEAR to alice.testnet',
|
|
99
|
+
detail: answer.text,
|
|
100
|
+
action: { label: 'Done' },
|
|
101
|
+
line: answer.ok ? 'seal' : ['done', 'fail'],
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
} finally {
|
|
105
|
+
surface.close();
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
- `record()` resolves with `recorded` (the samples) or `cancelled`. A too quiet recording
|
|
110
|
+
stays on the card with "Try again".
|
|
111
|
+
- `show()` resolves with `action` when the person selects the button of a result, `closed`
|
|
112
|
+
when the person closes the card, or `replaced` when a new view or recording takes its place.
|
|
113
|
+
- The card uses the CSS variables `--seams-colors-*`, `--seams-shape-*` and
|
|
114
|
+
`--seams-font-family` when the page sets them, and has its own values when it does not.
|
|
115
|
+
`data-theme="light"` or `"dark"` on the page selects the glow colours.
|
|
116
|
+
- `frame` adds what a host needs: the parent element, more class names, a Back control, and a
|
|
117
|
+
callback when the card is in the document.
|
|
118
|
+
- `VoicePrompt`, `PhraseCard`, `VoiceRibbon` and `VoiceVisual` are exported for a host that
|
|
119
|
+
makes its own surfaces.
|
|
120
|
+
|
|
121
|
+
## The example
|
|
122
|
+
|
|
123
|
+
```sh
|
|
124
|
+
pnpm build
|
|
125
|
+
pnpm example
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Open `http://localhost:4599/example/`. The page records one sentence on the card, or three
|
|
129
|
+
enrollment phrases one after another, with this package alone.
|
|
130
|
+
|
|
131
|
+
## Two detectors
|
|
132
|
+
|
|
133
|
+
| `detector` | Download | What it finds |
|
|
134
|
+
| --- | --- | --- |
|
|
135
|
+
| `model` (default) | About 16.6 MB, one time | Speech, with the Silero voice activity model |
|
|
136
|
+
| `level` | None | Any sound above the level. It cannot tell speech from other loud sound. |
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
await recordVoice(stop.signal, observer, { detector: 'level' });
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Settings
|
|
143
|
+
|
|
144
|
+
`configureVoiceCapture` takes:
|
|
145
|
+
|
|
146
|
+
| Option | Default | Use |
|
|
147
|
+
| --- | --- | --- |
|
|
148
|
+
| `assetBase` | none (required) | The folder URL of the asset files |
|
|
149
|
+
| `microphonePreference` | kept until the page reloads | `{ read, save }` to keep the chosen microphone |
|
|
150
|
+
| `label` | `Voice capture` | The product name in messages |
|
|
151
|
+
| `place` | `this page` | The place name in messages ("Keep this page open and focused ...") |
|
|
152
|
+
| `site` | `this site` | The site name in messages ("... is unavailable from this site.") |
|
|
153
|
+
| `recoveryHint` | `Reload the page and try again.` | What the person can do when a file cannot load |
|
|
154
|
+
| `cacheName` | `seams-voice-capture-models-v1` | The browser cache of the model files |
|
|
155
|
+
| `styleNonce` | none | The nonce of the page's style policy, for an older browser that needs a style element |
|
|
156
|
+
|
|
157
|
+
## Privacy
|
|
158
|
+
|
|
159
|
+
The audio stays in the page. The package sends nothing to a server. It overwrites its audio
|
|
160
|
+
buffers with zeros after use; the caller owns the returned samples and must do the same.
|
|
161
|
+
|
|
162
|
+
## Tests
|
|
163
|
+
|
|
164
|
+
```sh
|
|
165
|
+
pnpm build
|
|
166
|
+
pnpm test
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The `chromium` tests record from a fake microphone that plays
|
|
170
|
+
`tests/fixtures/speech-then-silence.wav` (synthetic speech from macOS `say`).
|
|
171
|
+
|
|
172
|
+
## Licences
|
|
173
|
+
|
|
174
|
+
The package is Apache-2.0. The Silero voice activity model is MIT (`SILERO_LICENSE.txt` in the
|
|
175
|
+
asset folder). `onnxruntime-web` is MIT.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020-present Silero Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
async function ortWasmThreaded(moduleArg={}){var moduleRtn;var h=moduleArg,aa=!!globalThis.window,k=!!globalThis.WorkerGlobalScope,m=globalThis.process?.versions?.node&&"renderer"!=globalThis.process?.type,n=k&&self.name?.startsWith("em-pthread");if(m){const {createRequire:a}=await import("module");var require=a(import.meta.url),ba=require("worker_threads");global.Worker=ba.Worker;n=(k=!ba.jc)&&"em-pthread"==ba.workerData}h.mountExternalData=(a,b)=>{a.startsWith("./")&&(a=a.substring(2));(h.Tb||(h.Tb=new Map)).set(a,b)};
|
|
2
|
+
h.unmountExternalData=()=>{delete h.Tb;delete h.mc;delete h.lc;delete h.nc};var SharedArrayBuffer=globalThis.SharedArrayBuffer??(new WebAssembly.Memory({initial:0,maximum:0,shared:!0})).buffer.constructor,ca="./this.program",da=(a,b)=>{throw b;},ea=import.meta.url,fa="",ha,ia;
|
|
3
|
+
if(m){var fs=require("fs");ea.startsWith("file:")&&(fa=require("path").dirname(require("url").fileURLToPath(ea))+"/");ia=a=>{a=ja(a)?new URL(a):a;return fs.readFileSync(a)};ha=async a=>{a=ja(a)?new URL(a):a;return fs.readFileSync(a,void 0)};1<process.argv.length&&(ca=process.argv[1].replace(/\\/g,"/"));process.argv.slice(2);da=(a,b)=>{process.exitCode=a;throw b;}}else if(aa||k){try{fa=(new URL(".",ea)).href}catch{}m||(k&&(ia=a=>{var b=new XMLHttpRequest;b.open("GET",a,!1);b.responseType="arraybuffer";
|
|
4
|
+
b.send(null);return new Uint8Array(b.response)}),ha=async a=>{if(ja(a))return new Promise((d,c)=>{var e=new XMLHttpRequest;e.open("GET",a,!0);e.responseType="arraybuffer";e.onload=()=>{200==e.status||0==e.status&&e.response?d(e.response):c(e.status)};e.onerror=c;e.send(null)});var b=await fetch(a,{credentials:"same-origin"});if(b.ok)return b.arrayBuffer();throw Error(b.status+" : "+b.url);})}var ka=console.log.bind(console),la=console.error.bind(console);
|
|
5
|
+
if(m){var ma=require("util"),na=a=>"object"==typeof a?ma.inspect(a):a;ka=(...a)=>fs.writeSync(1,a.map(na).join(" ")+"\n");la=(...a)=>fs.writeSync(2,a.map(na).join(" ")+"\n")}var oa=ka,p=la,q,r,pa=!1,t,ja=a=>a.startsWith("file://");function v(){x.buffer!=z.buffer&&qa()}var ra,sa;
|
|
6
|
+
if(m&&n){var ta=ba.parentPort;ta.on("message",a=>global.onmessage?.({data:a}));Object.assign(globalThis,{self:global,postMessage:a=>ta.postMessage(a)});process.on("uncaughtException",a=>{postMessage({Rb:"uncaughtException",error:a});process.exit(1)})}var ua;
|
|
7
|
+
if(n){var va=!1;self.onunhandledrejection=b=>{throw b.reason||b;};function a(b){try{var d=b.data,c=d.Rb;if("load"===c){let e=[];self.onmessage=f=>e.push(f);ua=()=>{postMessage({Rb:"loaded"});for(let f of e)a(f);self.onmessage=a};for(const f of d.ac)if(!h[f]||h[f].proxy)h[f]=(...g)=>{postMessage({Rb:"callHandler",$b:f,args:g})},"print"==f&&(oa=h[f]),"printErr"==f&&(p=h[f]);x=d.fc;qa();r=d.hc;wa();xa()}else if("run"===c){ya(d.Qb);za(d.Qb,0,0,1,0,0);Aa();Ba(d.Qb);va||=!0;try{Ca(d.dc,d.Vb)}catch(e){if("unwind"!=
|
|
8
|
+
e)throw e;}}else"setimmediate"!==d.target&&("checkMailbox"===c?va&&Da():c&&(p(`worker: received unknown command ${c}`),p(d)))}catch(e){throw Ea(),e;}}self.onmessage=a}var z,A,Fa,C,D,Ga,G,H,Ha=!1;function qa(){var a=x.buffer;h.HEAP8=z=new Int8Array(a);Fa=new Int16Array(a);h.HEAPU8=A=new Uint8Array(a);new Uint16Array(a);h.HEAP32=C=new Int32Array(a);h.HEAPU32=D=new Uint32Array(a);Ga=new Float32Array(a);G=new Float64Array(a);H=new BigInt64Array(a);new BigUint64Array(a)}
|
|
9
|
+
function Ia(){Ha=!0;n?ua():I.Va()}function J(a){a="Aborted("+a+")";p(a);pa=!0;a=new WebAssembly.RuntimeError(a+". Build with -sASSERTIONS for more info.");sa?.(a);throw a;}var Ja;async function Ka(a){if(!q)try{var b=await ha(a);return new Uint8Array(b)}catch{}if(a==Ja&&q)a=new Uint8Array(q);else if(ia)a=ia(a);else throw"both async and sync fetching of the wasm failed";return a}
|
|
10
|
+
async function La(a,b){try{var d=await Ka(a);return await WebAssembly.instantiate(d,b)}catch(c){p(`failed to asynchronously prepare wasm: ${c}`),J(c)}}async function Na(a){var b=Ja;if(!q&&!ja(b)&&!m)try{var d=fetch(b,{credentials:"same-origin"});return await WebAssembly.instantiateStreaming(d,a)}catch(c){p(`wasm streaming compile failed: ${c}`),p("falling back to ArrayBuffer instantiation")}return La(b,a)}
|
|
11
|
+
function Oa(){Pa={T:Qa,f:Ra,w:Sa,e:Ta,k:Ua,h:Va,L:Wa,b:Xa,G:Ya,ua:Za,j:$a,M:ab,La:bb,qa:cb,sa:db,Ma:eb,Ja:fb,Ca:gb,Ia:hb,Z:ib,ra:jb,oa:kb,Ka:lb,pa:mb,Ra:nb,Fa:ob,ma:pb,va:qb,ja:rb,U:sb,Ea:Ba,Oa:tb,za:ub,Aa:vb,Ba:wb,xa:xb,ya:yb,ka:zb,Ta:Ab,Qa:Bb,W:Cb,V:Db,Pa:Eb,F:Fb,Na:Gb,na:Hb,u:Ib,H:Jb,S:Kb,la:Lb,ba:Mb,Ua:Nb,Ga:Ob,Ha:Pb,ta:Qb,I:Rb,wa:Sb,Y:Tb,Da:Ub,X:Vb,$:Wb,N:Xb,aa:Yb,O:Zb,v:$b,d:ac,m:bc,n:cc,r:dc,ca:ec,E:fc,o:gc,P:hc,C:ic,J:jc,da:kc,ea:lc,z:mc,fa:nc,Q:oc,ga:pc,y:qc,D:rc,c:sc,q:tc,i:uc,_:vc,l:wc,
|
|
12
|
+
p:xc,s:yc,t:zc,x:Ac,R:Bc,A:Cc,K:Dc,B:Ec,ha:Fc,ia:Gc,g:Hc,a:x,Sa:Ic};return{a:Pa}}
|
|
13
|
+
async function wa(){function a(c,e){I=c.exports;I=Jc();Kc.push(I.xb);c=I;h._OrtInit=c.Wa;h._OrtGetLastError=c.Xa;h._OrtCreateSessionOptions=c.Ya;h._OrtAppendExecutionProvider=c.Za;h._OrtAddFreeDimensionOverride=c._a;h._OrtAddSessionConfigEntry=c.$a;h._OrtReleaseSessionOptions=c.ab;h._OrtCreateSession=c.bb;h._OrtReleaseSession=c.cb;h._OrtGetInputOutputCount=c.db;h._OrtGetInputOutputMetadata=c.eb;h._OrtFree=c.fb;h._OrtCreateTensor=c.gb;h._OrtGetTensorData=c.hb;h._OrtReleaseTensor=c.ib;h._OrtCreateRunOptions=
|
|
14
|
+
c.jb;h._OrtAddRunConfigEntry=c.kb;h._OrtReleaseRunOptions=c.lb;h._OrtCreateBinding=c.mb;h._OrtBindInput=c.nb;h._OrtBindOutput=c.ob;h._OrtClearBoundOutputs=c.pb;h._OrtReleaseBinding=c.qb;h._OrtRunWithBinding=c.rb;h._OrtRun=c.sb;h._OrtEndProfiling=c.tb;Lc=c.ub;Mc=h._free=c.vb;Nc=h._malloc=c.wb;za=c.zb;Ea=c.Ab;Oc=c.Bb;Pc=c.Cb;Qc=c.Db;Rc=c.Eb;Sc=c.Fb;K=c.Gb;L=c.Hb;Tc=c.Ib;M=c.Jb;Uc=c.Kb;N=c.Lb;Vc=c.Mb;Wc=c.Nb;Xc=c.Ob;Yc=c.Pb;Zc=c.yb;r=e;return I}var b=Oa();if(h.instantiateWasm)return new Promise(c=>{h.instantiateWasm(b,
|
|
15
|
+
(e,f)=>{c(a(e,f))})});if(n){var d=new WebAssembly.Instance(r,Oa());return a(d,r)}Ja??=h.locateFile?h.locateFile?h.locateFile("ort-wasm-simd-threaded.wasm",fa):fa+"ort-wasm-simd-threaded.wasm":(new URL("ort-wasm-simd-threaded.wasm",import.meta.url)).href;return function(c){return a(c.instance,c.module)}(await Na(b))}class $c{name="ExitStatus";constructor(a){this.message=`Program terminated with exit(${a})`;this.status=a}}
|
|
16
|
+
var ad=a=>{a.terminate();a.onmessage=()=>{}},bd=[],O=0,P=null,ed=a=>{0==Q.length&&(cd(),dd(Q[0]));var b=Q.pop();if(!b)return 6;R.push(b);S[a.Qb]=b;b.Qb=a.Qb;var d={Rb:"run",dc:a.cc,Vb:a.Vb,Qb:a.Qb};m&&b.unref();b.postMessage(d,a.Zb);return 0},T=0,U=(a,b,...d)=>{var c=16*d.length,e=N(),f=Uc(c),g=f>>>3,l;for(l of d)"bigint"==typeof l?((v(),H)[g++>>>0]=1n,(v(),H)[g++>>>0]=l):((v(),H)[g++>>>0]=0n,(v(),G)[g++>>>0]=l);a=Oc(a,0,c,f,b);M(e);return a};
|
|
17
|
+
function Ic(a){if(n)return U(0,1,a);t=a;if(!(0<T)){for(var b of R)ad(b);for(b of Q)ad(b);Q=[];R=[];S={};pa=!0}da(a,new $c(a))}function fd(a){if(n)return U(1,0,a);Qb(a)}var Qb=a=>{t=a;if(n)throw fd(a),"unwind";Ic(a)},Q=[],R=[],Kc=[],S={};function gd(){for(var a=h.numThreads-1;a--;)cd();bd.push(async()=>{var b=hd();O++;await b;O--;0==O&&P&&(b=P,P=null,b())})}var jd=a=>{var b=a.Qb;delete S[b];Q.push(a);R.splice(R.indexOf(a),1);a.Qb=0;Pc(b)};function Aa(){Kc.forEach(a=>a())}
|
|
18
|
+
var dd=a=>new Promise(b=>{a.onmessage=f=>{var g=f.data;f=g.Rb;if(g.Ub&&g.Ub!=Lc()){var l=S[g.Ub];l?l.postMessage(g,g.Zb):p(`Internal error! Worker sent a message "${f}" to target pthread ${g.Ub}, but that thread no longer exists!`)}else if("checkMailbox"===f)Da();else if("spawnThread"===f)ed(g);else if("cleanupThread"===f)kd(()=>{jd(S[g.ec])});else if("loaded"===f)a.loaded=!0,m&&!a.Qb&&a.unref(),b(a);else if("setimmediate"===g.target)a.postMessage(g);else if("uncaughtException"===f)a.onerror(g.error);
|
|
19
|
+
else if("callHandler"===f)h[g.$b](...g.args);else f&&p(`worker sent an unknown command ${f}`)};a.onerror=f=>{p(`${"worker sent an error!"} ${f.filename}:${f.lineno}: ${f.message}`);throw f;};m&&(a.on("message",f=>a.onmessage({data:f})),a.on("error",f=>a.onerror(f)));var d=[],c=[],e;for(e of c)h.propertyIsEnumerable(e)&&d.push(e);a.postMessage({Rb:"load",ac:d,fc:x,hc:r})});async function hd(){if(!n)return Promise.all(Q.map(dd))}
|
|
20
|
+
function cd(){var a=new Worker(new URL(import.meta.url),{type:"module",workerData:"em-pthread",name:"em-pthread"});Q.push(a)}function ya(a){var b=(v(),D)[a+52>>>2>>>0];a=(v(),D)[a+56>>>2>>>0];Tc(b,b-a);M(b)}var ld=[],V=a=>{var b=ld[a];b||(ld[a]=b=Zc.get(a));return b},Ca=(a,b)=>{T=0;a=V(a)(b);0<T?t=a:Qc(a)},x,md=[],nd=0;function Ra(a){a>>>=0;var b=new od(a);0==(v(),z)[b.Sb+12>>>0]&&(pd(b,!0),nd--);qd(b,!1);md.push(b);return Yc(a)}
|
|
21
|
+
var W=0,Sa=()=>{K(0,0);var a=md.pop();Vc(a.Wb);W=0};function pd(a,b){b=b?1:0;(v(),z)[a.Sb+12>>>0]=b}function qd(a,b){b=b?1:0;(v(),z)[a.Sb+13>>>0]=b}class od{constructor(a){this.Wb=a;this.Sb=a-24}}var rd=a=>{var b=W;if(!b)return L(0),0;var d=new od(b);(v(),D)[d.Sb+16>>>2>>>0]=b;var c=(v(),D)[d.Sb+4>>>2>>>0];if(!c)return L(0),b;for(var e of a){if(0===e||e===c)break;if(Xc(e,c,d.Sb+16))return L(e),b}L(c);return b};function Ta(){return rd([])}function Ua(a){return rd([a>>>0])}
|
|
22
|
+
function Va(a,b,d,c){return rd([a>>>0,b>>>0,d>>>0,c>>>0])}var Wa=()=>{var a=md.pop();a||J("no exception to throw");var b=a.Wb;0==(v(),z)[a.Sb+13>>>0]&&(md.push(a),qd(a,!0),pd(a,!1),nd++);Wc(b);W=b;throw W;};function Xa(a,b,d){a>>>=0;var c=new od(a);b>>>=0;d>>>=0;(v(),D)[c.Sb+16>>>2>>>0]=0;(v(),D)[c.Sb+4>>>2>>>0]=b;(v(),D)[c.Sb+8>>>2>>>0]=d;Wc(a);W=a;nd++;throw W;}var Ya=()=>nd;function sd(a,b,d,c){return n?U(2,1,a,b,d,c):Za(a,b,d,c)}
|
|
23
|
+
function Za(a,b,d,c){a>>>=0;b>>>=0;d>>>=0;c>>>=0;if(!globalThis.SharedArrayBuffer)return 6;var e=[];if(n&&0===e.length)return sd(a,b,d,c);a={cc:d,Qb:a,Vb:c,Zb:e};return n?(a.Rb="spawnThread",postMessage(a,e),0):ed(a)}function $a(a){W||=a>>>0;throw W;}
|
|
24
|
+
var td=globalThis.TextDecoder&&new TextDecoder,ud=(a,b=0,d,c)=>{b>>>=0;var e=b;d=e+d;if(c)c=d;else{for(;a[e]&&!(e>=d);)++e;c=e}if(16<c-b&&a.buffer&&td)return td.decode(a.buffer instanceof ArrayBuffer?a.subarray(b,c):a.slice(b,c));for(e="";b<c;)if(d=a[b++],d&128){var f=a[b++]&63;if(192==(d&224))e+=String.fromCharCode((d&31)<<6|f);else{var g=a[b++]&63;d=224==(d&240)?(d&15)<<12|f<<6|g:(d&7)<<18|f<<12|g<<6|a[b++]&63;65536>d?e+=String.fromCharCode(d):(d-=65536,e+=String.fromCharCode(55296|d>>10,56320|
|
|
25
|
+
d&1023))}}else e+=String.fromCharCode(d);return e},vd=(a,b,d)=>(a>>>=0)?ud((v(),A),a,b,d):"";function ab(a,b,d){return n?U(3,1,a,b,d):0}function bb(a,b){if(n)return U(4,1,a,b)}function cb(a,b){if(n)return U(5,1,a,b)}function db(a,b,d){if(n)return U(6,1,a,b,d)}function eb(a,b,d){return n?U(7,1,a,b,d):0}function fb(a,b){if(n)return U(8,1,a,b)}function gb(a,b,d){if(n)return U(9,1,a,b,d)}function hb(a,b,d,c){if(n)return U(10,1,a,b,d,c)}function ib(a,b,d,c){if(n)return U(11,1,a,b,d,c)}
|
|
26
|
+
function jb(a,b,d,c){if(n)return U(12,1,a,b,d,c)}function kb(a){if(n)return U(13,1,a)}function lb(a,b){if(n)return U(14,1,a,b)}function mb(a,b,d){if(n)return U(15,1,a,b,d)}var nb=()=>J("");function ob(a){za(a>>>0,!k,1,!aa,131072,!1);Aa()}
|
|
27
|
+
var kd=a=>{if(!pa)try{if(a(),!(0<T))try{n?Lc()&&Qc(t):Qb(t)}catch(b){b instanceof $c||"unwind"==b||da(1,b)}}catch(b){b instanceof $c||"unwind"==b||da(1,b)}},wd=!Atomics.waitAsync||globalThis.navigator?.userAgent&&91>Number((navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)||[])[2]);function Ba(a){a>>>=0;wd||(Atomics.waitAsync((v(),C),a>>>2,a).value.then(Da),a+=128,Atomics.store((v(),C),a>>>2,1))}var Da=()=>kd(()=>{var a=Lc();a&&(Ba(a),Sc())});
|
|
28
|
+
function pb(a,b){a>>>=0;a==b>>>0?setTimeout(Da):n?postMessage({Ub:a,Rb:"checkMailbox"}):(a=S[a])&&a.postMessage({Rb:"checkMailbox"})}var xd=[];function qb(a,b,d,c,e){b>>>=0;e>>>=0;xd.length=0;d=e>>>3;for(c=e+c>>>3;d<c;){var f;(v(),H)[d++>>>0]?f=(v(),H)[d++>>>0]:f=(v(),G)[d++>>>0];xd.push(f)}return(b?yd[b]:zd[a])(...xd)}var rb=()=>{T=0};function sb(a){a>>>=0;n?postMessage({Rb:"cleanupThread",ec:a}):jd(S[a])}function tb(a){m&&S[a>>>0].ref()}
|
|
29
|
+
function ub(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);(v(),C)[b>>>2>>>0]=a.getUTCSeconds();(v(),C)[b+4>>>2>>>0]=a.getUTCMinutes();(v(),C)[b+8>>>2>>>0]=a.getUTCHours();(v(),C)[b+12>>>2>>>0]=a.getUTCDate();(v(),C)[b+16>>>2>>>0]=a.getUTCMonth();(v(),C)[b+20>>>2>>>0]=a.getUTCFullYear()-1900;(v(),C)[b+24>>>2>>>0]=a.getUTCDay();a=(a.getTime()-Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0))/864E5|0;(v(),C)[b+28>>>2>>>0]=a}
|
|
30
|
+
var Ad=a=>0===a%4&&(0!==a%100||0===a%400),Bd=[0,31,60,91,121,152,182,213,244,274,305,335],Cd=[0,31,59,90,120,151,181,212,243,273,304,334];
|
|
31
|
+
function vb(a,b){a=-9007199254740992>a||9007199254740992<a?NaN:Number(a);b>>>=0;a=new Date(1E3*a);(v(),C)[b>>>2>>>0]=a.getSeconds();(v(),C)[b+4>>>2>>>0]=a.getMinutes();(v(),C)[b+8>>>2>>>0]=a.getHours();(v(),C)[b+12>>>2>>>0]=a.getDate();(v(),C)[b+16>>>2>>>0]=a.getMonth();(v(),C)[b+20>>>2>>>0]=a.getFullYear()-1900;(v(),C)[b+24>>>2>>>0]=a.getDay();var d=(Ad(a.getFullYear())?Bd:Cd)[a.getMonth()]+a.getDate()-1|0;(v(),C)[b+28>>>2>>>0]=d;(v(),C)[b+36>>>2>>>0]=-(60*a.getTimezoneOffset());d=(new Date(a.getFullYear(),
|
|
32
|
+
6,1)).getTimezoneOffset();var c=(new Date(a.getFullYear(),0,1)).getTimezoneOffset();a=(d!=c&&a.getTimezoneOffset()==Math.min(c,d))|0;(v(),C)[b+32>>>2>>>0]=a}
|
|
33
|
+
function wb(a){a>>>=0;var b=new Date((v(),C)[a+20>>>2>>>0]+1900,(v(),C)[a+16>>>2>>>0],(v(),C)[a+12>>>2>>>0],(v(),C)[a+8>>>2>>>0],(v(),C)[a+4>>>2>>>0],(v(),C)[a>>>2>>>0],0),d=(v(),C)[a+32>>>2>>>0],c=b.getTimezoneOffset(),e=(new Date(b.getFullYear(),6,1)).getTimezoneOffset(),f=(new Date(b.getFullYear(),0,1)).getTimezoneOffset(),g=Math.min(f,e);0>d?(v(),C)[a+32>>>2>>>0]=Number(e!=f&&g==c):0<d!=(g==c)&&(e=Math.max(f,e),b.setTime(b.getTime()+6E4*((0<d?g:e)-c)));(v(),C)[a+24>>>2>>>0]=b.getDay();d=(Ad(b.getFullYear())?
|
|
34
|
+
Bd:Cd)[b.getMonth()]+b.getDate()-1|0;(v(),C)[a+28>>>2>>>0]=d;(v(),C)[a>>>2>>>0]=b.getSeconds();(v(),C)[a+4>>>2>>>0]=b.getMinutes();(v(),C)[a+8>>>2>>>0]=b.getHours();(v(),C)[a+12>>>2>>>0]=b.getDate();(v(),C)[a+16>>>2>>>0]=b.getMonth();(v(),C)[a+20>>>2>>>0]=b.getYear();a=b.getTime();return BigInt(isNaN(a)?-1:a/1E3)}function xb(a,b,d,c,e,f,g){return n?U(16,1,a,b,d,c,e,f,g):-52}function yb(a,b,d,c,e,f){if(n)return U(17,1,a,b,d,c,e,f)}var X={},Ib=()=>performance.timeOrigin+performance.now();
|
|
35
|
+
function zb(a,b){if(n)return U(18,1,a,b);X[a]&&(clearTimeout(X[a].id),delete X[a]);if(!b)return 0;var d=setTimeout(()=>{delete X[a];kd(()=>Rc(a,performance.timeOrigin+performance.now()))},b);X[a]={id:d,oc:b};return 0}
|
|
36
|
+
var Y=(a,b,d)=>{var c=(v(),A);b>>>=0;if(0<d){var e=b;d=b+d-1;for(var f=0;f<a.length;++f){var g=a.codePointAt(f);if(127>=g){if(b>=d)break;c[b++>>>0]=g}else if(2047>=g){if(b+1>=d)break;c[b++>>>0]=192|g>>6;c[b++>>>0]=128|g&63}else if(65535>=g){if(b+2>=d)break;c[b++>>>0]=224|g>>12;c[b++>>>0]=128|g>>6&63;c[b++>>>0]=128|g&63}else{if(b+3>=d)break;c[b++>>>0]=240|g>>18;c[b++>>>0]=128|g>>12&63;c[b++>>>0]=128|g>>6&63;c[b++>>>0]=128|g&63;f++}}c[b>>>0]=0;a=b-e}else a=0;return a};
|
|
37
|
+
function Ab(a,b,d,c){a>>>=0;b>>>=0;d>>>=0;c>>>=0;var e=(new Date).getFullYear(),f=(new Date(e,0,1)).getTimezoneOffset();e=(new Date(e,6,1)).getTimezoneOffset();var g=Math.max(f,e);(v(),D)[a>>>2>>>0]=60*g;(v(),C)[b>>>2>>>0]=Number(f!=e);b=l=>{var u=Math.abs(l);return`UTC${0<=l?"-":"+"}${String(Math.floor(u/60)).padStart(2,"0")}${String(u%60).padStart(2,"0")}`};a=b(f);b=b(e);e<f?(Y(a,d,17),Y(b,c,17)):(Y(a,c,17),Y(b,d,17))}var Eb=()=>Date.now(),Dd=1;
|
|
38
|
+
function Bb(a,b,d){d>>>=0;if(!(0<=a&&3>=a))return 28;if(0===a)a=Date.now();else if(Dd)a=performance.timeOrigin+performance.now();else return 52;a=Math.round(1E6*a);(v(),H)[d>>>3>>>0]=BigInt(a);return 0}var Ed=[];function Cb(a,b,d){a>>>=0;b>>>=0;d>>>=0;Ed.length=0;for(var c;c=(v(),A)[b++>>>0];){var e=105!=c;e&=112!=c;d+=e&&d%8?4:0;Ed.push(112==c?(v(),D)[d>>>2>>>0]:106==c?(v(),H)[d>>>3>>>0]:105==c?(v(),C)[d>>>2>>>0]:(v(),G)[d>>>3>>>0]);d+=e?8:4}return yd[a](...Ed)}var Db=()=>{};
|
|
39
|
+
function Fb(a,b){return p(vd(a>>>0,b>>>0))}var Gb=()=>{T+=1;throw"unwind";};function Hb(){return 4294901760}var Jb=()=>m?require("os").cpus().length:navigator.hardwareConcurrency,Z={},Fd=a=>{for(var b=0,d=0;d<a.length;++d){var c=a.charCodeAt(d);127>=c?b++:2047>=c?b+=2:55296<=c&&57343>=c?(b+=4,++d):b+=3}return b},Gd=a=>{var b;return(b=/\bwasm-function\[\d+\]:(0x[0-9a-f]+)/.exec(a))?+b[1]:(b=/:(\d+):\d+(?:\)|$)/.exec(a))?2147483648|+b[1]:0},Hd=a=>{for(var b of a)(a=Gd(b))&&(Z[a]=b)};
|
|
40
|
+
function Mb(){var a=Error().stack.toString().split("\n");"Error"==a[0]&&a.shift();Hd(a);Z.Xb=Gd(a[3]);Z.bc=a;return Z.Xb}function Kb(a){a=Z[a>>>0];if(!a)return 0;var b;if(b=/^\s+at .*\.wasm\.(.*) \(.*\)$/.exec(a))a=b[1];else if(b=/^\s+at (.*) \(.*\)$/.exec(a))a=b[1];else if(b=/^(.+?)@/.exec(a))a=b[1];else return 0;Mc(Kb.Yb??0);b=Fd(a)+1;var d=Nc(b);d&&Y(a,d,b);Kb.Yb=d;return Kb.Yb}
|
|
41
|
+
function Lb(a){a>>>=0;var b=(v(),A).length;if(a<=b||4294901760<a)return!1;for(var d=1;4>=d;d*=2){var c=b*(1+.2/d);c=Math.min(c,a+100663296);a:{c=(Math.min(4294901760,65536*Math.ceil(Math.max(a,c)/65536))-x.buffer.byteLength+65535)/65536|0;try{x.grow(c);qa();var e=1;break a}catch(f){}e=void 0}if(e)return!0}return!1}
|
|
42
|
+
function Nb(a,b,d){a>>>=0;b>>>=0;if(Z.Xb==a)var c=Z.bc;else c=Error().stack.toString().split("\n"),"Error"==c[0]&&c.shift(),Hd(c);for(var e=3;c[e]&&Gd(c[e])!=a;)++e;for(a=0;a<d&&c[a+e];++a)(v(),C)[b+4*a>>>2>>>0]=Gd(c[a+e]);return a}
|
|
43
|
+
var Id={},Kd=()=>{if(!Jd){var a={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:(globalThis.navigator?.language??"C").replace("-","_")+".UTF-8",_:ca||"./this.program"},b;for(b in Id)void 0===Id[b]?delete a[b]:a[b]=Id[b];var d=[];for(b in a)d.push(`${b}=${a[b]}`);Jd=d}return Jd},Jd;function Ob(a,b){if(n)return U(19,1,a,b);a>>>=0;b>>>=0;var d=0,c=0,e;for(e of Kd()){var f=b+d;(v(),D)[a+c>>>2>>>0]=f;d+=Y(e,f,Infinity)+1;c+=4}return 0}
|
|
44
|
+
function Pb(a,b){if(n)return U(20,1,a,b);a>>>=0;b>>>=0;var d=Kd();(v(),D)[a>>>2>>>0]=d.length;a=0;for(var c of d)a+=Fd(c)+1;(v(),D)[b>>>2>>>0]=a;return 0}function Rb(a){return n?U(21,1,a):52}function Sb(a,b,d,c,e){return n?U(22,1,a,b,d,c,e):52}function Tb(a,b,d,c){return n?U(23,1,a,b,d,c):52}function Ub(a,b,d,c){return n?U(24,1,a,b,d,c):70}var Ld=[null,[],[]];
|
|
45
|
+
function Vb(a,b,d,c){if(n)return U(25,1,a,b,d,c);b>>>=0;d>>>=0;c>>>=0;for(var e=0,f=0;f<d;f++){var g=(v(),D)[b>>>2>>>0],l=(v(),D)[b+4>>>2>>>0];b+=8;for(var u=0;u<l;u++){var w=a,y=(v(),A)[g+u>>>0],B=Ld[w];0===y||10===y?((1===w?oa:p)(ud(B)),B.length=0):B.push(y)}e+=l}(v(),D)[c>>>2>>>0]=e;return 0}function Hc(a){return a>>>0}n||gd();n||(x=new WebAssembly.Memory({initial:256,maximum:65536,shared:!0}),qa());h.wasmBinary&&(q=h.wasmBinary);h.stackSave=()=>N();h.stackRestore=a=>M(a);h.stackAlloc=a=>Uc(a);
|
|
46
|
+
h.setValue=function(a,b,d="i8"){d.endsWith("*")&&(d="*");switch(d){case "i1":(v(),z)[a>>>0]=b;break;case "i8":(v(),z)[a>>>0]=b;break;case "i16":(v(),Fa)[a>>>1>>>0]=b;break;case "i32":(v(),C)[a>>>2>>>0]=b;break;case "i64":(v(),H)[a>>>3>>>0]=BigInt(b);break;case "float":(v(),Ga)[a>>>2>>>0]=b;break;case "double":(v(),G)[a>>>3>>>0]=b;break;case "*":(v(),D)[a>>>2>>>0]=b;break;default:J(`invalid type for setValue: ${d}`)}};
|
|
47
|
+
h.getValue=function(a,b="i8"){b.endsWith("*")&&(b="*");switch(b){case "i1":return(v(),z)[a>>>0];case "i8":return(v(),z)[a>>>0];case "i16":return(v(),Fa)[a>>>1>>>0];case "i32":return(v(),C)[a>>>2>>>0];case "i64":return(v(),H)[a>>>3>>>0];case "float":return(v(),Ga)[a>>>2>>>0];case "double":return(v(),G)[a>>>3>>>0];case "*":return(v(),D)[a>>>2>>>0];default:J(`invalid type for getValue: ${b}`)}};h.UTF8ToString=vd;h.stringToUTF8=Y;h.lengthBytesUTF8=Fd;
|
|
48
|
+
var zd=[Ic,fd,sd,ab,bb,cb,db,eb,fb,gb,hb,ib,jb,kb,lb,mb,xb,yb,zb,Ob,Pb,Rb,Sb,Tb,Ub,Vb],yd={1042604:(a,b,d,c,e)=>{if("undefined"==typeof h||!h.Tb)return 1;a=vd(Number(a>>>0));a.startsWith("./")&&(a=a.substring(2));a=h.Tb.get(a);if(!a)return 2;b=Number(b>>>0);d=Number(d>>>0);c=Number(c>>>0);if(b+d>a.byteLength)return 3;try{const f=a.subarray(b,b+d);switch(e){case 0:(v(),A).set(f,c>>>0);break;case 1:h.ic?h.ic(c,f):h.kc(c,f);break;default:return 4}return 0}catch{return 4}},1043428:()=>"undefined"!==typeof wasmOffsetConverter};
|
|
49
|
+
function Qa(){return"undefined"!==typeof wasmOffsetConverter}var Lc,Mc,Nc,za,Ea,Oc,Pc,Qc,Rc,Sc,K,L,Tc,M,Uc,N,Vc,Wc,Xc,Yc,Zc,Pa;function cc(a,b,d,c){var e=N();try{return V(a)(b,d,c)}catch(f){M(e);if(f!==f+0)throw f;K(1,0)}}function bc(a,b,d){var c=N();try{return V(a)(b,d)}catch(e){M(c);if(e!==e+0)throw e;K(1,0)}}function sc(a){var b=N();try{V(a)()}catch(d){M(b);if(d!==d+0)throw d;K(1,0)}}function ac(a,b){var d=N();try{return V(a)(b)}catch(c){M(d);if(c!==c+0)throw c;K(1,0)}}
|
|
50
|
+
function uc(a,b,d){var c=N();try{V(a)(b,d)}catch(e){M(c);if(e!==e+0)throw e;K(1,0)}}function tc(a,b){var d=N();try{V(a)(b)}catch(c){M(d);if(c!==c+0)throw c;K(1,0)}}function gc(a,b,d,c,e,f,g){var l=N();try{return V(a)(b,d,c,e,f,g)}catch(u){M(l);if(u!==u+0)throw u;K(1,0)}}function yc(a,b,d,c,e,f){var g=N();try{V(a)(b,d,c,e,f)}catch(l){M(g);if(l!==l+0)throw l;K(1,0)}}function wc(a,b,d,c){var e=N();try{V(a)(b,d,c)}catch(f){M(e);if(f!==f+0)throw f;K(1,0)}}
|
|
51
|
+
function xc(a,b,d,c,e){var f=N();try{V(a)(b,d,c,e)}catch(g){M(f);if(g!==g+0)throw g;K(1,0)}}function zc(a,b,d,c,e,f,g){var l=N();try{V(a)(b,d,c,e,f,g)}catch(u){M(l);if(u!==u+0)throw u;K(1,0)}}function Gc(a,b,d,c,e,f,g){var l=N();try{V(a)(b,d,c,e,f,g)}catch(u){M(l);if(u!==u+0)throw u;K(1,0)}}function Fc(a,b,d,c,e,f,g,l){var u=N();try{V(a)(b,d,c,e,f,g,l)}catch(w){M(u);if(w!==w+0)throw w;K(1,0)}}function dc(a,b,d,c,e){var f=N();try{return V(a)(b,d,c,e)}catch(g){M(f);if(g!==g+0)throw g;K(1,0)}}
|
|
52
|
+
function mc(a,b,d){var c=N();try{return V(a)(b,d)}catch(e){M(c);if(e!==e+0)throw e;K(1,0)}}function Ac(a,b,d,c,e,f,g,l){var u=N();try{V(a)(b,d,c,e,f,g,l)}catch(w){M(u);if(w!==w+0)throw w;K(1,0)}}function Dc(a,b,d,c,e,f,g,l,u,w,y,B){var E=N();try{V(a)(b,d,c,e,f,g,l,u,w,y,B)}catch(F){M(E);if(F!==F+0)throw F;K(1,0)}}function qc(a,b,d){var c=N();try{return V(a)(b,d)}catch(e){M(c);if(e!==e+0)throw e;K(1,0);return 0n}}
|
|
53
|
+
function Bc(a,b,d,c,e,f,g,l,u){var w=N();try{V(a)(b,d,c,e,f,g,l,u)}catch(y){M(w);if(y!==y+0)throw y;K(1,0)}}function $b(a){var b=N();try{return V(a)()}catch(d){M(b);if(d!==d+0)throw d;K(1,0)}}function pc(a,b){var d=N();try{return V(a)(b)}catch(c){M(d);if(c!==c+0)throw c;K(1,0);return 0n}}function nc(a,b,d,c){var e=N();try{return V(a)(b,d,c)}catch(f){M(e);if(f!==f+0)throw f;K(1,0)}}function oc(a){var b=N();try{return V(a)()}catch(d){M(b);if(d!==d+0)throw d;K(1,0);return 0n}}
|
|
54
|
+
function lc(a,b,d,c){var e=N();try{return V(a)(b,d,c)}catch(f){M(e);if(f!==f+0)throw f;K(1,0)}}function kc(a,b,d,c,e){var f=N();try{return V(a)(b,d,c,e)}catch(g){M(f);if(g!==g+0)throw g;K(1,0)}}function jc(a,b,d,c,e,f){var g=N();try{return V(a)(b,d,c,e,f)}catch(l){M(g);if(l!==l+0)throw l;K(1,0)}}function fc(a,b,d,c,e,f){var g=N();try{return V(a)(b,d,c,e,f)}catch(l){M(g);if(l!==l+0)throw l;K(1,0)}}
|
|
55
|
+
function ec(a,b,d,c,e,f){var g=N();try{return V(a)(b,d,c,e,f)}catch(l){M(g);if(l!==l+0)throw l;K(1,0)}}function hc(a,b,d,c,e,f,g,l){var u=N();try{return V(a)(b,d,c,e,f,g,l)}catch(w){M(u);if(w!==w+0)throw w;K(1,0)}}function rc(a,b,d,c,e){var f=N();try{return V(a)(b,d,c,e)}catch(g){M(f);if(g!==g+0)throw g;K(1,0);return 0n}}function Zb(a,b,d,c){var e=N();try{return V(a)(b,d,c)}catch(f){M(e);if(f!==f+0)throw f;K(1,0)}}
|
|
56
|
+
function Xb(a,b,d,c){var e=N();try{return V(a)(b,d,c)}catch(f){M(e);if(f!==f+0)throw f;K(1,0)}}function ic(a,b,d,c,e,f,g,l,u,w,y,B){var E=N();try{return V(a)(b,d,c,e,f,g,l,u,w,y,B)}catch(F){M(E);if(F!==F+0)throw F;K(1,0)}}function Cc(a,b,d,c,e,f,g,l,u,w,y){var B=N();try{V(a)(b,d,c,e,f,g,l,u,w,y)}catch(E){M(B);if(E!==E+0)throw E;K(1,0)}}function Ec(a,b,d,c,e,f,g,l,u,w,y,B,E,F,Md,Nd){var Od=N();try{V(a)(b,d,c,e,f,g,l,u,w,y,B,E,F,Md,Nd)}catch(Ma){M(Od);if(Ma!==Ma+0)throw Ma;K(1,0)}}
|
|
57
|
+
function Yb(a,b,d){var c=N();try{return V(a)(b,d)}catch(e){M(c);if(e!==e+0)throw e;K(1,0)}}function Wb(a,b,d){var c=N();try{return V(a)(b,d)}catch(e){M(c);if(e!==e+0)throw e;K(1,0)}}function vc(a,b,d,c){var e=N();try{V(a)(b,d,c)}catch(f){M(e);if(f!==f+0)throw f;K(1,0)}}function Jc(){var a=I;a=Object.assign({},a);var b=c=>()=>c()>>>0,d=c=>e=>c(e)>>>0;a.ub=b(a.ub);a.wb=d(a.wb);a.Kb=d(a.Kb);a.Lb=b(a.Lb);a.Pb=d(a.Pb);return a}
|
|
58
|
+
function xa(){if(0<O)P=xa;else if(n)ra?.(h),Ia();else{for(var a=bd;0<a.length;)a.shift()(h);0<O?P=xa:(h.calledRun=!0,pa||(Ia(),ra?.(h)))}}var I;n||(I=await (wa()),xa());h.PTR_SIZE=4;Ha?moduleRtn=h:moduleRtn=new Promise((a,b)=>{ra=a;sa=b});
|
|
59
|
+
;return moduleRtn}export default ortWasmThreaded;var isPthread=globalThis.self?.name?.startsWith("em-pthread");var isNode=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(isNode)isPthread=(await import("worker_threads")).workerData==="em-pthread";isPthread&&ortWasmThreaded();
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
class VoiceActivityFrames extends AudioWorkletProcessor {
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
this.frame = new Float32Array(512);
|
|
5
|
+
this.offset = 0;
|
|
6
|
+
}
|
|
7
|
+
process(inputs) {
|
|
8
|
+
const channel = inputs[0]?.[0];
|
|
9
|
+
if (!channel) return true;
|
|
10
|
+
for (const sample of channel) {
|
|
11
|
+
this.frame[this.offset++] = sample;
|
|
12
|
+
if (this.offset === 512) {
|
|
13
|
+
this.port.postMessage(this.frame, [this.frame.buffer]);
|
|
14
|
+
this.frame = new Float32Array(512);
|
|
15
|
+
this.offset = 0;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
registerProcessor('voice-activity-frames', VoiceActivityFrames);
|