Spaces:
Running
Running
Upload 21 files
Browse files- .gitattributes +12 -0
- README.md +3 -3
- app-asr.js +698 -0
- en.data +3 -0
- en.json +1 -0
- en1.ogg +3 -0
- en2.ogg +3 -0
- en3.ogg +3 -0
- en4.ogg +3 -0
- en5.ogg +3 -0
- fr.data +3 -0
- fr.json +1 -0
- fr1.ogg +3 -0
- fr2.ogg +3 -0
- fr3.ogg +3 -0
- fr4.ogg +3 -0
- fr5.ogg +3 -0
- index.html +142 -19
- model.js +209 -0
- sherpa-onnx-asr.js +1030 -0
- sherpa-onnx-wasm-main-asr.js +1 -0
- sherpa-onnx-wasm-main-asr.wasm +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,15 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
en.data filter=lfs diff=lfs merge=lfs -text
|
37 |
+
en1.ogg filter=lfs diff=lfs merge=lfs -text
|
38 |
+
en2.ogg filter=lfs diff=lfs merge=lfs -text
|
39 |
+
en3.ogg filter=lfs diff=lfs merge=lfs -text
|
40 |
+
en4.ogg filter=lfs diff=lfs merge=lfs -text
|
41 |
+
en5.ogg filter=lfs diff=lfs merge=lfs -text
|
42 |
+
fr.data filter=lfs diff=lfs merge=lfs -text
|
43 |
+
fr1.ogg filter=lfs diff=lfs merge=lfs -text
|
44 |
+
fr2.ogg filter=lfs diff=lfs merge=lfs -text
|
45 |
+
fr3.ogg filter=lfs diff=lfs merge=lfs -text
|
46 |
+
fr4.ogg filter=lfs diff=lfs merge=lfs -text
|
47 |
+
fr5.ogg filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
-
title: Kroko
|
3 |
-
emoji:
|
4 |
colorFrom: green
|
5 |
-
colorTo:
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
---
|
|
|
1 |
---
|
2 |
+
title: Kroko-Streaming-ASR-Wasm
|
3 |
+
emoji: 🐊
|
4 |
colorFrom: green
|
5 |
+
colorTo: indigo
|
6 |
sdk: static
|
7 |
pinned: false
|
8 |
---
|
app-asr.js
ADDED
@@ -0,0 +1,698 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// This file copies and modifies code
|
2 |
+
// from https://mdn.github.io/web-dictaphone/scripts/app.js
|
3 |
+
// and https://gist.github.com/meziantou/edb7217fddfbb70e899e
|
4 |
+
|
5 |
+
const urlParams = new URLSearchParams(window.location.search);
|
6 |
+
const lang = urlParams.get('lang') ?? 'en';
|
7 |
+
const activeTab = urlParams.get('tab') ?? 'single';
|
8 |
+
|
9 |
+
const startBtn = document.getElementById('recordBtn');
|
10 |
+
const hint = document.getElementById('hint');
|
11 |
+
const soundClips = document.getElementById('fileInput');
|
12 |
+
const playAllBtn = document.getElementById('playAllBtn');
|
13 |
+
|
14 |
+
let started = false;
|
15 |
+
let multistreamStarted = false;
|
16 |
+
|
17 |
+
let textArea = document.getElementById('results');
|
18 |
+
|
19 |
+
let lastResult = '';
|
20 |
+
let resultList = [];
|
21 |
+
|
22 |
+
function clear() {
|
23 |
+
resultList = [];
|
24 |
+
textArea.value = getDisplayResult();
|
25 |
+
textArea.scrollTop = textArea.scrollHeight; // auto scroll
|
26 |
+
};
|
27 |
+
|
28 |
+
function getDisplayResult() {
|
29 |
+
let i = 0;
|
30 |
+
let ans = '';
|
31 |
+
for (let s in resultList) {
|
32 |
+
if (resultList[s] == '') {
|
33 |
+
continue;
|
34 |
+
}
|
35 |
+
|
36 |
+
ans += '' + i + ': ' + resultList[s] + '\n';
|
37 |
+
i += 1;
|
38 |
+
}
|
39 |
+
|
40 |
+
if (lastResult.length > 0) {
|
41 |
+
ans += '' + i + ': ' + lastResult + '\n';
|
42 |
+
}
|
43 |
+
return ans;
|
44 |
+
}
|
45 |
+
|
46 |
+
Module = {};
|
47 |
+
Module.locateFile = function(path, scriptDirectory = '') {
|
48 |
+
if (path === 'model.data') {
|
49 |
+
return scriptDirectory + lang + '.data';
|
50 |
+
}
|
51 |
+
if (path === 'model.js.metadata') {
|
52 |
+
return scriptDirectory + lang + '.json';
|
53 |
+
}
|
54 |
+
return scriptDirectory + path;
|
55 |
+
};
|
56 |
+
Module.setStatus = function(status) {
|
57 |
+
const statusElement = document.getElementById('status');
|
58 |
+
statusElement.textContent = status;
|
59 |
+
if (status === '') {
|
60 |
+
statusElement.style.display = 'none';
|
61 |
+
document.querySelectorAll('.tab-content').forEach((tabContentElement) => {
|
62 |
+
tabContentElement.classList.remove('loading');
|
63 |
+
});
|
64 |
+
} else {
|
65 |
+
statusElement.style.display = 'block';
|
66 |
+
document.querySelectorAll('.tab-content').forEach((tabContentElement) => {
|
67 |
+
tabContentElement.classList.add('loading');
|
68 |
+
});
|
69 |
+
}
|
70 |
+
};
|
71 |
+
Module.onRuntimeInitialized = function() {
|
72 |
+
console.log('inited!');
|
73 |
+
//hint.innerText = 'Model loaded! Please click start';
|
74 |
+
|
75 |
+
started = false;
|
76 |
+
|
77 |
+
recognizer = createOnlineRecognizer(Module);
|
78 |
+
console.log('recognizer is created!', recognizer);
|
79 |
+
};
|
80 |
+
|
81 |
+
let audioCtx;
|
82 |
+
let mediaStream;
|
83 |
+
|
84 |
+
let expectedSampleRate = 16000;
|
85 |
+
let recordSampleRate; // the sampleRate of the microphone
|
86 |
+
let recorder = null; // the microphone
|
87 |
+
let leftchannel = []; // TODO: Use a single channel
|
88 |
+
|
89 |
+
let recordingLength = 0; // number of samples so far
|
90 |
+
|
91 |
+
let recognizer = null;
|
92 |
+
let recognizer_stream = null;
|
93 |
+
|
94 |
+
if (navigator.mediaDevices.getUserMedia) {
|
95 |
+
console.log('getUserMedia supported.');
|
96 |
+
|
97 |
+
// see https://w3c.github.io/mediacapture-main/#dom-mediadevices-getusermedia
|
98 |
+
const constraints = {audio: true};
|
99 |
+
|
100 |
+
let onSuccess = function(stream) {
|
101 |
+
if (!audioCtx) {
|
102 |
+
audioCtx = new AudioContext({sampleRate: 16000});
|
103 |
+
}
|
104 |
+
console.log(audioCtx);
|
105 |
+
recordSampleRate = audioCtx.sampleRate;
|
106 |
+
console.log('sample rate ' + recordSampleRate);
|
107 |
+
|
108 |
+
// creates an audio node from the microphone incoming stream
|
109 |
+
mediaStream = audioCtx.createMediaStreamSource(stream);
|
110 |
+
console.log('media stream', mediaStream);
|
111 |
+
|
112 |
+
// https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createScriptProcessor
|
113 |
+
// bufferSize: the onaudioprocess event is called when the buffer is full
|
114 |
+
var bufferSize = 4096;
|
115 |
+
var numberOfInputChannels = 1;
|
116 |
+
var numberOfOutputChannels = 2;
|
117 |
+
if (audioCtx.createScriptProcessor) {
|
118 |
+
recorder = audioCtx.createScriptProcessor(
|
119 |
+
bufferSize, numberOfInputChannels, numberOfOutputChannels);
|
120 |
+
} else {
|
121 |
+
recorder = audioCtx.createJavaScriptNode(
|
122 |
+
bufferSize, numberOfInputChannels, numberOfOutputChannels);
|
123 |
+
}
|
124 |
+
console.log('recorder', recorder);
|
125 |
+
|
126 |
+
recorder.onaudioprocess = function(e) {
|
127 |
+
let samples = new Float32Array(e.inputBuffer.getChannelData(0))
|
128 |
+
samples = downsampleBuffer(samples, expectedSampleRate);
|
129 |
+
|
130 |
+
if (recognizer_stream == null) {
|
131 |
+
recognizer_stream = recognizer.createStream();
|
132 |
+
}
|
133 |
+
|
134 |
+
recognizer_stream.acceptWaveform(expectedSampleRate, samples);
|
135 |
+
while (recognizer.isReady(recognizer_stream)) {
|
136 |
+
recognizer.decode(recognizer_stream);
|
137 |
+
}
|
138 |
+
|
139 |
+
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
140 |
+
|
141 |
+
let result = recognizer.getResult(recognizer_stream).text;
|
142 |
+
|
143 |
+
if (recognizer.config.modelConfig.paraformer.encoder != '') {
|
144 |
+
let tailPaddings = new Float32Array(expectedSampleRate);
|
145 |
+
recognizer_stream.acceptWaveform(expectedSampleRate, tailPaddings);
|
146 |
+
while (recognizer.isReady(recognizer_stream)) {
|
147 |
+
recognizer.decode(recognizer_stream);
|
148 |
+
}
|
149 |
+
result = recognizer.getResult(recognizer_stream).text;
|
150 |
+
}
|
151 |
+
|
152 |
+
|
153 |
+
if (result.length > 0 && lastResult != result) {
|
154 |
+
lastResult = result;
|
155 |
+
}
|
156 |
+
|
157 |
+
if (isEndpoint) {
|
158 |
+
if (lastResult.length > 0) {
|
159 |
+
resultList.push(lastResult);
|
160 |
+
lastResult = '';
|
161 |
+
}
|
162 |
+
recognizer.reset(recognizer_stream);
|
163 |
+
}
|
164 |
+
|
165 |
+
textArea.value = getDisplayResult();
|
166 |
+
textArea.scrollTop = textArea.scrollHeight; // auto scroll
|
167 |
+
|
168 |
+
let buf = new Int16Array(samples.length);
|
169 |
+
for (var i = 0; i < samples.length; ++i) {
|
170 |
+
let s = samples[i];
|
171 |
+
if (s >= 1)
|
172 |
+
s = 1;
|
173 |
+
else if (s <= -1)
|
174 |
+
s = -1;
|
175 |
+
|
176 |
+
samples[i] = s;
|
177 |
+
buf[i] = s * 32767;
|
178 |
+
}
|
179 |
+
|
180 |
+
leftchannel.push(buf);
|
181 |
+
recordingLength += bufferSize;
|
182 |
+
};
|
183 |
+
|
184 |
+
startBtn.onclick = function() {
|
185 |
+
if(started) {
|
186 |
+
console.log('recorder stopped');
|
187 |
+
|
188 |
+
recorder.disconnect(audioCtx.destination);
|
189 |
+
mediaStream.disconnect(recorder);
|
190 |
+
|
191 |
+
started = false;
|
192 |
+
|
193 |
+
var clipName = new Date().toISOString();
|
194 |
+
|
195 |
+
const clipContainer = document.createElement('article');
|
196 |
+
const clipLabel = document.createElement('p');
|
197 |
+
const audio = document.createElement('audio');
|
198 |
+
const deleteButton = document.createElement('button');
|
199 |
+
clipContainer.classList.add('clip');
|
200 |
+
audio.setAttribute('controls', '');
|
201 |
+
deleteButton.textContent = 'Delete';
|
202 |
+
deleteButton.className = 'delete';
|
203 |
+
|
204 |
+
clipLabel.textContent = clipName;
|
205 |
+
|
206 |
+
clipContainer.appendChild(audio);
|
207 |
+
|
208 |
+
clipContainer.appendChild(clipLabel);
|
209 |
+
clipContainer.appendChild(deleteButton);
|
210 |
+
soundClips.appendChild(clipContainer);
|
211 |
+
|
212 |
+
audio.controls = true;
|
213 |
+
let samples = flatten(leftchannel);
|
214 |
+
const blob = toWav(samples);
|
215 |
+
|
216 |
+
leftchannel = [];
|
217 |
+
const audioURL = window.URL.createObjectURL(blob);
|
218 |
+
audio.src = audioURL;
|
219 |
+
console.log('recorder stopped');
|
220 |
+
|
221 |
+
deleteButton.onclick = function(e) {
|
222 |
+
let evtTgt = e.target;
|
223 |
+
evtTgt.parentNode.parentNode.removeChild(evtTgt.parentNode);
|
224 |
+
};
|
225 |
+
|
226 |
+
clipLabel.onclick = function() {
|
227 |
+
const existingName = clipLabel.textContent;
|
228 |
+
const newClipName = prompt('Enter a new name for your sound clip?');
|
229 |
+
if (newClipName === null) {
|
230 |
+
clipLabel.textContent = existingName;
|
231 |
+
} else {
|
232 |
+
clipLabel.textContent = newClipName;
|
233 |
+
}
|
234 |
+
};
|
235 |
+
}
|
236 |
+
else {
|
237 |
+
mediaStream.connect(recorder);
|
238 |
+
recorder.connect(audioCtx.destination);
|
239 |
+
|
240 |
+
console.log('recorder started');
|
241 |
+
|
242 |
+
started = true;
|
243 |
+
}
|
244 |
+
};
|
245 |
+
};
|
246 |
+
|
247 |
+
let onError = function(err) {
|
248 |
+
console.log('The following error occured: ' + err);
|
249 |
+
};
|
250 |
+
|
251 |
+
navigator.mediaDevices.getUserMedia(constraints).then(onSuccess, onError);
|
252 |
+
} else {
|
253 |
+
console.log('getUserMedia not supported on your browser!');
|
254 |
+
alert('getUserMedia not supported on your browser!');
|
255 |
+
}
|
256 |
+
|
257 |
+
playAllBtn.onclick = function() {
|
258 |
+
if(!multistreamStarted) {
|
259 |
+
multistreamStarted = true;
|
260 |
+
playAllBtn.textContent = "Stop All Streams";
|
261 |
+
playAllBtn.style.backgroundColor = "#d9534f";
|
262 |
+
|
263 |
+
transcribe(audioSources[lang][0], 'transcript1', 0);
|
264 |
+
transcribe(audioSources[lang][1], 'transcript2', 1);
|
265 |
+
transcribe(audioSources[lang][2], 'transcript3', 2);
|
266 |
+
transcribe(audioSources[lang][3], 'transcript4', 3);
|
267 |
+
transcribe(audioSources[lang][4], 'transcript5', 4);
|
268 |
+
}
|
269 |
+
else {
|
270 |
+
audios[0].pause();
|
271 |
+
audios[1].pause();
|
272 |
+
audios[2].pause();
|
273 |
+
audios[3].pause();
|
274 |
+
audios[4].pause();
|
275 |
+
audios[0].currentTime = 0;
|
276 |
+
audios[1].currentTime = 0;
|
277 |
+
audios[2].currentTime = 0;
|
278 |
+
audios[3].currentTime = 0;
|
279 |
+
audios[4].currentTime = 0;
|
280 |
+
|
281 |
+
playAllBtn.textContent = "Play All Streams";
|
282 |
+
playAllBtn.style.backgroundColor = "#007bff";
|
283 |
+
|
284 |
+
multistreamStarted = false;
|
285 |
+
}
|
286 |
+
}
|
287 |
+
|
288 |
+
|
289 |
+
// this function is copied/modified from
|
290 |
+
// https://gist.github.com/meziantou/edb7217fddfbb70e899e
|
291 |
+
function flatten(listOfSamples) {
|
292 |
+
let n = 0;
|
293 |
+
for (let i = 0; i < listOfSamples.length; ++i) {
|
294 |
+
n += listOfSamples[i].length;
|
295 |
+
}
|
296 |
+
let ans = new Int16Array(n);
|
297 |
+
|
298 |
+
let offset = 0;
|
299 |
+
for (let i = 0; i < listOfSamples.length; ++i) {
|
300 |
+
ans.set(listOfSamples[i], offset);
|
301 |
+
offset += listOfSamples[i].length;
|
302 |
+
}
|
303 |
+
return ans;
|
304 |
+
}
|
305 |
+
|
306 |
+
// this function is copied/modified from
|
307 |
+
// https://gist.github.com/meziantou/edb7217fddfbb70e899e
|
308 |
+
function toWav(samples) {
|
309 |
+
let buf = new ArrayBuffer(44 + samples.length * 2);
|
310 |
+
var view = new DataView(buf);
|
311 |
+
|
312 |
+
// http://soundfile.sapp.org/doc/WaveFormat/
|
313 |
+
// F F I R
|
314 |
+
view.setUint32(0, 0x46464952, true); // chunkID
|
315 |
+
view.setUint32(4, 36 + samples.length * 2, true); // chunkSize
|
316 |
+
// E V A W
|
317 |
+
view.setUint32(8, 0x45564157, true); // format
|
318 |
+
//
|
319 |
+
// t m f
|
320 |
+
view.setUint32(12, 0x20746d66, true); // subchunk1ID
|
321 |
+
view.setUint32(16, 16, true); // subchunk1Size, 16 for PCM
|
322 |
+
view.setUint32(20, 1, true); // audioFormat, 1 for PCM
|
323 |
+
view.setUint16(22, 1, true); // numChannels: 1 channel
|
324 |
+
view.setUint32(24, expectedSampleRate, true); // sampleRate
|
325 |
+
view.setUint32(28, expectedSampleRate * 2, true); // byteRate
|
326 |
+
view.setUint16(32, 2, true); // blockAlign
|
327 |
+
view.setUint16(34, 16, true); // bitsPerSample
|
328 |
+
view.setUint32(36, 0x61746164, true); // Subchunk2ID
|
329 |
+
view.setUint32(40, samples.length * 2, true); // subchunk2Size
|
330 |
+
|
331 |
+
let offset = 44;
|
332 |
+
for (let i = 0; i < samples.length; ++i) {
|
333 |
+
view.setInt16(offset, samples[i], true);
|
334 |
+
offset += 2;
|
335 |
+
}
|
336 |
+
|
337 |
+
return new Blob([view], {type: 'audio/wav'});
|
338 |
+
}
|
339 |
+
|
340 |
+
// this function is copied from
|
341 |
+
// https://github.com/awslabs/aws-lex-browser-audio-capture/blob/master/lib/worker.js#L46
|
342 |
+
function downsampleBuffer(buffer, exportSampleRate) {
|
343 |
+
if (exportSampleRate === recordSampleRate) {
|
344 |
+
return buffer;
|
345 |
+
}
|
346 |
+
var sampleRateRatio = recordSampleRate / exportSampleRate;
|
347 |
+
var newLength = Math.round(buffer.length / sampleRateRatio);
|
348 |
+
var result = new Float32Array(newLength);
|
349 |
+
var offsetResult = 0;
|
350 |
+
var offsetBuffer = 0;
|
351 |
+
while (offsetResult < result.length) {
|
352 |
+
var nextOffsetBuffer = Math.round((offsetResult + 1) * sampleRateRatio);
|
353 |
+
var accum = 0, count = 0;
|
354 |
+
for (var i = offsetBuffer; i < nextOffsetBuffer && i < buffer.length; i++) {
|
355 |
+
accum += buffer[i];
|
356 |
+
count++;
|
357 |
+
}
|
358 |
+
result[offsetResult] = accum / count;
|
359 |
+
offsetResult++;
|
360 |
+
offsetBuffer = nextOffsetBuffer;
|
361 |
+
}
|
362 |
+
return result;
|
363 |
+
};
|
364 |
+
|
365 |
+
async function processArrayBufferWithASR(arrayBuffer, file) {
|
366 |
+
// Check if recognizer is ready.
|
367 |
+
if (recognizer === null) {
|
368 |
+
console.error("Recognizer not yet initialized! Please wait for WASM to load.");
|
369 |
+
//resultsTextarea.value = "Error: Recognizer not ready.";
|
370 |
+
return;
|
371 |
+
}
|
372 |
+
// Create an AudioContext. (On some platforms, creating multiple AudioContexts can be problematic.
|
373 |
+
// If needed, consider reusing a global AudioContext.)
|
374 |
+
const audioCtx = new (window.AudioContext || window.webkitAudioContext)({
|
375 |
+
sampleRate: expectedSampleRate
|
376 |
+
});
|
377 |
+
try {
|
378 |
+
const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
|
379 |
+
console.log("AudioBuffer decoded. Duration (s):", audioBuffer.duration);
|
380 |
+
let channelData = audioBuffer.getChannelData(0);
|
381 |
+
console.log("Channel data length:", channelData.length);
|
382 |
+
// Downsample if necessary.
|
383 |
+
if (audioBuffer.sampleRate !== expectedSampleRate) {
|
384 |
+
console.log("Downsampling from", audioBuffer.sampleRate, "to", expectedSampleRate);
|
385 |
+
channelData = downsampleBuffer(channelData, expectedSampleRate, audioBuffer.sampleRate);
|
386 |
+
console.log("Downsampled channel data length:", channelData.length);
|
387 |
+
}
|
388 |
+
// Create a new recognizer stream.
|
389 |
+
const stream = recognizer.createStream();
|
390 |
+
const chunkSize = expectedSampleRate; // assume 1 second worth of samples per chunk.
|
391 |
+
for (let i = 0; i < channelData.length; i += chunkSize) {
|
392 |
+
const chunk = channelData.subarray(i, i + chunkSize);
|
393 |
+
stream.acceptWaveform(expectedSampleRate, chunk);
|
394 |
+
while (recognizer.isReady(stream)) {
|
395 |
+
recognizer.decode(stream);
|
396 |
+
}
|
397 |
+
}
|
398 |
+
// Flush any tail data if necessary.
|
399 |
+
const tail = new Float32Array(expectedSampleRate);
|
400 |
+
stream.acceptWaveform(expectedSampleRate, tail);
|
401 |
+
while (recognizer.isReady(stream)) {
|
402 |
+
recognizer.decode(stream);
|
403 |
+
}
|
404 |
+
const fileResult = recognizer.getResult(stream).text || "";
|
405 |
+
console.log("ASR result for file:", fileResult);
|
406 |
+
textArea.value = fileResult;
|
407 |
+
} catch (err) {
|
408 |
+
console.error("Error decoding audio data:", err);
|
409 |
+
//resultsTextarea.value = "Error processing audio: " + err.message;
|
410 |
+
}
|
411 |
+
}
|
412 |
+
|
413 |
+
const audios = []
|
414 |
+
const recorders = []
|
415 |
+
|
416 |
+
async function loadAudio(url) {
|
417 |
+
try {
|
418 |
+
const response = await fetch(url, { mode: "cors" });
|
419 |
+
if (!response.ok) throw new Error("Network response was not ok");
|
420 |
+
|
421 |
+
const blob = await response.blob();
|
422 |
+
const objectUrl = URL.createObjectURL(blob);
|
423 |
+
|
424 |
+
return new Audio(objectUrl);
|
425 |
+
} catch (error) {
|
426 |
+
console.error("Error loading audio:", error);
|
427 |
+
}
|
428 |
+
}
|
429 |
+
|
430 |
+
async function transcribe(url, output, index) {
|
431 |
+
let urlLabel = document.createElement('h2');
|
432 |
+
//urlLabel.textContent = url;
|
433 |
+
let textarea = document.getElementById(output);
|
434 |
+
textarea.value = '';
|
435 |
+
|
436 |
+
//textarea.readOnly = true;
|
437 |
+
//textarea.rows = 10;
|
438 |
+
//document.querySelector('#container').append(urlLabel);
|
439 |
+
//document.querySelector('#container').append(textarea);
|
440 |
+
|
441 |
+
let lastResult = '';
|
442 |
+
let resultList = [];
|
443 |
+
|
444 |
+
function getDisplayResult() {
|
445 |
+
let i = 0;
|
446 |
+
let ans = '';
|
447 |
+
for (let s in resultList) {
|
448 |
+
if (resultList[s] == '') {
|
449 |
+
continue;
|
450 |
+
}
|
451 |
+
|
452 |
+
ans += '' + i + ': ' + resultList[s] + '\n';
|
453 |
+
i += 1;
|
454 |
+
}
|
455 |
+
|
456 |
+
if (lastResult.length > 0) {
|
457 |
+
ans += '' + i + ': ' + lastResult + '\n';
|
458 |
+
}
|
459 |
+
return ans;
|
460 |
+
}
|
461 |
+
|
462 |
+
if(!audios[index]) {
|
463 |
+
audios[index] = await loadAudio(url);
|
464 |
+
}
|
465 |
+
audios[index].play();
|
466 |
+
|
467 |
+
console.log(audioCtx);
|
468 |
+
let recordSampleRate = audioCtx.sampleRate;
|
469 |
+
console.log('sample rate ' + recordSampleRate);
|
470 |
+
|
471 |
+
// https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createScriptProcessor
|
472 |
+
// bufferSize: the onaudioprocess event is called when the buffer is full
|
473 |
+
var bufferSize = 4096;
|
474 |
+
var numberOfInputChannels = 1;
|
475 |
+
var numberOfOutputChannels = 2;
|
476 |
+
if(!recorders[index]) {
|
477 |
+
recorders[index] = audioCtx.createScriptProcessor(
|
478 |
+
bufferSize, numberOfInputChannels, numberOfOutputChannels);
|
479 |
+
let mediaStream = audioCtx.createMediaElementSource(audios[index]);
|
480 |
+
mediaStream.connect(recorders[index]);
|
481 |
+
recorders[index].connect(audioCtx.destination);
|
482 |
+
}
|
483 |
+
|
484 |
+
|
485 |
+
let recognizer_stream = null;
|
486 |
+
|
487 |
+
recorders[index].onaudioprocess = function(e) {
|
488 |
+
let samples = new Float32Array(e.inputBuffer.getChannelData(0))
|
489 |
+
e.outputBuffer.copyToChannel(samples, 0);
|
490 |
+
|
491 |
+
if (recognizer_stream == null) {
|
492 |
+
recognizer_stream = recognizer.createStream();
|
493 |
+
}
|
494 |
+
|
495 |
+
recognizer_stream.acceptWaveform(expectedSampleRate, samples);
|
496 |
+
while (recognizer.isReady(recognizer_stream)) {
|
497 |
+
recognizer.decode(recognizer_stream);
|
498 |
+
}
|
499 |
+
|
500 |
+
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
501 |
+
|
502 |
+
let result = recognizer.getResult(recognizer_stream).text;
|
503 |
+
|
504 |
+
if (result.length > 0 && lastResult != result) {
|
505 |
+
lastResult = result;
|
506 |
+
}
|
507 |
+
|
508 |
+
if (isEndpoint) {
|
509 |
+
if (lastResult.length > 0) {
|
510 |
+
resultList.push(lastResult);
|
511 |
+
lastResult = '';
|
512 |
+
}
|
513 |
+
recognizer.reset(recognizer_stream);
|
514 |
+
}
|
515 |
+
|
516 |
+
textarea.value = getDisplayResult();
|
517 |
+
textarea.scrollTop = textarea.scrollHeight; // auto scroll
|
518 |
+
|
519 |
+
let buf = new Int16Array(samples.length);
|
520 |
+
for (var i = 0; i < samples.length; ++i) {
|
521 |
+
let s = samples[i];
|
522 |
+
if (s >= 1)
|
523 |
+
s = 1;
|
524 |
+
else if (s <= -1)
|
525 |
+
s = -1;
|
526 |
+
|
527 |
+
samples[i] = s;
|
528 |
+
buf[i] = s * 32767;
|
529 |
+
}
|
530 |
+
};
|
531 |
+
|
532 |
+
recorders[index]?.addEventListener("recordingStopped", () => {
|
533 |
+
console.log("Decoding has stopped.");
|
534 |
+
mediaStream.disconnect(recorders[index]);
|
535 |
+
});
|
536 |
+
}
|
537 |
+
|
538 |
+
soundClips.addEventListener("change", function (event) {
|
539 |
+
if (!event.target.files || !event.target.files[0]) {
|
540 |
+
console.log("No file selected.");
|
541 |
+
return;
|
542 |
+
}
|
543 |
+
const file = event.target.files[0];
|
544 |
+
console.log("Selected file:", file.name, file.type, file.size, "bytes");
|
545 |
+
const reader = new FileReader();
|
546 |
+
reader.onload = function (ev) {
|
547 |
+
console.log("FileReader onload called.");
|
548 |
+
const arrayBuffer = ev.target.result;
|
549 |
+
console.log("ArrayBuffer length:", arrayBuffer.byteLength);
|
550 |
+
var url = URL.createObjectURL(file);
|
551 |
+
transcribe(url, 'results');
|
552 |
+
//processArrayBufferWithASR(arrayBuffer, file);
|
553 |
+
};
|
554 |
+
reader.onerror = function (err) {
|
555 |
+
console.error("FileReader error:", err);
|
556 |
+
};
|
557 |
+
console.log("Starting FileReader.readAsArrayBuffer...");
|
558 |
+
reader.readAsArrayBuffer(file);
|
559 |
+
});
|
560 |
+
|
561 |
+
const singleAudioTab = document.getElementById("singleAudioTab");
|
562 |
+
const multistreamTab = document.getElementById("multistreamTab");
|
563 |
+
const singleAudioContent = document.getElementById("singleAudioContent");
|
564 |
+
const multistreamContent = document.getElementById("multistreamContent");
|
565 |
+
|
566 |
+
const audioElements = [
|
567 |
+
document.getElementById("audio1"),
|
568 |
+
document.getElementById("audio2"),
|
569 |
+
document.getElementById("audio3"),
|
570 |
+
document.getElementById("audio4"),
|
571 |
+
document.getElementById("audio5"),
|
572 |
+
];
|
573 |
+
|
574 |
+
const audioSources = {
|
575 |
+
"en": [
|
576 |
+
"./en1.ogg",
|
577 |
+
"./en2.ogg",
|
578 |
+
"./en3.ogg",
|
579 |
+
"./en4.ogg",
|
580 |
+
"./en5.ogg",
|
581 |
+
],
|
582 |
+
"fr": [
|
583 |
+
"./fr1.ogg",
|
584 |
+
"./fr2.ogg",
|
585 |
+
"./fr3.ogg",
|
586 |
+
"./fr4.ogg",
|
587 |
+
"./fr5.ogg",
|
588 |
+
],
|
589 |
+
};
|
590 |
+
|
591 |
+
// Tab switching logic
|
592 |
+
singleAudioTab.addEventListener("click", () => {
|
593 |
+
singleAudioTab.classList.add("active");
|
594 |
+
multistreamTab.classList.remove("active");
|
595 |
+
singleAudioContent.style.display = "block";
|
596 |
+
multistreamContent.style.display = "none";
|
597 |
+
|
598 |
+
singleAudioTab.style.borderBottomColor = "#007bff";
|
599 |
+
multistreamTab.style.borderBottomColor = "transparent";
|
600 |
+
singleAudioTab.style.color = "#007bff";
|
601 |
+
multistreamTab.style.color = "#6c757d";
|
602 |
+
|
603 |
+
const url = new URL(window.location.href);
|
604 |
+
url.searchParams.set("tab", "single");
|
605 |
+
window.history.pushState({}, "", url.toString());
|
606 |
+
});
|
607 |
+
|
608 |
+
multistreamTab.addEventListener("click", () => {
|
609 |
+
multistreamTab.classList.add("active");
|
610 |
+
singleAudioTab.classList.remove("active");
|
611 |
+
multistreamContent.style.display = "block";
|
612 |
+
singleAudioContent.style.display = "none";
|
613 |
+
|
614 |
+
multistreamTab.style.borderBottomColor = "#007bff";
|
615 |
+
singleAudioTab.style.borderBottomColor = "transparent";
|
616 |
+
multistreamTab.style.color = "#007bff";
|
617 |
+
singleAudioTab.style.color = "#6c757d";
|
618 |
+
|
619 |
+
const url = new URL(window.location.href);
|
620 |
+
url.searchParams.set("tab", "multi");
|
621 |
+
window.history.pushState({}, "", url.toString());
|
622 |
+
});
|
623 |
+
|
624 |
+
// Load audio sources
|
625 |
+
audioElements.forEach((audio, index) => {
|
626 |
+
audio.src = audioSources[lang][index];
|
627 |
+
});
|
628 |
+
|
629 |
+
// Microphone recording logic
|
630 |
+
const recordBtn = document.getElementById("recordBtn");
|
631 |
+
const outputText = document.getElementById("outputText");
|
632 |
+
const audioPlayback = document.getElementById("audioPlayback");
|
633 |
+
|
634 |
+
let mediaRecorder;
|
635 |
+
let audioChunks = [];
|
636 |
+
|
637 |
+
recordBtn.addEventListener("click", async () => {
|
638 |
+
if (!mediaRecorder || mediaRecorder.state === "inactive") {
|
639 |
+
try {
|
640 |
+
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
641 |
+
mediaRecorder = new MediaRecorder(stream);
|
642 |
+
|
643 |
+
mediaRecorder.ondataavailable = (event) => {
|
644 |
+
audioChunks.push(event.data);
|
645 |
+
};
|
646 |
+
|
647 |
+
mediaRecorder.onstop = () => {
|
648 |
+
const audioBlob = new Blob(audioChunks, { type: "audio/wav" });
|
649 |
+
audioChunks = [];
|
650 |
+
const audioURL = URL.createObjectURL(audioBlob);
|
651 |
+
audioPlayback.src = audioURL;
|
652 |
+
audioPlayback.style.display = "block";
|
653 |
+
//outputText.value = "Recording completed. Playback is ready.";
|
654 |
+
};
|
655 |
+
|
656 |
+
mediaRecorder.start();
|
657 |
+
recordBtn.textContent = "Stop Recording";
|
658 |
+
recordBtn.style.color = "#5cb85c";
|
659 |
+
//outputText.value = "Recording...";
|
660 |
+
} catch (err) {
|
661 |
+
//outputText.value = "Error accessing microphone: " + err.message;
|
662 |
+
}
|
663 |
+
} else if (mediaRecorder.state === "recording") {
|
664 |
+
mediaRecorder.stop();
|
665 |
+
recordBtn.textContent = "Use Microphone";
|
666 |
+
recordBtn.style.color = "#d9534f";
|
667 |
+
}
|
668 |
+
});
|
669 |
+
|
670 |
+
// Function to handle language change and update URL
|
671 |
+
document.querySelectorAll('input[name="language"]').forEach((input) => {
|
672 |
+
input.addEventListener('change', function() {
|
673 |
+
const selectedLang = this.value;
|
674 |
+
|
675 |
+
// Update URL with new language parameter
|
676 |
+
const url = new URL(window.location.href);
|
677 |
+
url.searchParams.set('lang', selectedLang);
|
678 |
+
|
679 |
+
// Reload the page with new language setting
|
680 |
+
window.location.href = url.toString();
|
681 |
+
});
|
682 |
+
});
|
683 |
+
|
684 |
+
document.querySelectorAll('input[name="language"]').forEach((input) => {
|
685 |
+
input.checked = input.value === lang;
|
686 |
+
});
|
687 |
+
|
688 |
+
if (activeTab === "multi") {
|
689 |
+
multistreamTab.classList.add("active");
|
690 |
+
singleAudioTab.classList.remove("active");
|
691 |
+
multistreamContent.style.display = "block";
|
692 |
+
singleAudioContent.style.display = "none";
|
693 |
+
|
694 |
+
multistreamTab.style.borderBottomColor = "#007bff";
|
695 |
+
singleAudioTab.style.borderBottomColor = "transparent";
|
696 |
+
multistreamTab.style.color = "#007bff";
|
697 |
+
singleAudioTab.style.color = "#6c757d";
|
698 |
+
}
|
en.data
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1838b94374576507f0efaaf3aa91bb921072cdf46c8802a7c12acc527b7e1f0e
|
3 |
+
size 71056243
|
en.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"files":[{"filename":"/.gitignore","start":0,"end":0},{"filename":"/README.md","start":0,"end":3029},{"filename":"/decoder.onnx","start":3029,"end":620517},{"filename":"/encoder.onnx","start":620517,"end":70713116},{"filename":"/joiner.onnx","start":70713116,"end":71049933},{"filename":"/tokens.txt","start":71049933,"end":71056243}],"remote_package_size":71056243}
|
en1.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:dfb44beebf948f720a94ff4e9fd832274578bc7b398a92bea961429c1bd936f2
|
3 |
+
size 1349811
|
en2.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cb22f627270c075527e9121a250a86eed277af1bac3886886274f049c9832166
|
3 |
+
size 1325709
|
en3.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ac7cd76bce07e936dfec122d947bbfba3788856c2e32c82d6712faa401ad5433
|
3 |
+
size 2232896
|
en4.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cb545c1a52c034b2c5cb9af7eae17f15973e612612f81f23a0a07a331b9efee7
|
3 |
+
size 3448902
|
en5.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:0fffce00bf72f32cab74ed97ae09e779f56410392788c1a924ea92cec8d5bf98
|
3 |
+
size 2818226
|
fr.data
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:97d77f564f21cad9487ace162b7c4f4f42d2077f0a9bb0bc87d0f4964b5b59fc
|
3 |
+
size 71055348
|
fr.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"files":[{"filename":"/.gitignore","start":0,"end":0},{"filename":"/README.md","start":0,"end":3029},{"filename":"/decoder.onnx","start":3029,"end":620517},{"filename":"/encoder.onnx","start":620517,"end":70713116},{"filename":"/joiner.onnx","start":70713116,"end":71049933},{"filename":"/tokens.txt","start":71049933,"end":71055348}],"remote_package_size":71055348}
|
fr1.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9b0311f748c8d298054c7acd21f93cc2b838dbd25c7c9ae3659aa9c5cb2d1938
|
3 |
+
size 2818226
|
fr2.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4b287f4ba70bb6fba72be71d6c5b82080319c6ae6c6481ac80df98c6b6c8ecd2
|
3 |
+
size 3448902
|
fr3.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4fb9dcd52b4087354578287d361161dec59cf97a6829cba14889326ae042e1d5
|
3 |
+
size 2232896
|
fr4.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:88befaf0a530d4b9f0c9880b9439928c8931aefb7ae0a7d161898af5af990d02
|
3 |
+
size 1325709
|
fr5.ogg
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f26b68eeea22e39aa5db241edcce0b62bfab9e83d8cd5113ec24d0ef783feb28
|
3 |
+
size 1349811
|
index.html
CHANGED
@@ -1,19 +1,142 @@
|
|
1 |
-
<!
|
2 |
-
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
</
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
6 |
+
<title>Audio Input with Tabs and Features</title>
|
7 |
+
<style>
|
8 |
+
.loading {
|
9 |
+
display: none !important;
|
10 |
+
}
|
11 |
+
</style>
|
12 |
+
</head>
|
13 |
+
<body style="font-family: 'Source Sans Pro', sans-serif; background-color: #f9fafb; color: #333; display: flex; flex-direction: column; align-items: center; height: 100vh; margin: 0;">
|
14 |
+
|
15 |
+
<div style="width: 100%; max-width: 900px; background: #fff; padding: 1.5rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); flex: 1;">
|
16 |
+
|
17 |
+
<!-- Tabs -->
|
18 |
+
<div style="display: flex; border-bottom: 2px solid #e9ecef; margin-bottom: 1rem;">
|
19 |
+
<button id="singleAudioTab" class="tab active" style="flex: 1; text-align: center; padding: 1rem; background: transparent; border: none; border-bottom: 3px solid #007bff; font-weight: bold; cursor: pointer; color: #007bff;">Single Audio Stream</button>
|
20 |
+
<button id="multistreamTab" class="tab" style="flex: 1; text-align: center; padding: 1rem; background: transparent; border: none; border-bottom: 3px solid transparent; font-weight: bold; cursor: pointer; color: #6c757d;">Multistream Demo</button>
|
21 |
+
</div>
|
22 |
+
|
23 |
+
<!-- Language Selection -->
|
24 |
+
<div style="margin-bottom: 1rem; text-align: center; display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap;">
|
25 |
+
<label style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; border: 1px solid #ced4da; border-radius: 4px; cursor: pointer;">
|
26 |
+
<input type="radio" name="language" value="en" checked style="margin: 0;" />
|
27 |
+
<img src="https://flagcdn.com/us.svg" alt="US Flag" style="width: 20px; height: 14px;" /> English
|
28 |
+
</label>
|
29 |
+
<label style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; border: 1px solid #ced4da; border-radius: 4px; cursor: pointer;">
|
30 |
+
<input type="radio" name="language" value="fr" style="margin: 0;" />
|
31 |
+
<img src="https://flagcdn.com/fr.svg" alt="France Flag" style="width: 20px; height: 14px;" /> French
|
32 |
+
</label>
|
33 |
+
</div>
|
34 |
+
|
35 |
+
<!-- Single Audio Stream Content -->
|
36 |
+
<div id="singleAudioContent" class="tab-content loading">
|
37 |
+
<div style="display: flex; gap: 1.5rem;">
|
38 |
+
<!-- Input Section -->
|
39 |
+
<div style="flex: 1; display: flex; flex-direction: column; gap: 1rem;">
|
40 |
+
<div style="font-size: 1rem; font-weight: bold; padding: 0.5rem 1rem; background-color: #f8f9fa; border-radius: 8px; display: flex; align-items: center; gap: 0.5rem; color: #6c757d;">
|
41 |
+
<span style="line-height: 1;">🎵</span> Input
|
42 |
+
</div>
|
43 |
+
|
44 |
+
<!-- Drag and Drop / File Upload -->
|
45 |
+
<div id="dropzone" style="border: 2px dashed #ced4da; border-radius: 8px; padding: 2rem; text-align: center; color: #6c757d; cursor: pointer; background-color: #f8f9fa; transition: background-color 0.3s, border-color 0.3s; position: relative;">
|
46 |
+
<input type="file" id="fileInput" accept="audio/*" style="position: absolute; top: 0; left: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;" />
|
47 |
+
<p style="margin: 0;">Drop Audio Here<br>- or -<br>Click to Upload</p>
|
48 |
+
</div>
|
49 |
+
|
50 |
+
<!-- Record Microphone Button -->
|
51 |
+
<button id="recordBtn" style="padding: 0.5rem 1rem; border: 1px solid #e9ecef; border-radius: 4px; background-color: #fff; color: #d9534f; cursor: pointer; font-size: 1rem;">
|
52 |
+
<span style="font-size: 0.8rem; border-radius: 50%; background-color: #d9534f; width: 10px; height: 10px; display: inline-block;"></span>
|
53 |
+
Use Microphone
|
54 |
+
</button>
|
55 |
+
</div>
|
56 |
+
|
57 |
+
<!-- Output Section -->
|
58 |
+
<div style="flex: 1; display: flex; flex-direction: column; gap: 1rem;">
|
59 |
+
<div style="font-size: 1rem; font-weight: bold; padding: 0.5rem 1rem; background-color: #f8f9fa; border-radius: 8px; color: #6c757d;">Transcript</div>
|
60 |
+
<textarea id="results" placeholder="Output will appear here..." readonly style="flex: 1; padding: 0.75rem; font-size: 1rem; border: 1px solid #ced4da; border-radius: 8px; resize: none; background-color: #f8f9fa;"></textarea>
|
61 |
+
<audio id="audioPlayback" controls style="display: none; margin-top: 1rem; width: 100%;"></audio>
|
62 |
+
</div>
|
63 |
+
</div>
|
64 |
+
</div>
|
65 |
+
|
66 |
+
<!-- Multistream Demo Content -->
|
67 |
+
<div id="multistreamContent" class="tab-content loading" style="display: none;">
|
68 |
+
<div style="text-align: center; padding: 1rem;">
|
69 |
+
<button id="playAllBtn" style="padding: 0.75rem 1.5rem; background-color: #007bff; color: #fff; border: none; border-radius: 4px; cursor: pointer; font-size: 1rem;">Play All Streams</button>
|
70 |
+
</div>
|
71 |
+
<div style="display: flex; flex-wrap: wrap; gap: 1rem;">
|
72 |
+
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
73 |
+
<audio id="audio1" controls style="width: 100%;"></audio>
|
74 |
+
<textarea id="transcript1" readonly placeholder="Transcript for Audio 1"
|
75 |
+
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
76 |
+
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
77 |
+
</div>
|
78 |
+
|
79 |
+
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
80 |
+
<audio id="audio2" controls style="width: 100%;"></audio>
|
81 |
+
<textarea id="transcript2" readonly placeholder="Transcript for Audio 2"
|
82 |
+
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
83 |
+
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
84 |
+
</div>
|
85 |
+
|
86 |
+
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
87 |
+
<audio id="audio3" controls style="width: 100%;"></audio>
|
88 |
+
<textarea id="transcript3" readonly placeholder="Transcript for Audio 3"
|
89 |
+
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
90 |
+
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
91 |
+
</div>
|
92 |
+
|
93 |
+
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
94 |
+
<audio id="audio4" controls style="width: 100%;"></audio>
|
95 |
+
<textarea id="transcript4" readonly placeholder="Transcript for Audio 4"
|
96 |
+
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
97 |
+
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
98 |
+
</div>
|
99 |
+
|
100 |
+
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
101 |
+
<audio id="audio5" controls style="width: 100%;"></audio>
|
102 |
+
<textarea id="transcript5" readonly placeholder="Transcript for Audio 5"
|
103 |
+
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
104 |
+
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
105 |
+
</div>
|
106 |
+
</div>
|
107 |
+
</div>
|
108 |
+
|
109 |
+
<div id="status">Loading...</div>
|
110 |
+
|
111 |
+
</div>
|
112 |
+
|
113 |
+
<!-- Footer Section -->
|
114 |
+
<div style="width: 100%; max-width: 900px; margin-top: 1.5rem; background: #fff; padding: 1.5rem; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); text-align: left; font-size: 0.9rem; color: #6c757d;">
|
115 |
+
<h3>Model Licensing</h3>
|
116 |
+
<ul>
|
117 |
+
<li><strong>The models in this space are licensed under the Coqui Public license.</strong></li>
|
118 |
+
<li>For commercial licensing, please contact [email protected]</li>
|
119 |
+
<li></li>
|
120 |
+
<li>Pricing examples:</li>
|
121 |
+
<li> - 25$ per year for single user. </li>
|
122 |
+
<li> - 99$ / year for pbx with up to 10 users / extensions. </li>
|
123 |
+
<li> - contact us for your use case</li>
|
124 |
+
</ul>
|
125 |
+
<h3>About This Demo</h3>
|
126 |
+
<ul>
|
127 |
+
<li><strong>Private and Secure:</strong> All processing is done locally on your device (CPU) using your browser. No server is involved, ensuring privacy and security.</li>
|
128 |
+
<li><strong>Efficient Resource Usage:</strong> No GPU is required, leaving system resources available for webLLM analysis.</li>
|
129 |
+
<li><strong>Versatile Audio Handling:</strong> Can simultaneously manage microphone and speaker inputs, making it ideal for webRTC-based call centers or web meetings.</li>
|
130 |
+
</ul>
|
131 |
+
<h3>Latest Update</h3>
|
132 |
+
<ul>
|
133 |
+
<li>Added support for <strong>French (fr-FR)</strong>.</li>
|
134 |
+
</ul>
|
135 |
+
</div>
|
136 |
+
|
137 |
+
<script src="./sherpa-onnx-asr.js"></script>
|
138 |
+
<script src="./app-asr.js"></script>
|
139 |
+
<script src="./model.js"></script>
|
140 |
+
<script src="./sherpa-onnx-wasm-main-asr.js"></script>
|
141 |
+
</body>
|
142 |
+
</html>
|
model.js
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
var Module = typeof Module != 'undefined' ? Module : {};
|
3 |
+
|
4 |
+
Module['expectedDataFileDownloads'] ??= 0;
|
5 |
+
Module['expectedDataFileDownloads']++;
|
6 |
+
(() => {
|
7 |
+
// Do not attempt to redownload the virtual filesystem data when in a pthread or a Wasm Worker context.
|
8 |
+
var isPthread = typeof ENVIRONMENT_IS_PTHREAD != 'undefined' && ENVIRONMENT_IS_PTHREAD;
|
9 |
+
var isWasmWorker = typeof ENVIRONMENT_IS_WASM_WORKER != 'undefined' && ENVIRONMENT_IS_WASM_WORKER;
|
10 |
+
if (isPthread || isWasmWorker) return;
|
11 |
+
var isNode = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
|
12 |
+
function loadPackage(metadata) {
|
13 |
+
|
14 |
+
var PACKAGE_PATH = '';
|
15 |
+
if (typeof window === 'object') {
|
16 |
+
PACKAGE_PATH = window['encodeURIComponent'](window.location.pathname.substring(0, window.location.pathname.lastIndexOf('/')) + '/');
|
17 |
+
} else if (typeof process === 'undefined' && typeof location !== 'undefined') {
|
18 |
+
// web worker
|
19 |
+
PACKAGE_PATH = encodeURIComponent(location.pathname.substring(0, location.pathname.lastIndexOf('/')) + '/');
|
20 |
+
}
|
21 |
+
var PACKAGE_NAME = 'model.data';
|
22 |
+
var REMOTE_PACKAGE_BASE = 'model.data';
|
23 |
+
var REMOTE_PACKAGE_NAME = Module['locateFile'] ? Module['locateFile'](REMOTE_PACKAGE_BASE, '') : REMOTE_PACKAGE_BASE;
|
24 |
+
var REMOTE_PACKAGE_SIZE = metadata['remote_package_size'];
|
25 |
+
|
26 |
+
function fetchRemotePackage(packageName, packageSize, callback, errback) {
|
27 |
+
if (isNode) {
|
28 |
+
require('fs').readFile(packageName, (err, contents) => {
|
29 |
+
if (err) {
|
30 |
+
errback(err);
|
31 |
+
} else {
|
32 |
+
callback(contents.buffer);
|
33 |
+
}
|
34 |
+
});
|
35 |
+
return;
|
36 |
+
}
|
37 |
+
Module['dataFileDownloads'] ??= {};
|
38 |
+
fetch(packageName)
|
39 |
+
.catch((cause) => Promise.reject(new Error(`Network Error: ${packageName}`, {cause}))) // If fetch fails, rewrite the error to include the failing URL & the cause.
|
40 |
+
.then((response) => {
|
41 |
+
if (!response.ok) {
|
42 |
+
return Promise.reject(new Error(`${response.status}: ${response.url}`));
|
43 |
+
}
|
44 |
+
|
45 |
+
if (!response.body && response.arrayBuffer) { // If we're using the polyfill, readers won't be available...
|
46 |
+
return response.arrayBuffer().then(callback);
|
47 |
+
}
|
48 |
+
|
49 |
+
const reader = response.body.getReader();
|
50 |
+
const iterate = () => reader.read().then(handleChunk).catch((cause) => {
|
51 |
+
return Promise.reject(new Error(`Unexpected error while handling : ${response.url} ${cause}`, {cause}));
|
52 |
+
});
|
53 |
+
|
54 |
+
const chunks = [];
|
55 |
+
const headers = response.headers;
|
56 |
+
const total = Number(headers.get('Content-Length') ?? packageSize);
|
57 |
+
let loaded = 0;
|
58 |
+
|
59 |
+
const handleChunk = ({done, value}) => {
|
60 |
+
if (!done) {
|
61 |
+
chunks.push(value);
|
62 |
+
loaded += value.length;
|
63 |
+
Module['dataFileDownloads'][packageName] = {loaded, total};
|
64 |
+
|
65 |
+
let totalLoaded = 0;
|
66 |
+
let totalSize = 0;
|
67 |
+
|
68 |
+
for (const download of Object.values(Module['dataFileDownloads'])) {
|
69 |
+
totalLoaded += download.loaded;
|
70 |
+
totalSize += download.total;
|
71 |
+
}
|
72 |
+
|
73 |
+
Module['setStatus']?.(`Downloading data... (${totalLoaded}/${totalSize})`);
|
74 |
+
return iterate();
|
75 |
+
} else {
|
76 |
+
const packageData = new Uint8Array(chunks.map((c) => c.length).reduce((a, b) => a + b, 0));
|
77 |
+
let offset = 0;
|
78 |
+
for (const chunk of chunks) {
|
79 |
+
packageData.set(chunk, offset);
|
80 |
+
offset += chunk.length;
|
81 |
+
}
|
82 |
+
callback(packageData.buffer);
|
83 |
+
}
|
84 |
+
};
|
85 |
+
|
86 |
+
Module['setStatus']?.('Downloading data...');
|
87 |
+
return iterate();
|
88 |
+
});
|
89 |
+
};
|
90 |
+
|
91 |
+
function handleError(error) {
|
92 |
+
console.error('package error:', error);
|
93 |
+
};
|
94 |
+
|
95 |
+
var fetchedCallback = null;
|
96 |
+
var fetched = Module['getPreloadedPackage'] ? Module['getPreloadedPackage'](REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE) : null;
|
97 |
+
|
98 |
+
if (!fetched) fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, (data) => {
|
99 |
+
if (fetchedCallback) {
|
100 |
+
fetchedCallback(data);
|
101 |
+
fetchedCallback = null;
|
102 |
+
} else {
|
103 |
+
fetched = data;
|
104 |
+
}
|
105 |
+
}, handleError);
|
106 |
+
|
107 |
+
function runWithFS(Module) {
|
108 |
+
|
109 |
+
function assert(check, msg) {
|
110 |
+
if (!check) throw msg + new Error().stack;
|
111 |
+
}
|
112 |
+
|
113 |
+
/** @constructor */
|
114 |
+
function DataRequest(start, end, audio) {
|
115 |
+
this.start = start;
|
116 |
+
this.end = end;
|
117 |
+
this.audio = audio;
|
118 |
+
}
|
119 |
+
DataRequest.prototype = {
|
120 |
+
requests: {},
|
121 |
+
open: function(mode, name) {
|
122 |
+
this.name = name;
|
123 |
+
this.requests[name] = this;
|
124 |
+
Module['addRunDependency'](`fp ${this.name}`);
|
125 |
+
},
|
126 |
+
send: function() {},
|
127 |
+
onload: function() {
|
128 |
+
var byteArray = this.byteArray.subarray(this.start, this.end);
|
129 |
+
this.finish(byteArray);
|
130 |
+
},
|
131 |
+
finish: function(byteArray) {
|
132 |
+
var that = this;
|
133 |
+
// canOwn this data in the filesystem, it is a slide into the heap that will never change
|
134 |
+
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
|
135 |
+
Module['removeRunDependency'](`fp ${that.name}`);
|
136 |
+
this.requests[this.name] = null;
|
137 |
+
}
|
138 |
+
};
|
139 |
+
|
140 |
+
var files = metadata['files'];
|
141 |
+
for (var i = 0; i < files.length; ++i) {
|
142 |
+
new DataRequest(files[i]['start'], files[i]['end'], files[i]['audio'] || 0).open('GET', files[i]['filename']);
|
143 |
+
}
|
144 |
+
|
145 |
+
function processPackageData(arrayBuffer) {
|
146 |
+
assert(arrayBuffer, 'Loading data file failed.');
|
147 |
+
assert(arrayBuffer.constructor.name === ArrayBuffer.name, 'bad input to processPackageData');
|
148 |
+
var byteArray = new Uint8Array(arrayBuffer);
|
149 |
+
var curr;
|
150 |
+
// Reuse the bytearray from the XHR as the source for file reads.
|
151 |
+
DataRequest.prototype.byteArray = byteArray;
|
152 |
+
var files = metadata['files'];
|
153 |
+
for (var i = 0; i < files.length; ++i) {
|
154 |
+
DataRequest.prototype.requests[files[i].filename].onload();
|
155 |
+
} Module['removeRunDependency']('datafile_model.data');
|
156 |
+
|
157 |
+
};
|
158 |
+
Module['addRunDependency']('datafile_model.data');
|
159 |
+
|
160 |
+
Module['preloadResults'] ??= {};
|
161 |
+
|
162 |
+
Module['preloadResults'][PACKAGE_NAME] = {fromCache: false};
|
163 |
+
if (fetched) {
|
164 |
+
processPackageData(fetched);
|
165 |
+
fetched = null;
|
166 |
+
} else {
|
167 |
+
fetchedCallback = processPackageData;
|
168 |
+
}
|
169 |
+
|
170 |
+
}
|
171 |
+
if (Module['calledRun']) {
|
172 |
+
runWithFS(Module);
|
173 |
+
} else {
|
174 |
+
(Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it
|
175 |
+
}
|
176 |
+
|
177 |
+
Module['removeRunDependency']('model.js.metadata');
|
178 |
+
}
|
179 |
+
|
180 |
+
function runMetaWithFS() {
|
181 |
+
Module['addRunDependency']('model.js.metadata');
|
182 |
+
var metadataUrl = Module['locateFile'] ? Module['locateFile']('model.js.metadata', '') : 'model.js.metadata';
|
183 |
+
if (isNode) {
|
184 |
+
require('fs').readFile(metadataUrl, 'utf8', (err, contents) => {
|
185 |
+
if (err) {
|
186 |
+
return Promise.reject(err);
|
187 |
+
} else {
|
188 |
+
loadPackage(JSON.parse(contents));
|
189 |
+
}
|
190 |
+
});
|
191 |
+
return;
|
192 |
+
}
|
193 |
+
fetch(metadataUrl)
|
194 |
+
.then((response) => {
|
195 |
+
if (response.ok) {
|
196 |
+
return response.json();
|
197 |
+
}
|
198 |
+
return Promise.reject(new Error(`${response.status}: ${response.url}`));
|
199 |
+
})
|
200 |
+
.then(loadPackage);
|
201 |
+
}
|
202 |
+
|
203 |
+
if (Module['calledRun']) {
|
204 |
+
runMetaWithFS();
|
205 |
+
} else {
|
206 |
+
(Module['preRun'] ??= []).push(runMetaWithFS);
|
207 |
+
}
|
208 |
+
|
209 |
+
})();
|
sherpa-onnx-asr.js
ADDED
@@ -0,0 +1,1030 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
function freeConfig(config, Module) {
|
2 |
+
if ('buffer' in config) {
|
3 |
+
Module._free(config.buffer);
|
4 |
+
}
|
5 |
+
|
6 |
+
if ('config' in config) {
|
7 |
+
freeConfig(config.config, Module)
|
8 |
+
}
|
9 |
+
|
10 |
+
if ('transducer' in config) {
|
11 |
+
freeConfig(config.transducer, Module)
|
12 |
+
}
|
13 |
+
|
14 |
+
if ('paraformer' in config) {
|
15 |
+
freeConfig(config.paraformer, Module)
|
16 |
+
}
|
17 |
+
|
18 |
+
if ('ctc' in config) {
|
19 |
+
freeConfig(config.ctc, Module)
|
20 |
+
}
|
21 |
+
|
22 |
+
if ('feat' in config) {
|
23 |
+
freeConfig(config.feat, Module)
|
24 |
+
}
|
25 |
+
|
26 |
+
if ('model' in config) {
|
27 |
+
freeConfig(config.model, Module)
|
28 |
+
}
|
29 |
+
|
30 |
+
if ('nemoCtc' in config) {
|
31 |
+
freeConfig(config.nemoCtc, Module)
|
32 |
+
}
|
33 |
+
|
34 |
+
if ('whisper' in config) {
|
35 |
+
freeConfig(config.whisper, Module)
|
36 |
+
}
|
37 |
+
|
38 |
+
if ('tdnn' in config) {
|
39 |
+
freeConfig(config.tdnn, Module)
|
40 |
+
}
|
41 |
+
|
42 |
+
if ('senseVoice' in config) {
|
43 |
+
freeConfig(config.senseVoice, Module)
|
44 |
+
}
|
45 |
+
|
46 |
+
if ('lm' in config) {
|
47 |
+
freeConfig(config.lm, Module)
|
48 |
+
}
|
49 |
+
|
50 |
+
if ('ctcFstDecoder' in config) {
|
51 |
+
freeConfig(config.ctcFstDecoder, Module)
|
52 |
+
}
|
53 |
+
|
54 |
+
Module._free(config.ptr);
|
55 |
+
}
|
56 |
+
|
57 |
+
// The user should free the returned pointers
|
58 |
+
function initSherpaOnnxOnlineTransducerModelConfig(config, Module) {
|
59 |
+
const encoderLen = Module.lengthBytesUTF8(config.encoder || '') + 1;
|
60 |
+
const decoderLen = Module.lengthBytesUTF8(config.decoder || '') + 1;
|
61 |
+
const joinerLen = Module.lengthBytesUTF8(config.joiner || '') + 1;
|
62 |
+
|
63 |
+
const n = encoderLen + decoderLen + joinerLen;
|
64 |
+
|
65 |
+
const buffer = Module._malloc(n);
|
66 |
+
|
67 |
+
const len = 3 * 4; // 3 pointers
|
68 |
+
const ptr = Module._malloc(len);
|
69 |
+
|
70 |
+
let offset = 0;
|
71 |
+
Module.stringToUTF8(config.encoder || '', buffer + offset, encoderLen);
|
72 |
+
offset += encoderLen;
|
73 |
+
|
74 |
+
Module.stringToUTF8(config.decoder || '', buffer + offset, decoderLen);
|
75 |
+
offset += decoderLen;
|
76 |
+
|
77 |
+
Module.stringToUTF8(config.joiner || '', buffer + offset, joinerLen);
|
78 |
+
|
79 |
+
offset = 0;
|
80 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
81 |
+
offset += encoderLen;
|
82 |
+
|
83 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
84 |
+
offset += decoderLen;
|
85 |
+
|
86 |
+
Module.setValue(ptr + 8, buffer + offset, 'i8*');
|
87 |
+
|
88 |
+
return {
|
89 |
+
buffer: buffer, ptr: ptr, len: len,
|
90 |
+
}
|
91 |
+
}
|
92 |
+
|
93 |
+
function initSherpaOnnxOnlineParaformerModelConfig(config, Module) {
|
94 |
+
const encoderLen = Module.lengthBytesUTF8(config.encoder || '') + 1;
|
95 |
+
const decoderLen = Module.lengthBytesUTF8(config.decoder || '') + 1;
|
96 |
+
|
97 |
+
const n = encoderLen + decoderLen;
|
98 |
+
const buffer = Module._malloc(n);
|
99 |
+
|
100 |
+
const len = 2 * 4; // 2 pointers
|
101 |
+
const ptr = Module._malloc(len);
|
102 |
+
|
103 |
+
let offset = 0;
|
104 |
+
Module.stringToUTF8(config.encoder || '', buffer + offset, encoderLen);
|
105 |
+
offset += encoderLen;
|
106 |
+
|
107 |
+
Module.stringToUTF8(config.decoder || '', buffer + offset, decoderLen);
|
108 |
+
|
109 |
+
offset = 0;
|
110 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
111 |
+
offset += encoderLen;
|
112 |
+
|
113 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
114 |
+
|
115 |
+
return {
|
116 |
+
buffer: buffer, ptr: ptr, len: len,
|
117 |
+
}
|
118 |
+
}
|
119 |
+
|
120 |
+
function initSherpaOnnxOnlineZipformer2CtcModelConfig(config, Module) {
|
121 |
+
const n = Module.lengthBytesUTF8(config.model || '') + 1;
|
122 |
+
const buffer = Module._malloc(n);
|
123 |
+
|
124 |
+
const len = 1 * 4; // 1 pointer
|
125 |
+
const ptr = Module._malloc(len);
|
126 |
+
|
127 |
+
Module.stringToUTF8(config.model || '', buffer, n);
|
128 |
+
|
129 |
+
Module.setValue(ptr, buffer, 'i8*');
|
130 |
+
|
131 |
+
return {
|
132 |
+
buffer: buffer, ptr: ptr, len: len,
|
133 |
+
}
|
134 |
+
}
|
135 |
+
|
136 |
+
function initSherpaOnnxOnlineModelConfig(config, Module) {
|
137 |
+
if (!('transducer' in config)) {
|
138 |
+
config.transducer = {
|
139 |
+
encoder: '',
|
140 |
+
decoder: '',
|
141 |
+
joiner: '',
|
142 |
+
};
|
143 |
+
}
|
144 |
+
|
145 |
+
if (!('paraformer' in config)) {
|
146 |
+
config.paraformer = {
|
147 |
+
encoder: '',
|
148 |
+
decoder: '',
|
149 |
+
};
|
150 |
+
}
|
151 |
+
|
152 |
+
if (!('zipformer2Ctc' in config)) {
|
153 |
+
config.zipformer2Ctc = {
|
154 |
+
model: '',
|
155 |
+
};
|
156 |
+
}
|
157 |
+
|
158 |
+
const transducer =
|
159 |
+
initSherpaOnnxOnlineTransducerModelConfig(config.transducer, Module);
|
160 |
+
|
161 |
+
const paraformer =
|
162 |
+
initSherpaOnnxOnlineParaformerModelConfig(config.paraformer, Module);
|
163 |
+
|
164 |
+
const ctc = initSherpaOnnxOnlineZipformer2CtcModelConfig(
|
165 |
+
config.zipformer2Ctc, Module);
|
166 |
+
|
167 |
+
const len = transducer.len + paraformer.len + ctc.len + 7 * 4;
|
168 |
+
const ptr = Module._malloc(len);
|
169 |
+
|
170 |
+
let offset = 0;
|
171 |
+
Module._CopyHeap(transducer.ptr, transducer.len, ptr + offset);
|
172 |
+
offset += transducer.len;
|
173 |
+
|
174 |
+
Module._CopyHeap(paraformer.ptr, paraformer.len, ptr + offset);
|
175 |
+
offset += paraformer.len;
|
176 |
+
|
177 |
+
Module._CopyHeap(ctc.ptr, ctc.len, ptr + offset);
|
178 |
+
offset += ctc.len;
|
179 |
+
|
180 |
+
const tokensLen = Module.lengthBytesUTF8(config.tokens || '') + 1;
|
181 |
+
const providerLen = Module.lengthBytesUTF8(config.provider || 'cpu') + 1;
|
182 |
+
const modelTypeLen = Module.lengthBytesUTF8(config.modelType || '') + 1;
|
183 |
+
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
184 |
+
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
185 |
+
|
186 |
+
const bufferLen =
|
187 |
+
tokensLen + providerLen + modelTypeLen + modelingUnitLen + bpeVocabLen;
|
188 |
+
const buffer = Module._malloc(bufferLen);
|
189 |
+
|
190 |
+
offset = 0;
|
191 |
+
Module.stringToUTF8(config.tokens || '', buffer, tokensLen);
|
192 |
+
offset += tokensLen;
|
193 |
+
|
194 |
+
Module.stringToUTF8(config.provider || 'cpu', buffer + offset, providerLen);
|
195 |
+
offset += providerLen;
|
196 |
+
|
197 |
+
Module.stringToUTF8(config.modelType || '', buffer + offset, modelTypeLen);
|
198 |
+
offset += modelTypeLen;
|
199 |
+
|
200 |
+
Module.stringToUTF8(
|
201 |
+
config.modelingUnit || '', buffer + offset, modelingUnitLen);
|
202 |
+
offset += modelingUnitLen;
|
203 |
+
|
204 |
+
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
205 |
+
offset += bpeVocabLen;
|
206 |
+
|
207 |
+
offset = transducer.len + paraformer.len + ctc.len;
|
208 |
+
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
209 |
+
offset += 4;
|
210 |
+
|
211 |
+
Module.setValue(ptr + offset, config.numThreads || 1, 'i32');
|
212 |
+
offset += 4;
|
213 |
+
|
214 |
+
Module.setValue(ptr + offset, buffer + tokensLen, 'i8*'); // provider
|
215 |
+
offset += 4;
|
216 |
+
|
217 |
+
Module.setValue(ptr + offset, config.debug || 0, 'i32');
|
218 |
+
offset += 4;
|
219 |
+
|
220 |
+
Module.setValue(
|
221 |
+
ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType
|
222 |
+
offset += 4;
|
223 |
+
|
224 |
+
Module.setValue(
|
225 |
+
ptr + offset, buffer + tokensLen + providerLen + modelTypeLen,
|
226 |
+
'i8*'); // modelingUnit
|
227 |
+
offset += 4;
|
228 |
+
|
229 |
+
Module.setValue(
|
230 |
+
ptr + offset,
|
231 |
+
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen,
|
232 |
+
'i8*'); // bpeVocab
|
233 |
+
offset += 4;
|
234 |
+
|
235 |
+
return {
|
236 |
+
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
237 |
+
paraformer: paraformer, ctc: ctc
|
238 |
+
}
|
239 |
+
}
|
240 |
+
|
241 |
+
function initSherpaOnnxFeatureConfig(config, Module) {
|
242 |
+
const len = 2 * 4; // 2 pointers
|
243 |
+
const ptr = Module._malloc(len);
|
244 |
+
|
245 |
+
Module.setValue(ptr, config.sampleRate || 16000, 'i32');
|
246 |
+
Module.setValue(ptr + 4, config.featureDim || 80, 'i32');
|
247 |
+
return {ptr: ptr, len: len};
|
248 |
+
}
|
249 |
+
|
250 |
+
function initSherpaOnnxOnlineCtcFstDecoderConfig(config, Module) {
|
251 |
+
const len = 2 * 4;
|
252 |
+
const ptr = Module._malloc(len);
|
253 |
+
|
254 |
+
const graphLen = Module.lengthBytesUTF8(config.graph || '') + 1;
|
255 |
+
const buffer = Module._malloc(graphLen);
|
256 |
+
Module.stringToUTF8(config.graph, buffer, graphLen);
|
257 |
+
|
258 |
+
Module.setValue(ptr, buffer, 'i8*');
|
259 |
+
Module.setValue(ptr + 4, config.maxActive || 3000, 'i32');
|
260 |
+
return {ptr: ptr, len: len, buffer: buffer};
|
261 |
+
}
|
262 |
+
|
263 |
+
function initSherpaOnnxOnlineRecognizerConfig(config, Module) {
|
264 |
+
if (!('featConfig' in config)) {
|
265 |
+
config.featConfig = {
|
266 |
+
sampleRate: 16000,
|
267 |
+
featureDim: 80,
|
268 |
+
};
|
269 |
+
}
|
270 |
+
|
271 |
+
if (!('ctcFstDecoderConfig' in config)) {
|
272 |
+
config.ctcFstDecoderConfig = {
|
273 |
+
graph: '',
|
274 |
+
maxActive: 3000,
|
275 |
+
};
|
276 |
+
}
|
277 |
+
|
278 |
+
const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
|
279 |
+
const model = initSherpaOnnxOnlineModelConfig(config.modelConfig, Module);
|
280 |
+
const ctcFstDecoder = initSherpaOnnxOnlineCtcFstDecoderConfig(
|
281 |
+
config.ctcFstDecoderConfig, Module)
|
282 |
+
|
283 |
+
const len = feat.len + model.len + 8 * 4 + ctcFstDecoder.len + 3 * 4;
|
284 |
+
const ptr = Module._malloc(len);
|
285 |
+
|
286 |
+
let offset = 0;
|
287 |
+
Module._CopyHeap(feat.ptr, feat.len, ptr + offset);
|
288 |
+
offset += feat.len;
|
289 |
+
|
290 |
+
Module._CopyHeap(model.ptr, model.len, ptr + offset);
|
291 |
+
offset += model.len;
|
292 |
+
|
293 |
+
const decodingMethodLen =
|
294 |
+
Module.lengthBytesUTF8(config.decodingMethod || 'greedy_search') + 1;
|
295 |
+
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile || '') + 1;
|
296 |
+
const ruleFstsFileLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
|
297 |
+
const ruleFarsFileLen = Module.lengthBytesUTF8(config.ruleFars || '') + 1;
|
298 |
+
const bufferLen =
|
299 |
+
decodingMethodLen + hotwordsFileLen + ruleFstsFileLen + ruleFarsFileLen;
|
300 |
+
const buffer = Module._malloc(bufferLen);
|
301 |
+
|
302 |
+
offset = 0;
|
303 |
+
Module.stringToUTF8(
|
304 |
+
config.decodingMethod || 'greedy_search', buffer, decodingMethodLen);
|
305 |
+
offset += decodingMethodLen;
|
306 |
+
|
307 |
+
Module.stringToUTF8(
|
308 |
+
config.hotwordsFile || '', buffer + offset, hotwordsFileLen);
|
309 |
+
offset += hotwordsFileLen;
|
310 |
+
|
311 |
+
Module.stringToUTF8(config.ruleFsts || '', buffer + offset, ruleFstsFileLen);
|
312 |
+
offset += ruleFstsFileLen;
|
313 |
+
|
314 |
+
Module.stringToUTF8(config.ruleFars || '', buffer + offset, ruleFarsFileLen);
|
315 |
+
offset += ruleFarsFileLen;
|
316 |
+
|
317 |
+
offset = feat.len + model.len;
|
318 |
+
Module.setValue(ptr + offset, buffer, 'i8*'); // decoding method
|
319 |
+
offset += 4;
|
320 |
+
|
321 |
+
Module.setValue(ptr + offset, config.maxActivePaths || 4, 'i32');
|
322 |
+
offset += 4;
|
323 |
+
|
324 |
+
Module.setValue(ptr + offset, config.enableEndpoint || 0, 'i32');
|
325 |
+
offset += 4;
|
326 |
+
|
327 |
+
Module.setValue(ptr + offset, config.rule1MinTrailingSilence || 2.4, 'float');
|
328 |
+
offset += 4;
|
329 |
+
|
330 |
+
Module.setValue(ptr + offset, config.rule2MinTrailingSilence || 1.2, 'float');
|
331 |
+
offset += 4;
|
332 |
+
|
333 |
+
Module.setValue(ptr + offset, config.rule3MinUtteranceLength || 20, 'float');
|
334 |
+
offset += 4;
|
335 |
+
|
336 |
+
Module.setValue(ptr + offset, buffer + decodingMethodLen, 'i8*');
|
337 |
+
offset += 4;
|
338 |
+
|
339 |
+
Module.setValue(ptr + offset, config.hotwordsScore || 1.5, 'float');
|
340 |
+
offset += 4;
|
341 |
+
|
342 |
+
Module._CopyHeap(ctcFstDecoder.ptr, ctcFstDecoder.len, ptr + offset);
|
343 |
+
offset += ctcFstDecoder.len;
|
344 |
+
|
345 |
+
Module.setValue(
|
346 |
+
ptr + offset, buffer + decodingMethodLen + hotwordsFileLen, 'i8*');
|
347 |
+
offset += 4;
|
348 |
+
|
349 |
+
Module.setValue(
|
350 |
+
ptr + offset,
|
351 |
+
buffer + decodingMethodLen + hotwordsFileLen + ruleFstsFileLen, 'i8*');
|
352 |
+
offset += 4;
|
353 |
+
|
354 |
+
Module.setValue(ptr + offset, config.blankPenalty || 0, 'float');
|
355 |
+
offset += 4;
|
356 |
+
|
357 |
+
return {
|
358 |
+
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model,
|
359 |
+
ctcFstDecoder: ctcFstDecoder
|
360 |
+
}
|
361 |
+
}
|
362 |
+
|
363 |
+
function createOnlineRecognizer(Module, myConfig) {
|
364 |
+
const onlineTransducerModelConfig = {
|
365 |
+
encoder: '',
|
366 |
+
decoder: '',
|
367 |
+
joiner: '',
|
368 |
+
};
|
369 |
+
|
370 |
+
const onlineParaformerModelConfig = {
|
371 |
+
encoder: '',
|
372 |
+
decoder: '',
|
373 |
+
};
|
374 |
+
|
375 |
+
const onlineZipformer2CtcModelConfig = {
|
376 |
+
model: '',
|
377 |
+
};
|
378 |
+
|
379 |
+
let type = 0;
|
380 |
+
|
381 |
+
switch (type) {
|
382 |
+
case 0:
|
383 |
+
// transducer
|
384 |
+
onlineTransducerModelConfig.encoder = './encoder.onnx';
|
385 |
+
onlineTransducerModelConfig.decoder = './decoder.onnx';
|
386 |
+
onlineTransducerModelConfig.joiner = './joiner.onnx';
|
387 |
+
break;
|
388 |
+
case 1:
|
389 |
+
// paraformer
|
390 |
+
onlineParaformerModelConfig.encoder = './encoder.onnx';
|
391 |
+
onlineParaformerModelConfig.decoder = './decoder.onnx';
|
392 |
+
break;
|
393 |
+
case 2:
|
394 |
+
// ctc
|
395 |
+
onlineZipformer2CtcModelConfig.model = './encoder.onnx';
|
396 |
+
break;
|
397 |
+
}
|
398 |
+
|
399 |
+
|
400 |
+
const onlineModelConfig = {
|
401 |
+
transducer: onlineTransducerModelConfig,
|
402 |
+
paraformer: onlineParaformerModelConfig,
|
403 |
+
zipformer2Ctc: onlineZipformer2CtcModelConfig,
|
404 |
+
tokens: './tokens.txt',
|
405 |
+
numThreads: 1,
|
406 |
+
provider: 'cpu',
|
407 |
+
debug: 1,
|
408 |
+
modelType: '',
|
409 |
+
modelingUnit: 'cjkchar',
|
410 |
+
bpeVocab: '',
|
411 |
+
};
|
412 |
+
|
413 |
+
const featureConfig = {
|
414 |
+
sampleRate: 16000,
|
415 |
+
featureDim: 80,
|
416 |
+
};
|
417 |
+
|
418 |
+
let recognizerConfig = {
|
419 |
+
featConfig: featureConfig,
|
420 |
+
modelConfig: onlineModelConfig,
|
421 |
+
decodingMethod: 'greedy_search',
|
422 |
+
maxActivePaths: 4,
|
423 |
+
enableEndpoint: 1,
|
424 |
+
rule1MinTrailingSilence: 2.4,
|
425 |
+
rule2MinTrailingSilence: 1.2,
|
426 |
+
rule3MinUtteranceLength: 20,
|
427 |
+
hotwordsFile: '',
|
428 |
+
hotwordsScore: 1.5,
|
429 |
+
ctcFstDecoderConfig: {
|
430 |
+
graph: '',
|
431 |
+
maxActive: 3000,
|
432 |
+
},
|
433 |
+
ruleFsts: '',
|
434 |
+
ruleFars: '',
|
435 |
+
};
|
436 |
+
if (myConfig) {
|
437 |
+
recognizerConfig = myConfig;
|
438 |
+
}
|
439 |
+
|
440 |
+
return new OnlineRecognizer(recognizerConfig, Module);
|
441 |
+
}
|
442 |
+
|
443 |
+
function initSherpaOnnxOfflineTransducerModelConfig(config, Module) {
|
444 |
+
const encoderLen = Module.lengthBytesUTF8(config.encoder || '') + 1;
|
445 |
+
const decoderLen = Module.lengthBytesUTF8(config.decoder || '') + 1;
|
446 |
+
const joinerLen = Module.lengthBytesUTF8(config.joiner || '') + 1;
|
447 |
+
|
448 |
+
const n = encoderLen + decoderLen + joinerLen;
|
449 |
+
|
450 |
+
const buffer = Module._malloc(n);
|
451 |
+
|
452 |
+
const len = 3 * 4; // 3 pointers
|
453 |
+
const ptr = Module._malloc(len);
|
454 |
+
|
455 |
+
let offset = 0;
|
456 |
+
Module.stringToUTF8(config.encoder || '', buffer + offset, encoderLen);
|
457 |
+
offset += encoderLen;
|
458 |
+
|
459 |
+
Module.stringToUTF8(config.decoder || '', buffer + offset, decoderLen);
|
460 |
+
offset += decoderLen;
|
461 |
+
|
462 |
+
Module.stringToUTF8(config.joiner || '', buffer + offset, joinerLen);
|
463 |
+
|
464 |
+
offset = 0;
|
465 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
466 |
+
offset += encoderLen;
|
467 |
+
|
468 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
469 |
+
offset += decoderLen;
|
470 |
+
|
471 |
+
Module.setValue(ptr + 8, buffer + offset, 'i8*');
|
472 |
+
|
473 |
+
return {
|
474 |
+
buffer: buffer, ptr: ptr, len: len,
|
475 |
+
}
|
476 |
+
}
|
477 |
+
|
478 |
+
function initSherpaOnnxOfflineParaformerModelConfig(config, Module) {
|
479 |
+
const n = Module.lengthBytesUTF8(config.model || '') + 1;
|
480 |
+
|
481 |
+
const buffer = Module._malloc(n);
|
482 |
+
|
483 |
+
const len = 1 * 4; // 1 pointer
|
484 |
+
const ptr = Module._malloc(len);
|
485 |
+
|
486 |
+
Module.stringToUTF8(config.model || '', buffer, n);
|
487 |
+
|
488 |
+
Module.setValue(ptr, buffer, 'i8*');
|
489 |
+
|
490 |
+
return {
|
491 |
+
buffer: buffer, ptr: ptr, len: len,
|
492 |
+
}
|
493 |
+
}
|
494 |
+
|
495 |
+
function initSherpaOnnxOfflineNemoEncDecCtcModelConfig(config, Module) {
|
496 |
+
const n = Module.lengthBytesUTF8(config.model || '') + 1;
|
497 |
+
|
498 |
+
const buffer = Module._malloc(n);
|
499 |
+
|
500 |
+
const len = 1 * 4; // 1 pointer
|
501 |
+
const ptr = Module._malloc(len);
|
502 |
+
|
503 |
+
Module.stringToUTF8(config.model || '', buffer, n);
|
504 |
+
|
505 |
+
Module.setValue(ptr, buffer, 'i8*');
|
506 |
+
|
507 |
+
return {
|
508 |
+
buffer: buffer, ptr: ptr, len: len,
|
509 |
+
}
|
510 |
+
}
|
511 |
+
|
512 |
+
function initSherpaOnnxOfflineWhisperModelConfig(config, Module) {
|
513 |
+
const encoderLen = Module.lengthBytesUTF8(config.encoder || '') + 1;
|
514 |
+
const decoderLen = Module.lengthBytesUTF8(config.decoder || '') + 1;
|
515 |
+
const languageLen = Module.lengthBytesUTF8(config.language || '') + 1;
|
516 |
+
const taskLen = Module.lengthBytesUTF8(config.task || '') + 1;
|
517 |
+
|
518 |
+
const n = encoderLen + decoderLen + languageLen + taskLen;
|
519 |
+
const buffer = Module._malloc(n);
|
520 |
+
|
521 |
+
const len = 5 * 4; // 4 pointers
|
522 |
+
const ptr = Module._malloc(len);
|
523 |
+
|
524 |
+
let offset = 0;
|
525 |
+
Module.stringToUTF8(config.encoder || '', buffer + offset, encoderLen);
|
526 |
+
offset += encoderLen;
|
527 |
+
|
528 |
+
Module.stringToUTF8(config.decoder || '', buffer + offset, decoderLen);
|
529 |
+
offset += decoderLen;
|
530 |
+
|
531 |
+
Module.stringToUTF8(config.language || '', buffer + offset, languageLen);
|
532 |
+
offset += languageLen;
|
533 |
+
|
534 |
+
Module.stringToUTF8(config.task || '', buffer + offset, taskLen);
|
535 |
+
|
536 |
+
offset = 0;
|
537 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
538 |
+
offset += encoderLen;
|
539 |
+
|
540 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
541 |
+
offset += decoderLen;
|
542 |
+
|
543 |
+
Module.setValue(ptr + 8, buffer + offset, 'i8*');
|
544 |
+
offset += languageLen;
|
545 |
+
|
546 |
+
Module.setValue(ptr + 12, buffer + offset, 'i8*');
|
547 |
+
offset += taskLen;
|
548 |
+
|
549 |
+
Module.setValue(ptr + 16, config.tailPaddings || 2000, 'i32');
|
550 |
+
|
551 |
+
return {
|
552 |
+
buffer: buffer, ptr: ptr, len: len,
|
553 |
+
}
|
554 |
+
}
|
555 |
+
|
556 |
+
function initSherpaOnnxOfflineTdnnModelConfig(config, Module) {
|
557 |
+
const n = Module.lengthBytesUTF8(config.model || '') + 1;
|
558 |
+
const buffer = Module._malloc(n);
|
559 |
+
|
560 |
+
const len = 1 * 4; // 1 pointer
|
561 |
+
const ptr = Module._malloc(len);
|
562 |
+
|
563 |
+
Module.stringToUTF8(config.model || '', buffer, n);
|
564 |
+
|
565 |
+
Module.setValue(ptr, buffer, 'i8*');
|
566 |
+
|
567 |
+
return {
|
568 |
+
buffer: buffer, ptr: ptr, len: len,
|
569 |
+
}
|
570 |
+
}
|
571 |
+
|
572 |
+
function initSherpaOnnxOfflineSenseVoiceModelConfig(config, Module) {
|
573 |
+
const modelLen = Module.lengthBytesUTF8(config.model || '') + 1;
|
574 |
+
const languageLen = Module.lengthBytesUTF8(config.language || '') + 1;
|
575 |
+
|
576 |
+
// useItn is a integer with 4 bytes
|
577 |
+
const n = modelLen + languageLen;
|
578 |
+
const buffer = Module._malloc(n);
|
579 |
+
|
580 |
+
const len = 3 * 4; // 2 pointers + 1 int
|
581 |
+
const ptr = Module._malloc(len);
|
582 |
+
|
583 |
+
let offset = 0;
|
584 |
+
Module.stringToUTF8(config.model || '', buffer + offset, modelLen);
|
585 |
+
offset += modelLen;
|
586 |
+
|
587 |
+
Module.stringToUTF8(config.language || '', buffer + offset, languageLen);
|
588 |
+
offset += languageLen;
|
589 |
+
|
590 |
+
offset = 0;
|
591 |
+
Module.setValue(ptr, buffer + offset, 'i8*');
|
592 |
+
offset += modelLen;
|
593 |
+
|
594 |
+
Module.setValue(ptr + 4, buffer + offset, 'i8*');
|
595 |
+
offset += languageLen;
|
596 |
+
|
597 |
+
Module.setValue(ptr + 8, config.useInverseTextNormalization || 0, 'i32');
|
598 |
+
|
599 |
+
return {
|
600 |
+
buffer: buffer, ptr: ptr, len: len,
|
601 |
+
}
|
602 |
+
}
|
603 |
+
|
604 |
+
function initSherpaOnnxOfflineLMConfig(config, Module) {
|
605 |
+
const n = Module.lengthBytesUTF8(config.model || '') + 1;
|
606 |
+
const buffer = Module._malloc(n);
|
607 |
+
|
608 |
+
const len = 2 * 4;
|
609 |
+
const ptr = Module._malloc(len);
|
610 |
+
|
611 |
+
Module.stringToUTF8(config.model || '', buffer, n);
|
612 |
+
Module.setValue(ptr, buffer, 'i8*');
|
613 |
+
Module.setValue(ptr + 4, config.scale || 1, 'float');
|
614 |
+
|
615 |
+
return {
|
616 |
+
buffer: buffer, ptr: ptr, len: len,
|
617 |
+
}
|
618 |
+
}
|
619 |
+
|
620 |
+
function initSherpaOnnxOfflineModelConfig(config, Module) {
|
621 |
+
if (!('transducer' in config)) {
|
622 |
+
config.transducer = {
|
623 |
+
encoder: '',
|
624 |
+
decoder: '',
|
625 |
+
joiner: '',
|
626 |
+
};
|
627 |
+
}
|
628 |
+
|
629 |
+
if (!('paraformer' in config)) {
|
630 |
+
config.paraformer = {
|
631 |
+
model: '',
|
632 |
+
};
|
633 |
+
}
|
634 |
+
|
635 |
+
if (!('nemoCtc' in config)) {
|
636 |
+
config.nemoCtc = {
|
637 |
+
model: '',
|
638 |
+
};
|
639 |
+
}
|
640 |
+
|
641 |
+
if (!('whisper' in config)) {
|
642 |
+
config.whisper = {
|
643 |
+
encoder: '',
|
644 |
+
decoder: '',
|
645 |
+
language: '',
|
646 |
+
task: '',
|
647 |
+
tailPaddings: -1,
|
648 |
+
};
|
649 |
+
}
|
650 |
+
|
651 |
+
if (!('tdnn' in config)) {
|
652 |
+
config.tdnn = {
|
653 |
+
model: '',
|
654 |
+
};
|
655 |
+
}
|
656 |
+
|
657 |
+
if (!('senseVoice' in config)) {
|
658 |
+
config.senseVoice = {
|
659 |
+
model: '',
|
660 |
+
language: '',
|
661 |
+
useInverseTextNormalization: 0,
|
662 |
+
};
|
663 |
+
}
|
664 |
+
|
665 |
+
const transducer =
|
666 |
+
initSherpaOnnxOfflineTransducerModelConfig(config.transducer, Module);
|
667 |
+
|
668 |
+
const paraformer =
|
669 |
+
initSherpaOnnxOfflineParaformerModelConfig(config.paraformer, Module);
|
670 |
+
|
671 |
+
const nemoCtc =
|
672 |
+
initSherpaOnnxOfflineNemoEncDecCtcModelConfig(config.nemoCtc, Module);
|
673 |
+
|
674 |
+
const whisper =
|
675 |
+
initSherpaOnnxOfflineWhisperModelConfig(config.whisper, Module);
|
676 |
+
|
677 |
+
const tdnn = initSherpaOnnxOfflineTdnnModelConfig(config.tdnn, Module);
|
678 |
+
|
679 |
+
const senseVoice =
|
680 |
+
initSherpaOnnxOfflineSenseVoiceModelConfig(config.senseVoice, Module);
|
681 |
+
|
682 |
+
const len = transducer.len + paraformer.len + nemoCtc.len + whisper.len +
|
683 |
+
tdnn.len + 8 * 4 + senseVoice.len;
|
684 |
+
|
685 |
+
const ptr = Module._malloc(len);
|
686 |
+
|
687 |
+
let offset = 0;
|
688 |
+
Module._CopyHeap(transducer.ptr, transducer.len, ptr + offset);
|
689 |
+
offset += transducer.len;
|
690 |
+
|
691 |
+
Module._CopyHeap(paraformer.ptr, paraformer.len, ptr + offset);
|
692 |
+
offset += paraformer.len;
|
693 |
+
|
694 |
+
Module._CopyHeap(nemoCtc.ptr, nemoCtc.len, ptr + offset);
|
695 |
+
offset += nemoCtc.len;
|
696 |
+
|
697 |
+
Module._CopyHeap(whisper.ptr, whisper.len, ptr + offset);
|
698 |
+
offset += whisper.len;
|
699 |
+
|
700 |
+
Module._CopyHeap(tdnn.ptr, tdnn.len, ptr + offset);
|
701 |
+
offset += tdnn.len;
|
702 |
+
|
703 |
+
|
704 |
+
const tokensLen = Module.lengthBytesUTF8(config.tokens || '') + 1;
|
705 |
+
const providerLen = Module.lengthBytesUTF8(config.provider || 'cpu') + 1;
|
706 |
+
const modelTypeLen = Module.lengthBytesUTF8(config.modelType || '') + 1;
|
707 |
+
const modelingUnitLen = Module.lengthBytesUTF8(config.modelingUnit || '') + 1;
|
708 |
+
const bpeVocabLen = Module.lengthBytesUTF8(config.bpeVocab || '') + 1;
|
709 |
+
const teleSpeechCtcLen =
|
710 |
+
Module.lengthBytesUTF8(config.teleSpeechCtc || '') + 1;
|
711 |
+
|
712 |
+
const bufferLen = tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
713 |
+
bpeVocabLen + teleSpeechCtcLen;
|
714 |
+
|
715 |
+
const buffer = Module._malloc(bufferLen);
|
716 |
+
|
717 |
+
offset = 0;
|
718 |
+
Module.stringToUTF8(config.tokens, buffer, tokensLen);
|
719 |
+
offset += tokensLen;
|
720 |
+
|
721 |
+
Module.stringToUTF8(config.provider || 'cpu', buffer + offset, providerLen);
|
722 |
+
offset += providerLen;
|
723 |
+
|
724 |
+
Module.stringToUTF8(config.modelType || '', buffer + offset, modelTypeLen);
|
725 |
+
offset += modelTypeLen;
|
726 |
+
|
727 |
+
Module.stringToUTF8(
|
728 |
+
config.modelingUnit || '', buffer + offset, modelingUnitLen);
|
729 |
+
offset += modelingUnitLen;
|
730 |
+
|
731 |
+
Module.stringToUTF8(config.bpeVocab || '', buffer + offset, bpeVocabLen);
|
732 |
+
offset += bpeVocabLen;
|
733 |
+
|
734 |
+
Module.stringToUTF8(
|
735 |
+
config.teleSpeechCtc || '', buffer + offset, teleSpeechCtcLen);
|
736 |
+
offset += teleSpeechCtcLen;
|
737 |
+
|
738 |
+
offset =
|
739 |
+
transducer.len + paraformer.len + nemoCtc.len + whisper.len + tdnn.len;
|
740 |
+
Module.setValue(ptr + offset, buffer, 'i8*'); // tokens
|
741 |
+
offset += 4;
|
742 |
+
|
743 |
+
Module.setValue(ptr + offset, config.numThreads || 1, 'i32');
|
744 |
+
offset += 4;
|
745 |
+
|
746 |
+
Module.setValue(ptr + offset, config.debug || 0, 'i32');
|
747 |
+
offset += 4;
|
748 |
+
|
749 |
+
Module.setValue(ptr + offset, buffer + tokensLen, 'i8*'); // provider
|
750 |
+
offset += 4;
|
751 |
+
|
752 |
+
Module.setValue(
|
753 |
+
ptr + offset, buffer + tokensLen + providerLen, 'i8*'); // modelType
|
754 |
+
offset += 4;
|
755 |
+
|
756 |
+
Module.setValue(
|
757 |
+
ptr + offset, buffer + tokensLen + providerLen + modelTypeLen,
|
758 |
+
'i8*'); // modelingUnit
|
759 |
+
offset += 4;
|
760 |
+
|
761 |
+
Module.setValue(
|
762 |
+
ptr + offset,
|
763 |
+
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen,
|
764 |
+
'i8*'); // bpeVocab
|
765 |
+
offset += 4;
|
766 |
+
|
767 |
+
Module.setValue(
|
768 |
+
ptr + offset,
|
769 |
+
buffer + tokensLen + providerLen + modelTypeLen + modelingUnitLen +
|
770 |
+
bpeVocabLen,
|
771 |
+
'i8*'); // teleSpeechCtc
|
772 |
+
offset += 4;
|
773 |
+
|
774 |
+
Module._CopyHeap(senseVoice.ptr, senseVoice.len, ptr + offset);
|
775 |
+
|
776 |
+
return {
|
777 |
+
buffer: buffer, ptr: ptr, len: len, transducer: transducer,
|
778 |
+
paraformer: paraformer, nemoCtc: nemoCtc, whisper: whisper, tdnn: tdnn,
|
779 |
+
senseVoice: senseVoice,
|
780 |
+
}
|
781 |
+
}
|
782 |
+
|
783 |
+
function initSherpaOnnxOfflineRecognizerConfig(config, Module) {
|
784 |
+
if (!('featConfig' in config)) {
|
785 |
+
config.featConfig = {
|
786 |
+
sampleRate: 16000,
|
787 |
+
featureDim: 80,
|
788 |
+
};
|
789 |
+
}
|
790 |
+
|
791 |
+
if (!('lmConfig' in config)) {
|
792 |
+
config.lmConfig = {
|
793 |
+
model: '',
|
794 |
+
scale: 1.0,
|
795 |
+
};
|
796 |
+
}
|
797 |
+
|
798 |
+
const feat = initSherpaOnnxFeatureConfig(config.featConfig, Module);
|
799 |
+
const model = initSherpaOnnxOfflineModelConfig(config.modelConfig, Module);
|
800 |
+
const lm = initSherpaOnnxOfflineLMConfig(config.lmConfig, Module);
|
801 |
+
|
802 |
+
const len = feat.len + model.len + lm.len + 7 * 4;
|
803 |
+
const ptr = Module._malloc(len);
|
804 |
+
|
805 |
+
let offset = 0;
|
806 |
+
Module._CopyHeap(feat.ptr, feat.len, ptr + offset);
|
807 |
+
offset += feat.len;
|
808 |
+
|
809 |
+
Module._CopyHeap(model.ptr, model.len, ptr + offset);
|
810 |
+
offset += model.len;
|
811 |
+
|
812 |
+
Module._CopyHeap(lm.ptr, lm.len, ptr + offset);
|
813 |
+
offset += lm.len;
|
814 |
+
|
815 |
+
const decodingMethodLen =
|
816 |
+
Module.lengthBytesUTF8(config.decodingMethod || 'greedy_search') + 1;
|
817 |
+
const hotwordsFileLen = Module.lengthBytesUTF8(config.hotwordsFile || '') + 1;
|
818 |
+
const ruleFstsLen = Module.lengthBytesUTF8(config.ruleFsts || '') + 1;
|
819 |
+
const ruleFarsLen = Module.lengthBytesUTF8(config.ruleFars || '') + 1;
|
820 |
+
const bufferLen =
|
821 |
+
decodingMethodLen + hotwordsFileLen + ruleFstsLen + ruleFarsLen;
|
822 |
+
const buffer = Module._malloc(bufferLen);
|
823 |
+
|
824 |
+
offset = 0;
|
825 |
+
Module.stringToUTF8(
|
826 |
+
config.decodingMethod || 'greedy_search', buffer, decodingMethodLen);
|
827 |
+
offset += decodingMethodLen;
|
828 |
+
|
829 |
+
Module.stringToUTF8(
|
830 |
+
config.hotwordsFile || '', buffer + offset, hotwordsFileLen);
|
831 |
+
offset += hotwordsFileLen;
|
832 |
+
|
833 |
+
Module.stringToUTF8(config.ruleFsts || '', buffer + offset, ruleFstsLen);
|
834 |
+
offset += ruleFstsLen;
|
835 |
+
|
836 |
+
Module.stringToUTF8(config.ruleFars || '', buffer + offset, ruleFarsLen);
|
837 |
+
offset += ruleFarsLen;
|
838 |
+
|
839 |
+
offset = feat.len + model.len + lm.len;
|
840 |
+
|
841 |
+
Module.setValue(ptr + offset, buffer, 'i8*'); // decoding method
|
842 |
+
offset += 4;
|
843 |
+
|
844 |
+
Module.setValue(ptr + offset, config.maxActivePaths || 4, 'i32');
|
845 |
+
offset += 4;
|
846 |
+
|
847 |
+
Module.setValue(ptr + offset, buffer + decodingMethodLen, 'i8*');
|
848 |
+
offset += 4;
|
849 |
+
|
850 |
+
Module.setValue(ptr + offset, config.hotwordsScore || 1.5, 'float');
|
851 |
+
offset += 4;
|
852 |
+
|
853 |
+
Module.setValue(
|
854 |
+
ptr + offset, buffer + decodingMethodLen + hotwordsFileLen, 'i8*');
|
855 |
+
offset += 4;
|
856 |
+
|
857 |
+
Module.setValue(
|
858 |
+
ptr + offset, buffer + decodingMethodLen + hotwordsFileLen + ruleFstsLen,
|
859 |
+
'i8*');
|
860 |
+
offset += 4;
|
861 |
+
|
862 |
+
Module.setValue(ptr + offset, config.blankPenalty || 0, 'float');
|
863 |
+
offset += 4;
|
864 |
+
|
865 |
+
return {
|
866 |
+
buffer: buffer, ptr: ptr, len: len, feat: feat, model: model, lm: lm
|
867 |
+
}
|
868 |
+
}
|
869 |
+
|
870 |
+
class OfflineStream {
|
871 |
+
constructor(handle, Module) {
|
872 |
+
this.handle = handle;
|
873 |
+
this.Module = Module;
|
874 |
+
}
|
875 |
+
|
876 |
+
free() {
|
877 |
+
if (this.handle) {
|
878 |
+
this.Module._SherpaOnnxDestroyOfflineStream(this.handle);
|
879 |
+
this.handle = null;
|
880 |
+
}
|
881 |
+
}
|
882 |
+
|
883 |
+
/**
|
884 |
+
* @param sampleRate {Number}
|
885 |
+
* @param samples {Float32Array} Containing samples in the range [-1, 1]
|
886 |
+
*/
|
887 |
+
acceptWaveform(sampleRate, samples) {
|
888 |
+
const pointer =
|
889 |
+
this.Module._malloc(samples.length * samples.BYTES_PER_ELEMENT);
|
890 |
+
this.Module.HEAPF32.set(samples, pointer / samples.BYTES_PER_ELEMENT);
|
891 |
+
this.Module._SherpaOnnxAcceptWaveformOffline(
|
892 |
+
this.handle, sampleRate, pointer, samples.length);
|
893 |
+
this.Module._free(pointer);
|
894 |
+
}
|
895 |
+
};
|
896 |
+
|
897 |
+
class OfflineRecognizer {
|
898 |
+
constructor(configObj, Module) {
|
899 |
+
this.config = configObj;
|
900 |
+
const config = initSherpaOnnxOfflineRecognizerConfig(configObj, Module);
|
901 |
+
const handle = Module._SherpaOnnxCreateOfflineRecognizer(config.ptr);
|
902 |
+
freeConfig(config, Module);
|
903 |
+
|
904 |
+
this.handle = handle;
|
905 |
+
this.Module = Module;
|
906 |
+
}
|
907 |
+
|
908 |
+
free() {
|
909 |
+
this.Module._SherpaOnnxDestroyOfflineRecognizer(this.handle);
|
910 |
+
this.handle = 0
|
911 |
+
}
|
912 |
+
|
913 |
+
createStream() {
|
914 |
+
const handle = this.Module._SherpaOnnxCreateOfflineStream(this.handle);
|
915 |
+
return new OfflineStream(handle, this.Module);
|
916 |
+
}
|
917 |
+
|
918 |
+
decode(stream) {
|
919 |
+
this.Module._SherpaOnnxDecodeOfflineStream(this.handle, stream.handle);
|
920 |
+
}
|
921 |
+
|
922 |
+
getResult(stream) {
|
923 |
+
const r =
|
924 |
+
this.Module._SherpaOnnxGetOfflineStreamResultAsJson(stream.handle);
|
925 |
+
const jsonStr = this.Module.UTF8ToString(r);
|
926 |
+
const ans = JSON.parse(jsonStr);
|
927 |
+
this.Module._SherpaOnnxDestroyOfflineStreamResultJson(r);
|
928 |
+
|
929 |
+
return ans;
|
930 |
+
}
|
931 |
+
};
|
932 |
+
|
933 |
+
class OnlineStream {
|
934 |
+
constructor(handle, Module) {
|
935 |
+
this.handle = handle;
|
936 |
+
this.pointer = null; // buffer
|
937 |
+
this.n = 0; // buffer size
|
938 |
+
this.Module = Module;
|
939 |
+
}
|
940 |
+
|
941 |
+
free() {
|
942 |
+
if (this.handle) {
|
943 |
+
this.Module._SherpaOnnxDestroyOnlineStream(this.handle);
|
944 |
+
this.handle = null;
|
945 |
+
this.Module._free(this.pointer);
|
946 |
+
this.pointer = null;
|
947 |
+
this.n = 0;
|
948 |
+
}
|
949 |
+
}
|
950 |
+
|
951 |
+
/**
|
952 |
+
* @param sampleRate {Number}
|
953 |
+
* @param samples {Float32Array} Containing samples in the range [-1, 1]
|
954 |
+
*/
|
955 |
+
acceptWaveform(sampleRate, samples) {
|
956 |
+
if (this.n < samples.length) {
|
957 |
+
this.Module._free(this.pointer);
|
958 |
+
this.pointer =
|
959 |
+
this.Module._malloc(samples.length * samples.BYTES_PER_ELEMENT);
|
960 |
+
this.n = samples.length
|
961 |
+
}
|
962 |
+
|
963 |
+
this.Module.HEAPF32.set(samples, this.pointer / samples.BYTES_PER_ELEMENT);
|
964 |
+
this.Module._SherpaOnnxOnlineStreamAcceptWaveform(
|
965 |
+
this.handle, sampleRate, this.pointer, samples.length);
|
966 |
+
}
|
967 |
+
|
968 |
+
inputFinished() {
|
969 |
+
this.Module._SherpaOnnxOnlineStreamInputFinished(this.handle);
|
970 |
+
}
|
971 |
+
};
|
972 |
+
|
973 |
+
class OnlineRecognizer {
|
974 |
+
constructor(configObj, Module) {
|
975 |
+
this.config = configObj;
|
976 |
+
const config = initSherpaOnnxOnlineRecognizerConfig(configObj, Module)
|
977 |
+
const handle = Module._SherpaOnnxCreateOnlineRecognizer(config.ptr);
|
978 |
+
|
979 |
+
freeConfig(config, Module);
|
980 |
+
|
981 |
+
this.handle = handle;
|
982 |
+
this.Module = Module;
|
983 |
+
}
|
984 |
+
|
985 |
+
free() {
|
986 |
+
this.Module._SherpaOnnxDestroyOnlineRecognizer(this.handle);
|
987 |
+
this.handle = 0
|
988 |
+
}
|
989 |
+
|
990 |
+
createStream() {
|
991 |
+
const handle = this.Module._SherpaOnnxCreateOnlineStream(this.handle);
|
992 |
+
return new OnlineStream(handle, this.Module);
|
993 |
+
}
|
994 |
+
|
995 |
+
isReady(stream) {
|
996 |
+
return this.Module._SherpaOnnxIsOnlineStreamReady(
|
997 |
+
this.handle, stream.handle) == 1;
|
998 |
+
}
|
999 |
+
|
1000 |
+
decode(stream) {
|
1001 |
+
this.Module._SherpaOnnxDecodeOnlineStream(this.handle, stream.handle);
|
1002 |
+
}
|
1003 |
+
|
1004 |
+
isEndpoint(stream) {
|
1005 |
+
return this.Module._SherpaOnnxOnlineStreamIsEndpoint(
|
1006 |
+
this.handle, stream.handle) == 1;
|
1007 |
+
}
|
1008 |
+
|
1009 |
+
reset(stream) {
|
1010 |
+
this.Module._SherpaOnnxOnlineStreamReset(this.handle, stream.handle);
|
1011 |
+
}
|
1012 |
+
|
1013 |
+
getResult(stream) {
|
1014 |
+
const r = this.Module._SherpaOnnxGetOnlineStreamResultAsJson(
|
1015 |
+
this.handle, stream.handle);
|
1016 |
+
const jsonStr = this.Module.UTF8ToString(r);
|
1017 |
+
const ans = JSON.parse(jsonStr);
|
1018 |
+
this.Module._SherpaOnnxDestroyOnlineStreamResultJson(r);
|
1019 |
+
|
1020 |
+
return ans;
|
1021 |
+
}
|
1022 |
+
}
|
1023 |
+
|
1024 |
+
if (typeof process == 'object' && typeof process.versions == 'object' &&
|
1025 |
+
typeof process.versions.node == 'string') {
|
1026 |
+
module.exports = {
|
1027 |
+
createOnlineRecognizer,
|
1028 |
+
OfflineRecognizer,
|
1029 |
+
};
|
1030 |
+
}
|
sherpa-onnx-wasm-main-asr.js
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
var Module=typeof Module!="undefined"?Module:{};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&process.type!="renderer";if(ENVIRONMENT_IS_NODE){}var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename);return ret};readAsync=async(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):filename;var ret=fs.readFileSync(filename,binary?undefined:"utf8");return ret};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=async url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var EXITSTATUS;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAP64,HEAPU64,HEAPF64;var runtimeInitialized=false;var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b);Module["HEAP64"]=HEAP64=new BigInt64Array(b);Module["HEAPU64"]=HEAPU64=new BigUint64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATPOSTRUN__=[];function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;if(!Module["noFSInit"]&&!FS.initialized)FS.init();FS.ignorePermissions=false;TTY.init();callRuntimeCallbacks(__ATINIT__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var dependenciesFulfilled=null;function getUniqueRunDependency(id){return id}function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var wasmBinaryFile;function findWasmBinary(){var f="sherpa-onnx-wasm-main-asr.wasm";if(!isDataURI(f)){return locateFile(f)}return f}function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){return{a:wasmImports}}async function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["I"];updateMemoryViews();addOnInit(wasmExports["J"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);return false}}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}var ASM_CONSTS={1004968:($0,$1,$2,$3)=>{if(typeof Module=="undefined"||!Module.MountedFiles){return 1}let fileName=UTF8ToString($0>>>0);if(fileName.startsWith("./")){fileName=fileName.substring(2)}const fileData=Module.MountedFiles.get(fileName);if(!fileData){return 2}const offset=$1>>>0;const length=$2>>>0;const buffer=$3>>>0;if(offset+length>fileData.byteLength){return 3}try{HEAPU8.set(fileData.subarray(offset,offset+length),buffer);return 0}catch{return 4}}};class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};function getValue(ptr,type="i8"){if(type.endsWith("*"))type="*";switch(type){case"i1":return HEAP8[ptr];case"i8":return HEAP8[ptr];case"i16":return HEAP16[ptr>>1];case"i32":return HEAP32[ptr>>2];case"i64":return HEAP64[ptr>>3];case"float":return HEAPF32[ptr>>2];case"double":return HEAPF64[ptr>>3];case"*":return HEAPU32[ptr>>2];default:abort(`invalid type for getValue: ${type}`)}}var noExitRuntime=Module["noExitRuntime"]||true;function setValue(ptr,value,type="i8"){if(type.endsWith("*"))type="*";switch(type){case"i1":HEAP8[ptr]=value;break;case"i8":HEAP8[ptr]=value;break;case"i16":HEAP16[ptr>>1]=value;break;case"i32":HEAP32[ptr>>2]=value;break;case"i64":HEAP64[ptr>>3]=BigInt(value);break;case"float":HEAPF32[ptr>>2]=value;break;case"double":HEAPF64[ptr>>3]=value;break;case"*":HEAPU32[ptr>>2]=value;break;default:abort(`invalid type for setValue: ${type}`)}}var stackRestore=val=>__emscripten_stack_restore(val);var stackSave=()=>_emscripten_stack_get_current();class ExceptionInfo{constructor(excPtr){this.excPtr=excPtr;this.ptr=excPtr-24}set_type(type){HEAPU32[this.ptr+4>>2]=type}get_type(){return HEAPU32[this.ptr+4>>2]}set_destructor(destructor){HEAPU32[this.ptr+8>>2]=destructor}get_destructor(){return HEAPU32[this.ptr+8>>2]}set_caught(caught){caught=caught?1:0;HEAP8[this.ptr+12]=caught}get_caught(){return HEAP8[this.ptr+12]!=0}set_rethrown(rethrown){rethrown=rethrown?1:0;HEAP8[this.ptr+13]=rethrown}get_rethrown(){return HEAP8[this.ptr+13]!=0}init(type,destructor){this.set_adjusted_ptr(0);this.set_type(type);this.set_destructor(destructor)}set_adjusted_ptr(adjustedPtr){HEAPU32[this.ptr+16>>2]=adjustedPtr}get_adjusted_ptr(){return HEAPU32[this.ptr+16>>2]}}var exceptionLast=0;var uncaughtExceptionCount=0;var ___cxa_throw=(ptr,type,destructor)=>{var info=new ExceptionInfo(ptr);info.init(type,destructor);exceptionLast=ptr;uncaughtExceptionCount++;throw exceptionLast};var syscallGetVarargI=()=>{var ret=HEAP32[+SYSCALLS.varargs>>2];SYSCALLS.varargs+=4;return ret};var syscallGetVarargP=syscallGetVarargI;var PATH={isAbs:path=>path.charAt(0)==="/",splitPath:filename=>{var splitPathRe=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/;return splitPathRe.exec(filename).slice(1)},normalizeArray:(parts,allowAboveRoot)=>{var up=0;for(var i=parts.length-1;i>=0;i--){var last=parts[i];if(last==="."){parts.splice(i,1)}else if(last===".."){parts.splice(i,1);up++}else if(up){parts.splice(i,1);up--}}if(allowAboveRoot){for(;up;up--){parts.unshift("..")}}return parts},normalize:path=>{var isAbsolute=PATH.isAbs(path),trailingSlash=path.substr(-1)==="/";path=PATH.normalizeArray(path.split("/").filter(p=>!!p),!isAbsolute).join("/");if(!path&&!isAbsolute){path="."}if(path&&trailingSlash){path+="/"}return(isAbsolute?"/":"")+path},dirname:path=>{var result=PATH.splitPath(path),root=result[0],dir=result[1];if(!root&&!dir){return"."}if(dir){dir=dir.substr(0,dir.length-1)}return root+dir},basename:path=>path&&path.match(/([^\/]+|\/)\/*$/)[1],join:(...paths)=>PATH.normalize(paths.join("/")),join2:(l,r)=>PATH.normalize(l+"/"+r)};var initRandomFill=()=>{if(ENVIRONMENT_IS_NODE){var nodeCrypto=require("crypto");return view=>nodeCrypto.randomFillSync(view)}return view=>crypto.getRandomValues(view)};var randomFill=view=>{(randomFill=initRandomFill())(view)};var PATH_FS={resolve:(...args)=>{var resolvedPath="",resolvedAbsolute=false;for(var i=args.length-1;i>=-1&&!resolvedAbsolute;i--){var path=i>=0?args[i]:FS.cwd();if(typeof path!="string"){throw new TypeError("Arguments to path.resolve must be strings")}else if(!path){return""}resolvedPath=path+"/"+resolvedPath;resolvedAbsolute=PATH.isAbs(path)}resolvedPath=PATH.normalizeArray(resolvedPath.split("/").filter(p=>!!p),!resolvedAbsolute).join("/");return(resolvedAbsolute?"/":"")+resolvedPath||"."},relative:(from,to)=>{from=PATH_FS.resolve(from).substr(1);to=PATH_FS.resolve(to).substr(1);function trim(arr){var start=0;for(;start<arr.length;start++){if(arr[start]!=="")break}var end=arr.length-1;for(;end>=0;end--){if(arr[end]!=="")break}if(start>end)return[];return arr.slice(start,end-start+1)}var fromParts=trim(from.split("/"));var toParts=trim(to.split("/"));var length=Math.min(fromParts.length,toParts.length);var samePartsLength=length;for(var i=0;i<length;i++){if(fromParts[i]!==toParts[i]){samePartsLength=i;break}}var outputParts=[];for(var i=samePartsLength;i<fromParts.length;i++){outputParts.push("..")}outputParts=outputParts.concat(toParts.slice(samePartsLength));return outputParts.join("/")}};var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder:undefined;var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead=NaN)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var FS_stdin_getChar_buffer=[];var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};function intArrayFromString(stringy,dontAddNull,length){var len=length>0?length:lengthBytesUTF8(stringy)+1;var u8array=new Array(len);var numBytesWritten=stringToUTF8Array(stringy,u8array,0,u8array.length);if(dontAddNull)u8array.length=numBytesWritten;return u8array}var FS_stdin_getChar=()=>{if(!FS_stdin_getChar_buffer.length){var result=null;if(ENVIRONMENT_IS_NODE){var BUFSIZE=256;var buf=Buffer.alloc(BUFSIZE);var bytesRead=0;var fd=process.stdin.fd;try{bytesRead=fs.readSync(fd,buf,0,BUFSIZE)}catch(e){if(e.toString().includes("EOF"))bytesRead=0;else throw e}if(bytesRead>0){result=buf.slice(0,bytesRead).toString("utf-8")}}else if(typeof window!="undefined"&&typeof window.prompt=="function"){result=window.prompt("Input: ");if(result!==null){result+="\n"}}else{}if(!result){return null}FS_stdin_getChar_buffer=intArrayFromString(result,true)}return FS_stdin_getChar_buffer.shift()};var TTY={ttys:[],init(){},shutdown(){},register(dev,ops){TTY.ttys[dev]={input:[],output:[],ops};FS.registerDevice(dev,TTY.stream_ops)},stream_ops:{open(stream){var tty=TTY.ttys[stream.node.rdev];if(!tty){throw new FS.ErrnoError(43)}stream.tty=tty;stream.seekable=false},close(stream){stream.tty.ops.fsync(stream.tty)},fsync(stream){stream.tty.ops.fsync(stream.tty)},read(stream,buffer,offset,length,pos){if(!stream.tty||!stream.tty.ops.get_char){throw new FS.ErrnoError(60)}var bytesRead=0;for(var i=0;i<length;i++){var result;try{result=stream.tty.ops.get_char(stream.tty)}catch(e){throw new FS.ErrnoError(29)}if(result===undefined&&bytesRead===0){throw new FS.ErrnoError(6)}if(result===null||result===undefined)break;bytesRead++;buffer[offset+i]=result}if(bytesRead){stream.node.atime=Date.now()}return bytesRead},write(stream,buffer,offset,length,pos){if(!stream.tty||!stream.tty.ops.put_char){throw new FS.ErrnoError(60)}try{for(var i=0;i<length;i++){stream.tty.ops.put_char(stream.tty,buffer[offset+i])}}catch(e){throw new FS.ErrnoError(29)}if(length){stream.node.mtime=stream.node.ctime=Date.now()}return i}},default_tty_ops:{get_char(tty){return FS_stdin_getChar()},put_char(tty,val){if(val===null||val===10){out(UTF8ArrayToString(tty.output));tty.output=[]}else{if(val!=0)tty.output.push(val)}},fsync(tty){if(tty.output&&tty.output.length>0){out(UTF8ArrayToString(tty.output));tty.output=[]}},ioctl_tcgets(tty){return{c_iflag:25856,c_oflag:5,c_cflag:191,c_lflag:35387,c_cc:[3,28,127,21,4,0,1,0,17,19,26,0,18,15,23,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}},ioctl_tcsets(tty,optional_actions,data){return 0},ioctl_tiocgwinsz(tty){return[24,80]}},default_tty1_ops:{put_char(tty,val){if(val===null||val===10){err(UTF8ArrayToString(tty.output));tty.output=[]}else{if(val!=0)tty.output.push(val)}},fsync(tty){if(tty.output&&tty.output.length>0){err(UTF8ArrayToString(tty.output));tty.output=[]}}}};var zeroMemory=(address,size)=>{HEAPU8.fill(0,address,address+size)};var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var mmapAlloc=size=>{size=alignMemory(size,65536);var ptr=_emscripten_builtin_memalign(65536,size);if(ptr)zeroMemory(ptr,size);return ptr};var MEMFS={ops_table:null,mount(mount){return MEMFS.createNode(null,"/",16895,0)},createNode(parent,name,mode,dev){if(FS.isBlkdev(mode)||FS.isFIFO(mode)){throw new FS.ErrnoError(63)}MEMFS.ops_table||={dir:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr,lookup:MEMFS.node_ops.lookup,mknod:MEMFS.node_ops.mknod,rename:MEMFS.node_ops.rename,unlink:MEMFS.node_ops.unlink,rmdir:MEMFS.node_ops.rmdir,readdir:MEMFS.node_ops.readdir,symlink:MEMFS.node_ops.symlink},stream:{llseek:MEMFS.stream_ops.llseek}},file:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr},stream:{llseek:MEMFS.stream_ops.llseek,read:MEMFS.stream_ops.read,write:MEMFS.stream_ops.write,allocate:MEMFS.stream_ops.allocate,mmap:MEMFS.stream_ops.mmap,msync:MEMFS.stream_ops.msync}},link:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr,readlink:MEMFS.node_ops.readlink},stream:{}},chrdev:{node:{getattr:MEMFS.node_ops.getattr,setattr:MEMFS.node_ops.setattr},stream:FS.chrdev_stream_ops}};var node=FS.createNode(parent,name,mode,dev);if(FS.isDir(node.mode)){node.node_ops=MEMFS.ops_table.dir.node;node.stream_ops=MEMFS.ops_table.dir.stream;node.contents={}}else if(FS.isFile(node.mode)){node.node_ops=MEMFS.ops_table.file.node;node.stream_ops=MEMFS.ops_table.file.stream;node.usedBytes=0;node.contents=null}else if(FS.isLink(node.mode)){node.node_ops=MEMFS.ops_table.link.node;node.stream_ops=MEMFS.ops_table.link.stream}else if(FS.isChrdev(node.mode)){node.node_ops=MEMFS.ops_table.chrdev.node;node.stream_ops=MEMFS.ops_table.chrdev.stream}node.atime=node.mtime=node.ctime=Date.now();if(parent){parent.contents[name]=node;parent.atime=parent.mtime=parent.ctime=node.atime}return node},getFileDataAsTypedArray(node){if(!node.contents)return new Uint8Array(0);if(node.contents.subarray)return node.contents.subarray(0,node.usedBytes);return new Uint8Array(node.contents)},expandFileStorage(node,newCapacity){var prevCapacity=node.contents?node.contents.length:0;if(prevCapacity>=newCapacity)return;var CAPACITY_DOUBLING_MAX=1024*1024;newCapacity=Math.max(newCapacity,prevCapacity*(prevCapacity<CAPACITY_DOUBLING_MAX?2:1.125)>>>0);if(prevCapacity!=0)newCapacity=Math.max(newCapacity,256);var oldContents=node.contents;node.contents=new Uint8Array(newCapacity);if(node.usedBytes>0)node.contents.set(oldContents.subarray(0,node.usedBytes),0)},resizeFileStorage(node,newSize){if(node.usedBytes==newSize)return;if(newSize==0){node.contents=null;node.usedBytes=0}else{var oldContents=node.contents;node.contents=new Uint8Array(newSize);if(oldContents){node.contents.set(oldContents.subarray(0,Math.min(newSize,node.usedBytes)))}node.usedBytes=newSize}},node_ops:{getattr(node){var attr={};attr.dev=FS.isChrdev(node.mode)?node.id:1;attr.ino=node.id;attr.mode=node.mode;attr.nlink=1;attr.uid=0;attr.gid=0;attr.rdev=node.rdev;if(FS.isDir(node.mode)){attr.size=4096}else if(FS.isFile(node.mode)){attr.size=node.usedBytes}else if(FS.isLink(node.mode)){attr.size=node.link.length}else{attr.size=0}attr.atime=new Date(node.atime);attr.mtime=new Date(node.mtime);attr.ctime=new Date(node.ctime);attr.blksize=4096;attr.blocks=Math.ceil(attr.size/attr.blksize);return attr},setattr(node,attr){for(const key of["mode","atime","mtime","ctime"]){if(attr[key]!=null){node[key]=attr[key]}}if(attr.size!==undefined){MEMFS.resizeFileStorage(node,attr.size)}},lookup(parent,name){throw MEMFS.doesNotExistError},mknod(parent,name,mode,dev){return MEMFS.createNode(parent,name,mode,dev)},rename(old_node,new_dir,new_name){var new_node;try{new_node=FS.lookupNode(new_dir,new_name)}catch(e){}if(new_node){if(FS.isDir(old_node.mode)){for(var i in new_node.contents){throw new FS.ErrnoError(55)}}FS.hashRemoveNode(new_node)}delete old_node.parent.contents[old_node.name];new_dir.contents[new_name]=old_node;old_node.name=new_name;new_dir.ctime=new_dir.mtime=old_node.parent.ctime=old_node.parent.mtime=Date.now()},unlink(parent,name){delete parent.contents[name];parent.ctime=parent.mtime=Date.now()},rmdir(parent,name){var node=FS.lookupNode(parent,name);for(var i in node.contents){throw new FS.ErrnoError(55)}delete parent.contents[name];parent.ctime=parent.mtime=Date.now()},readdir(node){return[".","..",...Object.keys(node.contents)]},symlink(parent,newname,oldpath){var node=MEMFS.createNode(parent,newname,511|40960,0);node.link=oldpath;return node},readlink(node){if(!FS.isLink(node.mode)){throw new FS.ErrnoError(28)}return node.link}},stream_ops:{read(stream,buffer,offset,length,position){var contents=stream.node.contents;if(position>=stream.node.usedBytes)return 0;var size=Math.min(stream.node.usedBytes-position,length);if(size>8&&contents.subarray){buffer.set(contents.subarray(position,position+size),offset)}else{for(var i=0;i<size;i++)buffer[offset+i]=contents[position+i]}return size},write(stream,buffer,offset,length,position,canOwn){if(buffer.buffer===HEAP8.buffer){canOwn=false}if(!length)return 0;var node=stream.node;node.mtime=node.ctime=Date.now();if(buffer.subarray&&(!node.contents||node.contents.subarray)){if(canOwn){node.contents=buffer.subarray(offset,offset+length);node.usedBytes=length;return length}else if(node.usedBytes===0&&position===0){node.contents=buffer.slice(offset,offset+length);node.usedBytes=length;return length}else if(position+length<=node.usedBytes){node.contents.set(buffer.subarray(offset,offset+length),position);return length}}MEMFS.expandFileStorage(node,position+length);if(node.contents.subarray&&buffer.subarray){node.contents.set(buffer.subarray(offset,offset+length),position)}else{for(var i=0;i<length;i++){node.contents[position+i]=buffer[offset+i]}}node.usedBytes=Math.max(node.usedBytes,position+length);return length},llseek(stream,offset,whence){var position=offset;if(whence===1){position+=stream.position}else if(whence===2){if(FS.isFile(stream.node.mode)){position+=stream.node.usedBytes}}if(position<0){throw new FS.ErrnoError(28)}return position},allocate(stream,offset,length){MEMFS.expandFileStorage(stream.node,offset+length);stream.node.usedBytes=Math.max(stream.node.usedBytes,offset+length)},mmap(stream,length,position,prot,flags){if(!FS.isFile(stream.node.mode)){throw new FS.ErrnoError(43)}var ptr;var allocated;var contents=stream.node.contents;if(!(flags&2)&&contents&&contents.buffer===HEAP8.buffer){allocated=false;ptr=contents.byteOffset}else{allocated=true;ptr=mmapAlloc(length);if(!ptr){throw new FS.ErrnoError(48)}if(contents){if(position>0||position+length<contents.length){if(contents.subarray){contents=contents.subarray(position,position+length)}else{contents=Array.prototype.slice.call(contents,position,position+length)}}HEAP8.set(contents,ptr)}}return{ptr,allocated}},msync(stream,buffer,offset,length,mmapFlags){MEMFS.stream_ops.write(stream,buffer,0,length,offset,false);return 0}}};var asyncLoad=async url=>{var arrayBuffer=await readAsync(url);return new Uint8Array(arrayBuffer)};var FS_createDataFile=(parent,name,fileData,canRead,canWrite,canOwn)=>{FS.createDataFile(parent,name,fileData,canRead,canWrite,canOwn)};var preloadPlugins=Module["preloadPlugins"]||[];var FS_handledByPreloadPlugin=(byteArray,fullname,finish,onerror)=>{if(typeof Browser!="undefined")Browser.init();var handled=false;preloadPlugins.forEach(plugin=>{if(handled)return;if(plugin["canHandle"](fullname)){plugin["handle"](byteArray,fullname,finish,onerror);handled=true}});return handled};var FS_createPreloadedFile=(parent,name,url,canRead,canWrite,onload,onerror,dontCreateFile,canOwn,preFinish)=>{var fullname=name?PATH_FS.resolve(PATH.join2(parent,name)):parent;var dep=getUniqueRunDependency(`cp ${fullname}`);function processData(byteArray){function finish(byteArray){preFinish?.();if(!dontCreateFile){FS_createDataFile(parent,name,byteArray,canRead,canWrite,canOwn)}onload?.();removeRunDependency(dep)}if(FS_handledByPreloadPlugin(byteArray,fullname,finish,()=>{onerror?.();removeRunDependency(dep)})){return}finish(byteArray)}addRunDependency(dep);if(typeof url=="string"){asyncLoad(url).then(processData,onerror)}else{processData(url)}};var FS_modeStringToFlags=str=>{var flagModes={r:0,"r+":2,w:512|64|1,"w+":512|64|2,a:1024|64|1,"a+":1024|64|2};var flags=flagModes[str];if(typeof flags=="undefined"){throw new Error(`Unknown file open mode: ${str}`)}return flags};var FS_getMode=(canRead,canWrite)=>{var mode=0;if(canRead)mode|=292|73;if(canWrite)mode|=146;return mode};var FS={root:null,mounts:[],devices:{},streams:[],nextInode:1,nameTable:null,currentPath:"/",initialized:false,ignorePermissions:true,ErrnoError:class{name="ErrnoError";constructor(errno){this.errno=errno}},filesystems:null,syncFSRequests:0,readFiles:{},FSStream:class{shared={};get object(){return this.node}set object(val){this.node=val}get isRead(){return(this.flags&2097155)!==1}get isWrite(){return(this.flags&2097155)!==0}get isAppend(){return this.flags&1024}get flags(){return this.shared.flags}set flags(val){this.shared.flags=val}get position(){return this.shared.position}set position(val){this.shared.position=val}},FSNode:class{node_ops={};stream_ops={};readMode=292|73;writeMode=146;mounted=null;constructor(parent,name,mode,rdev){if(!parent){parent=this}this.parent=parent;this.mount=parent.mount;this.id=FS.nextInode++;this.name=name;this.mode=mode;this.rdev=rdev;this.atime=this.mtime=this.ctime=Date.now()}get read(){return(this.mode&this.readMode)===this.readMode}set read(val){val?this.mode|=this.readMode:this.mode&=~this.readMode}get write(){return(this.mode&this.writeMode)===this.writeMode}set write(val){val?this.mode|=this.writeMode:this.mode&=~this.writeMode}get isFolder(){return FS.isDir(this.mode)}get isDevice(){return FS.isChrdev(this.mode)}},lookupPath(path,opts={}){if(!path){throw new FS.ErrnoError(44)}opts.follow_mount??=true;if(!PATH.isAbs(path)){path=FS.cwd()+"/"+path}linkloop:for(var nlinks=0;nlinks<40;nlinks++){var parts=path.split("/").filter(p=>!!p);var current=FS.root;var current_path="/";for(var i=0;i<parts.length;i++){var islast=i===parts.length-1;if(islast&&opts.parent){break}if(parts[i]==="."){continue}if(parts[i]===".."){current_path=PATH.dirname(current_path);current=current.parent;continue}current_path=PATH.join2(current_path,parts[i]);try{current=FS.lookupNode(current,parts[i])}catch(e){if(e?.errno===44&&islast&&opts.noent_okay){return{path:current_path}}throw e}if(FS.isMountpoint(current)&&(!islast||opts.follow_mount)){current=current.mounted.root}if(FS.isLink(current.mode)&&(!islast||opts.follow)){if(!current.node_ops.readlink){throw new FS.ErrnoError(52)}var link=current.node_ops.readlink(current);if(!PATH.isAbs(link)){link=PATH.dirname(current_path)+"/"+link}path=link+"/"+parts.slice(i+1).join("/");continue linkloop}}return{path:current_path,node:current}}throw new FS.ErrnoError(32)},getPath(node){var path;while(true){if(FS.isRoot(node)){var mount=node.mount.mountpoint;if(!path)return mount;return mount[mount.length-1]!=="/"?`${mount}/${path}`:mount+path}path=path?`${node.name}/${path}`:node.name;node=node.parent}},hashName(parentid,name){var hash=0;for(var i=0;i<name.length;i++){hash=(hash<<5)-hash+name.charCodeAt(i)|0}return(parentid+hash>>>0)%FS.nameTable.length},hashAddNode(node){var hash=FS.hashName(node.parent.id,node.name);node.name_next=FS.nameTable[hash];FS.nameTable[hash]=node},hashRemoveNode(node){var hash=FS.hashName(node.parent.id,node.name);if(FS.nameTable[hash]===node){FS.nameTable[hash]=node.name_next}else{var current=FS.nameTable[hash];while(current){if(current.name_next===node){current.name_next=node.name_next;break}current=current.name_next}}},lookupNode(parent,name){var errCode=FS.mayLookup(parent);if(errCode){throw new FS.ErrnoError(errCode)}var hash=FS.hashName(parent.id,name);for(var node=FS.nameTable[hash];node;node=node.name_next){var nodeName=node.name;if(node.parent.id===parent.id&&nodeName===name){return node}}return FS.lookup(parent,name)},createNode(parent,name,mode,rdev){var node=new FS.FSNode(parent,name,mode,rdev);FS.hashAddNode(node);return node},destroyNode(node){FS.hashRemoveNode(node)},isRoot(node){return node===node.parent},isMountpoint(node){return!!node.mounted},isFile(mode){return(mode&61440)===32768},isDir(mode){return(mode&61440)===16384},isLink(mode){return(mode&61440)===40960},isChrdev(mode){return(mode&61440)===8192},isBlkdev(mode){return(mode&61440)===24576},isFIFO(mode){return(mode&61440)===4096},isSocket(mode){return(mode&49152)===49152},flagsToPermissionString(flag){var perms=["r","w","rw"][flag&3];if(flag&512){perms+="w"}return perms},nodePermissions(node,perms){if(FS.ignorePermissions){return 0}if(perms.includes("r")&&!(node.mode&292)){return 2}else if(perms.includes("w")&&!(node.mode&146)){return 2}else if(perms.includes("x")&&!(node.mode&73)){return 2}return 0},mayLookup(dir){if(!FS.isDir(dir.mode))return 54;var errCode=FS.nodePermissions(dir,"x");if(errCode)return errCode;if(!dir.node_ops.lookup)return 2;return 0},mayCreate(dir,name){if(!FS.isDir(dir.mode)){return 54}try{var node=FS.lookupNode(dir,name);return 20}catch(e){}return FS.nodePermissions(dir,"wx")},mayDelete(dir,name,isdir){var node;try{node=FS.lookupNode(dir,name)}catch(e){return e.errno}var errCode=FS.nodePermissions(dir,"wx");if(errCode){return errCode}if(isdir){if(!FS.isDir(node.mode)){return 54}if(FS.isRoot(node)||FS.getPath(node)===FS.cwd()){return 10}}else{if(FS.isDir(node.mode)){return 31}}return 0},mayOpen(node,flags){if(!node){return 44}if(FS.isLink(node.mode)){return 32}else if(FS.isDir(node.mode)){if(FS.flagsToPermissionString(flags)!=="r"||flags&(512|64)){return 31}}return FS.nodePermissions(node,FS.flagsToPermissionString(flags))},checkOpExists(op,err){if(!op){throw new FS.ErrnoError(err)}return op},MAX_OPEN_FDS:4096,nextfd(){for(var fd=0;fd<=FS.MAX_OPEN_FDS;fd++){if(!FS.streams[fd]){return fd}}throw new FS.ErrnoError(33)},getStreamChecked(fd){var stream=FS.getStream(fd);if(!stream){throw new FS.ErrnoError(8)}return stream},getStream:fd=>FS.streams[fd],createStream(stream,fd=-1){stream=Object.assign(new FS.FSStream,stream);if(fd==-1){fd=FS.nextfd()}stream.fd=fd;FS.streams[fd]=stream;return stream},closeStream(fd){FS.streams[fd]=null},dupStream(origStream,fd=-1){var stream=FS.createStream(origStream,fd);stream.stream_ops?.dup?.(stream);return stream},chrdev_stream_ops:{open(stream){var device=FS.getDevice(stream.node.rdev);stream.stream_ops=device.stream_ops;stream.stream_ops.open?.(stream)},llseek(){throw new FS.ErrnoError(70)}},major:dev=>dev>>8,minor:dev=>dev&255,makedev:(ma,mi)=>ma<<8|mi,registerDevice(dev,ops){FS.devices[dev]={stream_ops:ops}},getDevice:dev=>FS.devices[dev],getMounts(mount){var mounts=[];var check=[mount];while(check.length){var m=check.pop();mounts.push(m);check.push(...m.mounts)}return mounts},syncfs(populate,callback){if(typeof populate=="function"){callback=populate;populate=false}FS.syncFSRequests++;if(FS.syncFSRequests>1){err(`warning: ${FS.syncFSRequests} FS.syncfs operations in flight at once, probably just doing extra work`)}var mounts=FS.getMounts(FS.root.mount);var completed=0;function doCallback(errCode){FS.syncFSRequests--;return callback(errCode)}function done(errCode){if(errCode){if(!done.errored){done.errored=true;return doCallback(errCode)}return}if(++completed>=mounts.length){doCallback(null)}}mounts.forEach(mount=>{if(!mount.type.syncfs){return done(null)}mount.type.syncfs(mount,populate,done)})},mount(type,opts,mountpoint){var root=mountpoint==="/";var pseudo=!mountpoint;var node;if(root&&FS.root){throw new FS.ErrnoError(10)}else if(!root&&!pseudo){var lookup=FS.lookupPath(mountpoint,{follow_mount:false});mountpoint=lookup.path;node=lookup.node;if(FS.isMountpoint(node)){throw new FS.ErrnoError(10)}if(!FS.isDir(node.mode)){throw new FS.ErrnoError(54)}}var mount={type,opts,mountpoint,mounts:[]};var mountRoot=type.mount(mount);mountRoot.mount=mount;mount.root=mountRoot;if(root){FS.root=mountRoot}else if(node){node.mounted=mount;if(node.mount){node.mount.mounts.push(mount)}}return mountRoot},unmount(mountpoint){var lookup=FS.lookupPath(mountpoint,{follow_mount:false});if(!FS.isMountpoint(lookup.node)){throw new FS.ErrnoError(28)}var node=lookup.node;var mount=node.mounted;var mounts=FS.getMounts(mount);Object.keys(FS.nameTable).forEach(hash=>{var current=FS.nameTable[hash];while(current){var next=current.name_next;if(mounts.includes(current.mount)){FS.destroyNode(current)}current=next}});node.mounted=null;var idx=node.mount.mounts.indexOf(mount);node.mount.mounts.splice(idx,1)},lookup(parent,name){return parent.node_ops.lookup(parent,name)},mknod(path,mode,dev){var lookup=FS.lookupPath(path,{parent:true});var parent=lookup.node;var name=PATH.basename(path);if(!name){throw new FS.ErrnoError(28)}if(name==="."||name===".."){throw new FS.ErrnoError(20)}var errCode=FS.mayCreate(parent,name);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.mknod){throw new FS.ErrnoError(63)}return parent.node_ops.mknod(parent,name,mode,dev)},statfs(path){return FS.statfsNode(FS.lookupPath(path,{follow:true}).node)},statfsStream(stream){return FS.statfsNode(stream.node)},statfsNode(node){var rtn={bsize:4096,frsize:4096,blocks:1e6,bfree:5e5,bavail:5e5,files:FS.nextInode,ffree:FS.nextInode-1,fsid:42,flags:2,namelen:255};if(node.node_ops.statfs){Object.assign(rtn,node.node_ops.statfs(node.mount.opts.root))}return rtn},create(path,mode=438){mode&=4095;mode|=32768;return FS.mknod(path,mode,0)},mkdir(path,mode=511){mode&=511|512;mode|=16384;return FS.mknod(path,mode,0)},mkdirTree(path,mode){var dirs=path.split("/");var d="";for(var i=0;i<dirs.length;++i){if(!dirs[i])continue;d+="/"+dirs[i];try{FS.mkdir(d,mode)}catch(e){if(e.errno!=20)throw e}}},mkdev(path,mode,dev){if(typeof dev=="undefined"){dev=mode;mode=438}mode|=8192;return FS.mknod(path,mode,dev)},symlink(oldpath,newpath){if(!PATH_FS.resolve(oldpath)){throw new FS.ErrnoError(44)}var lookup=FS.lookupPath(newpath,{parent:true});var parent=lookup.node;if(!parent){throw new FS.ErrnoError(44)}var newname=PATH.basename(newpath);var errCode=FS.mayCreate(parent,newname);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.symlink){throw new FS.ErrnoError(63)}return parent.node_ops.symlink(parent,newname,oldpath)},rename(old_path,new_path){var old_dirname=PATH.dirname(old_path);var new_dirname=PATH.dirname(new_path);var old_name=PATH.basename(old_path);var new_name=PATH.basename(new_path);var lookup,old_dir,new_dir;lookup=FS.lookupPath(old_path,{parent:true});old_dir=lookup.node;lookup=FS.lookupPath(new_path,{parent:true});new_dir=lookup.node;if(!old_dir||!new_dir)throw new FS.ErrnoError(44);if(old_dir.mount!==new_dir.mount){throw new FS.ErrnoError(75)}var old_node=FS.lookupNode(old_dir,old_name);var relative=PATH_FS.relative(old_path,new_dirname);if(relative.charAt(0)!=="."){throw new FS.ErrnoError(28)}relative=PATH_FS.relative(new_path,old_dirname);if(relative.charAt(0)!=="."){throw new FS.ErrnoError(55)}var new_node;try{new_node=FS.lookupNode(new_dir,new_name)}catch(e){}if(old_node===new_node){return}var isdir=FS.isDir(old_node.mode);var errCode=FS.mayDelete(old_dir,old_name,isdir);if(errCode){throw new FS.ErrnoError(errCode)}errCode=new_node?FS.mayDelete(new_dir,new_name,isdir):FS.mayCreate(new_dir,new_name);if(errCode){throw new FS.ErrnoError(errCode)}if(!old_dir.node_ops.rename){throw new FS.ErrnoError(63)}if(FS.isMountpoint(old_node)||new_node&&FS.isMountpoint(new_node)){throw new FS.ErrnoError(10)}if(new_dir!==old_dir){errCode=FS.nodePermissions(old_dir,"w");if(errCode){throw new FS.ErrnoError(errCode)}}FS.hashRemoveNode(old_node);try{old_dir.node_ops.rename(old_node,new_dir,new_name);old_node.parent=new_dir}catch(e){throw e}finally{FS.hashAddNode(old_node)}},rmdir(path){var lookup=FS.lookupPath(path,{parent:true});var parent=lookup.node;var name=PATH.basename(path);var node=FS.lookupNode(parent,name);var errCode=FS.mayDelete(parent,name,true);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.rmdir){throw new FS.ErrnoError(63)}if(FS.isMountpoint(node)){throw new FS.ErrnoError(10)}parent.node_ops.rmdir(parent,name);FS.destroyNode(node)},readdir(path){var lookup=FS.lookupPath(path,{follow:true});var node=lookup.node;var readdir=FS.checkOpExists(node.node_ops.readdir,54);return readdir(node)},unlink(path){var lookup=FS.lookupPath(path,{parent:true});var parent=lookup.node;if(!parent){throw new FS.ErrnoError(44)}var name=PATH.basename(path);var node=FS.lookupNode(parent,name);var errCode=FS.mayDelete(parent,name,false);if(errCode){throw new FS.ErrnoError(errCode)}if(!parent.node_ops.unlink){throw new FS.ErrnoError(63)}if(FS.isMountpoint(node)){throw new FS.ErrnoError(10)}parent.node_ops.unlink(parent,name);FS.destroyNode(node)},readlink(path){var lookup=FS.lookupPath(path);var link=lookup.node;if(!link){throw new FS.ErrnoError(44)}if(!link.node_ops.readlink){throw new FS.ErrnoError(28)}return link.node_ops.readlink(link)},stat(path,dontFollow){var lookup=FS.lookupPath(path,{follow:!dontFollow});var node=lookup.node;var getattr=FS.checkOpExists(node.node_ops.getattr,63);return getattr(node)},lstat(path){return FS.stat(path,true)},chmod(path,mode,dontFollow){var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:!dontFollow});node=lookup.node}else{node=path}var setattr=FS.checkOpExists(node.node_ops.setattr,63);setattr(node,{mode:mode&4095|node.mode&~4095,ctime:Date.now(),dontFollow})},lchmod(path,mode){FS.chmod(path,mode,true)},fchmod(fd,mode){var stream=FS.getStreamChecked(fd);FS.chmod(stream.node,mode)},chown(path,uid,gid,dontFollow){var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:!dontFollow});node=lookup.node}else{node=path}var setattr=FS.checkOpExists(node.node_ops.setattr,63);setattr(node,{timestamp:Date.now(),dontFollow})},lchown(path,uid,gid){FS.chown(path,uid,gid,true)},fchown(fd,uid,gid){var stream=FS.getStreamChecked(fd);FS.chown(stream.node,uid,gid)},truncate(path,len){if(len<0){throw new FS.ErrnoError(28)}var node;if(typeof path=="string"){var lookup=FS.lookupPath(path,{follow:true});node=lookup.node}else{node=path}if(FS.isDir(node.mode)){throw new FS.ErrnoError(31)}if(!FS.isFile(node.mode)){throw new FS.ErrnoError(28)}var errCode=FS.nodePermissions(node,"w");if(errCode){throw new FS.ErrnoError(errCode)}var setattr=FS.checkOpExists(node.node_ops.setattr,63);setattr(node,{size:len,timestamp:Date.now()})},ftruncate(fd,len){var stream=FS.getStreamChecked(fd);if((stream.flags&2097155)===0){throw new FS.ErrnoError(28)}FS.truncate(stream.node,len)},utime(path,atime,mtime){var lookup=FS.lookupPath(path,{follow:true});var node=lookup.node;var setattr=FS.checkOpExists(node.node_ops.setattr,63);setattr(node,{atime,mtime})},open(path,flags,mode=438){if(path===""){throw new FS.ErrnoError(44)}flags=typeof flags=="string"?FS_modeStringToFlags(flags):flags;if(flags&64){mode=mode&4095|32768}else{mode=0}var node;var isDirPath;if(typeof path=="object"){node=path}else{isDirPath=path.endsWith("/");var lookup=FS.lookupPath(path,{follow:!(flags&131072),noent_okay:true});node=lookup.node;path=lookup.path}var created=false;if(flags&64){if(node){if(flags&128){throw new FS.ErrnoError(20)}}else if(isDirPath){throw new FS.ErrnoError(31)}else{node=FS.mknod(path,mode|511,0);created=true}}if(!node){throw new FS.ErrnoError(44)}if(FS.isChrdev(node.mode)){flags&=~512}if(flags&65536&&!FS.isDir(node.mode)){throw new FS.ErrnoError(54)}if(!created){var errCode=FS.mayOpen(node,flags);if(errCode){throw new FS.ErrnoError(errCode)}}if(flags&512&&!created){FS.truncate(node,0)}flags&=~(128|512|131072);var stream=FS.createStream({node,path:FS.getPath(node),flags,seekable:true,position:0,stream_ops:node.stream_ops,ungotten:[],error:false});if(stream.stream_ops.open){stream.stream_ops.open(stream)}if(created){FS.chmod(node,mode&511)}if(Module["logReadFiles"]&&!(flags&1)){if(!(path in FS.readFiles)){FS.readFiles[path]=1}}return stream},close(stream){if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if(stream.getdents)stream.getdents=null;try{if(stream.stream_ops.close){stream.stream_ops.close(stream)}}catch(e){throw e}finally{FS.closeStream(stream.fd)}stream.fd=null},isClosed(stream){return stream.fd===null},llseek(stream,offset,whence){if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if(!stream.seekable||!stream.stream_ops.llseek){throw new FS.ErrnoError(70)}if(whence!=0&&whence!=1&&whence!=2){throw new FS.ErrnoError(28)}stream.position=stream.stream_ops.llseek(stream,offset,whence);stream.ungotten=[];return stream.position},read(stream,buffer,offset,length,position){if(length<0||position<0){throw new FS.ErrnoError(28)}if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if((stream.flags&2097155)===1){throw new FS.ErrnoError(8)}if(FS.isDir(stream.node.mode)){throw new FS.ErrnoError(31)}if(!stream.stream_ops.read){throw new FS.ErrnoError(28)}var seeking=typeof position!="undefined";if(!seeking){position=stream.position}else if(!stream.seekable){throw new FS.ErrnoError(70)}var bytesRead=stream.stream_ops.read(stream,buffer,offset,length,position);if(!seeking)stream.position+=bytesRead;return bytesRead},write(stream,buffer,offset,length,position,canOwn){if(length<0||position<0){throw new FS.ErrnoError(28)}if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if((stream.flags&2097155)===0){throw new FS.ErrnoError(8)}if(FS.isDir(stream.node.mode)){throw new FS.ErrnoError(31)}if(!stream.stream_ops.write){throw new FS.ErrnoError(28)}if(stream.seekable&&stream.flags&1024){FS.llseek(stream,0,2)}var seeking=typeof position!="undefined";if(!seeking){position=stream.position}else if(!stream.seekable){throw new FS.ErrnoError(70)}var bytesWritten=stream.stream_ops.write(stream,buffer,offset,length,position,canOwn);if(!seeking)stream.position+=bytesWritten;return bytesWritten},allocate(stream,offset,length){if(FS.isClosed(stream)){throw new FS.ErrnoError(8)}if(offset<0||length<=0){throw new FS.ErrnoError(28)}if((stream.flags&2097155)===0){throw new FS.ErrnoError(8)}if(!FS.isFile(stream.node.mode)&&!FS.isDir(stream.node.mode)){throw new FS.ErrnoError(43)}if(!stream.stream_ops.allocate){throw new FS.ErrnoError(138)}stream.stream_ops.allocate(stream,offset,length)},mmap(stream,length,position,prot,flags){if((prot&2)!==0&&(flags&2)===0&&(stream.flags&2097155)!==2){throw new FS.ErrnoError(2)}if((stream.flags&2097155)===1){throw new FS.ErrnoError(2)}if(!stream.stream_ops.mmap){throw new FS.ErrnoError(43)}if(!length){throw new FS.ErrnoError(28)}return stream.stream_ops.mmap(stream,length,position,prot,flags)},msync(stream,buffer,offset,length,mmapFlags){if(!stream.stream_ops.msync){return 0}return stream.stream_ops.msync(stream,buffer,offset,length,mmapFlags)},ioctl(stream,cmd,arg){if(!stream.stream_ops.ioctl){throw new FS.ErrnoError(59)}return stream.stream_ops.ioctl(stream,cmd,arg)},readFile(path,opts={}){opts.flags=opts.flags||0;opts.encoding=opts.encoding||"binary";if(opts.encoding!=="utf8"&&opts.encoding!=="binary"){throw new Error(`Invalid encoding type "${opts.encoding}"`)}var ret;var stream=FS.open(path,opts.flags);var stat=FS.stat(path);var length=stat.size;var buf=new Uint8Array(length);FS.read(stream,buf,0,length,0);if(opts.encoding==="utf8"){ret=UTF8ArrayToString(buf)}else if(opts.encoding==="binary"){ret=buf}FS.close(stream);return ret},writeFile(path,data,opts={}){opts.flags=opts.flags||577;var stream=FS.open(path,opts.flags,opts.mode);if(typeof data=="string"){var buf=new Uint8Array(lengthBytesUTF8(data)+1);var actualNumBytes=stringToUTF8Array(data,buf,0,buf.length);FS.write(stream,buf,0,actualNumBytes,undefined,opts.canOwn)}else if(ArrayBuffer.isView(data)){FS.write(stream,data,0,data.byteLength,undefined,opts.canOwn)}else{throw new Error("Unsupported data type")}FS.close(stream)},cwd:()=>FS.currentPath,chdir(path){var lookup=FS.lookupPath(path,{follow:true});if(lookup.node===null){throw new FS.ErrnoError(44)}if(!FS.isDir(lookup.node.mode)){throw new FS.ErrnoError(54)}var errCode=FS.nodePermissions(lookup.node,"x");if(errCode){throw new FS.ErrnoError(errCode)}FS.currentPath=lookup.path},createDefaultDirectories(){FS.mkdir("/tmp");FS.mkdir("/home");FS.mkdir("/home/web_user")},createDefaultDevices(){FS.mkdir("/dev");FS.registerDevice(FS.makedev(1,3),{read:()=>0,write:(stream,buffer,offset,length,pos)=>length,llseek:()=>0});FS.mkdev("/dev/null",FS.makedev(1,3));TTY.register(FS.makedev(5,0),TTY.default_tty_ops);TTY.register(FS.makedev(6,0),TTY.default_tty1_ops);FS.mkdev("/dev/tty",FS.makedev(5,0));FS.mkdev("/dev/tty1",FS.makedev(6,0));var randomBuffer=new Uint8Array(1024),randomLeft=0;var randomByte=()=>{if(randomLeft===0){randomFill(randomBuffer);randomLeft=randomBuffer.byteLength}return randomBuffer[--randomLeft]};FS.createDevice("/dev","random",randomByte);FS.createDevice("/dev","urandom",randomByte);FS.mkdir("/dev/shm");FS.mkdir("/dev/shm/tmp")},createSpecialDirectories(){FS.mkdir("/proc");var proc_self=FS.mkdir("/proc/self");FS.mkdir("/proc/self/fd");FS.mount({mount(){var node=FS.createNode(proc_self,"fd",16895,73);node.stream_ops={llseek:MEMFS.stream_ops.llseek};node.node_ops={lookup(parent,name){var fd=+name;var stream=FS.getStreamChecked(fd);var ret={parent:null,mount:{mountpoint:"fake"},node_ops:{readlink:()=>stream.path},id:fd+1};ret.parent=ret;return ret},readdir(){return Array.from(FS.streams.entries()).filter(([k,v])=>v).map(([k,v])=>k.toString())}};return node}},{},"/proc/self/fd")},createStandardStreams(input,output,error){if(input){FS.createDevice("/dev","stdin",input)}else{FS.symlink("/dev/tty","/dev/stdin")}if(output){FS.createDevice("/dev","stdout",null,output)}else{FS.symlink("/dev/tty","/dev/stdout")}if(error){FS.createDevice("/dev","stderr",null,error)}else{FS.symlink("/dev/tty1","/dev/stderr")}var stdin=FS.open("/dev/stdin",0);var stdout=FS.open("/dev/stdout",1);var stderr=FS.open("/dev/stderr",1)},staticInit(){FS.nameTable=new Array(4096);FS.mount(MEMFS,{},"/");FS.createDefaultDirectories();FS.createDefaultDevices();FS.createSpecialDirectories();FS.filesystems={MEMFS}},init(input,output,error){FS.initialized=true;input??=Module["stdin"];output??=Module["stdout"];error??=Module["stderr"];FS.createStandardStreams(input,output,error)},quit(){FS.initialized=false;for(var i=0;i<FS.streams.length;i++){var stream=FS.streams[i];if(!stream){continue}FS.close(stream)}},findObject(path,dontResolveLastLink){var ret=FS.analyzePath(path,dontResolveLastLink);if(!ret.exists){return null}return ret.object},analyzePath(path,dontResolveLastLink){try{var lookup=FS.lookupPath(path,{follow:!dontResolveLastLink});path=lookup.path}catch(e){}var ret={isRoot:false,exists:false,error:0,name:null,path:null,object:null,parentExists:false,parentPath:null,parentObject:null};try{var lookup=FS.lookupPath(path,{parent:true});ret.parentExists=true;ret.parentPath=lookup.path;ret.parentObject=lookup.node;ret.name=PATH.basename(path);lookup=FS.lookupPath(path,{follow:!dontResolveLastLink});ret.exists=true;ret.path=lookup.path;ret.object=lookup.node;ret.name=lookup.node.name;ret.isRoot=lookup.path==="/"}catch(e){ret.error=e.errno}return ret},createPath(parent,path,canRead,canWrite){parent=typeof parent=="string"?parent:FS.getPath(parent);var parts=path.split("/").reverse();while(parts.length){var part=parts.pop();if(!part)continue;var current=PATH.join2(parent,part);try{FS.mkdir(current)}catch(e){}parent=current}return current},createFile(parent,name,properties,canRead,canWrite){var path=PATH.join2(typeof parent=="string"?parent:FS.getPath(parent),name);var mode=FS_getMode(canRead,canWrite);return FS.create(path,mode)},createDataFile(parent,name,data,canRead,canWrite,canOwn){var path=name;if(parent){parent=typeof parent=="string"?parent:FS.getPath(parent);path=name?PATH.join2(parent,name):parent}var mode=FS_getMode(canRead,canWrite);var node=FS.create(path,mode);if(data){if(typeof data=="string"){var arr=new Array(data.length);for(var i=0,len=data.length;i<len;++i)arr[i]=data.charCodeAt(i);data=arr}FS.chmod(node,mode|146);var stream=FS.open(node,577);FS.write(stream,data,0,data.length,0,canOwn);FS.close(stream);FS.chmod(node,mode)}},createDevice(parent,name,input,output){var path=PATH.join2(typeof parent=="string"?parent:FS.getPath(parent),name);var mode=FS_getMode(!!input,!!output);FS.createDevice.major??=64;var dev=FS.makedev(FS.createDevice.major++,0);FS.registerDevice(dev,{open(stream){stream.seekable=false},close(stream){if(output?.buffer?.length){output(10)}},read(stream,buffer,offset,length,pos){var bytesRead=0;for(var i=0;i<length;i++){var result;try{result=input()}catch(e){throw new FS.ErrnoError(29)}if(result===undefined&&bytesRead===0){throw new FS.ErrnoError(6)}if(result===null||result===undefined)break;bytesRead++;buffer[offset+i]=result}if(bytesRead){stream.node.atime=Date.now()}return bytesRead},write(stream,buffer,offset,length,pos){for(var i=0;i<length;i++){try{output(buffer[offset+i])}catch(e){throw new FS.ErrnoError(29)}}if(length){stream.node.mtime=stream.node.ctime=Date.now()}return i}});return FS.mkdev(path,mode,dev)},forceLoadFile(obj){if(obj.isDevice||obj.isFolder||obj.link||obj.contents)return true;if(typeof XMLHttpRequest!="undefined"){throw new Error("Lazy loading should have been performed (contents set) in createLazyFile, but it was not. Lazy loading only works in web workers. Use --embed-file or --preload-file in emcc on the main thread.")}else{try{obj.contents=readBinary(obj.url);obj.usedBytes=obj.contents.length}catch(e){throw new FS.ErrnoError(29)}}},createLazyFile(parent,name,url,canRead,canWrite){class LazyUint8Array{lengthKnown=false;chunks=[];get(idx){if(idx>this.length-1||idx<0){return undefined}var chunkOffset=idx%this.chunkSize;var chunkNum=idx/this.chunkSize|0;return this.getter(chunkNum)[chunkOffset]}setDataGetter(getter){this.getter=getter}cacheLength(){var xhr=new XMLHttpRequest;xhr.open("HEAD",url,false);xhr.send(null);if(!(xhr.status>=200&&xhr.status<300||xhr.status===304))throw new Error("Couldn't load "+url+". Status: "+xhr.status);var datalength=Number(xhr.getResponseHeader("Content-length"));var header;var hasByteServing=(header=xhr.getResponseHeader("Accept-Ranges"))&&header==="bytes";var usesGzip=(header=xhr.getResponseHeader("Content-Encoding"))&&header==="gzip";var chunkSize=1024*1024;if(!hasByteServing)chunkSize=datalength;var doXHR=(from,to)=>{if(from>to)throw new Error("invalid range ("+from+", "+to+") or no bytes requested!");if(to>datalength-1)throw new Error("only "+datalength+" bytes available! programmer error!");var xhr=new XMLHttpRequest;xhr.open("GET",url,false);if(datalength!==chunkSize)xhr.setRequestHeader("Range","bytes="+from+"-"+to);xhr.responseType="arraybuffer";if(xhr.overrideMimeType){xhr.overrideMimeType("text/plain; charset=x-user-defined")}xhr.send(null);if(!(xhr.status>=200&&xhr.status<300||xhr.status===304))throw new Error("Couldn't load "+url+". Status: "+xhr.status);if(xhr.response!==undefined){return new Uint8Array(xhr.response||[])}return intArrayFromString(xhr.responseText||"",true)};var lazyArray=this;lazyArray.setDataGetter(chunkNum=>{var start=chunkNum*chunkSize;var end=(chunkNum+1)*chunkSize-1;end=Math.min(end,datalength-1);if(typeof lazyArray.chunks[chunkNum]=="undefined"){lazyArray.chunks[chunkNum]=doXHR(start,end)}if(typeof lazyArray.chunks[chunkNum]=="undefined")throw new Error("doXHR failed!");return lazyArray.chunks[chunkNum]});if(usesGzip||!datalength){chunkSize=datalength=1;datalength=this.getter(0).length;chunkSize=datalength;out("LazyFiles on gzip forces download of the whole file when length is accessed")}this._length=datalength;this._chunkSize=chunkSize;this.lengthKnown=true}get length(){if(!this.lengthKnown){this.cacheLength()}return this._length}get chunkSize(){if(!this.lengthKnown){this.cacheLength()}return this._chunkSize}}if(typeof XMLHttpRequest!="undefined"){if(!ENVIRONMENT_IS_WORKER)throw"Cannot do synchronous binary XHRs outside webworkers in modern browsers. Use --embed-file or --preload-file in emcc";var lazyArray=new LazyUint8Array;var properties={isDevice:false,contents:lazyArray}}else{var properties={isDevice:false,url}}var node=FS.createFile(parent,name,properties,canRead,canWrite);if(properties.contents){node.contents=properties.contents}else if(properties.url){node.contents=null;node.url=properties.url}Object.defineProperties(node,{usedBytes:{get:function(){return this.contents.length}}});var stream_ops={};var keys=Object.keys(node.stream_ops);keys.forEach(key=>{var fn=node.stream_ops[key];stream_ops[key]=(...args)=>{FS.forceLoadFile(node);return fn(...args)}});function writeChunks(stream,buffer,offset,length,position){var contents=stream.node.contents;if(position>=contents.length)return 0;var size=Math.min(contents.length-position,length);if(contents.slice){for(var i=0;i<size;i++){buffer[offset+i]=contents[position+i]}}else{for(var i=0;i<size;i++){buffer[offset+i]=contents.get(position+i)}}return size}stream_ops.read=(stream,buffer,offset,length,position)=>{FS.forceLoadFile(node);return writeChunks(stream,buffer,offset,length,position)};stream_ops.mmap=(stream,length,position,prot,flags)=>{FS.forceLoadFile(node);var ptr=mmapAlloc(length);if(!ptr){throw new FS.ErrnoError(48)}writeChunks(stream,HEAP8,ptr,length,position);return{ptr,allocated:true}};node.stream_ops=stream_ops;return node}};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";var SYSCALLS={DEFAULT_POLLMASK:5,calculateAt(dirfd,path,allowEmpty){if(PATH.isAbs(path)){return path}var dir;if(dirfd===-100){dir=FS.cwd()}else{var dirstream=SYSCALLS.getStreamFromFD(dirfd);dir=dirstream.path}if(path.length==0){if(!allowEmpty){throw new FS.ErrnoError(44)}return dir}return dir+"/"+path},writeStat(buf,stat){HEAP32[buf>>2]=stat.dev;HEAP32[buf+4>>2]=stat.mode;HEAPU32[buf+8>>2]=stat.nlink;HEAP32[buf+12>>2]=stat.uid;HEAP32[buf+16>>2]=stat.gid;HEAP32[buf+20>>2]=stat.rdev;HEAP64[buf+24>>3]=BigInt(stat.size);HEAP32[buf+32>>2]=4096;HEAP32[buf+36>>2]=stat.blocks;var atime=stat.atime.getTime();var mtime=stat.mtime.getTime();var ctime=stat.ctime.getTime();HEAP64[buf+40>>3]=BigInt(Math.floor(atime/1e3));HEAPU32[buf+48>>2]=atime%1e3*1e3*1e3;HEAP64[buf+56>>3]=BigInt(Math.floor(mtime/1e3));HEAPU32[buf+64>>2]=mtime%1e3*1e3*1e3;HEAP64[buf+72>>3]=BigInt(Math.floor(ctime/1e3));HEAPU32[buf+80>>2]=ctime%1e3*1e3*1e3;HEAP64[buf+88>>3]=BigInt(stat.ino);return 0},writeStatFs(buf,stats){HEAP32[buf+4>>2]=stats.bsize;HEAP32[buf+40>>2]=stats.bsize;HEAP32[buf+8>>2]=stats.blocks;HEAP32[buf+12>>2]=stats.bfree;HEAP32[buf+16>>2]=stats.bavail;HEAP32[buf+20>>2]=stats.files;HEAP32[buf+24>>2]=stats.ffree;HEAP32[buf+28>>2]=stats.fsid;HEAP32[buf+44>>2]=stats.flags;HEAP32[buf+36>>2]=stats.namelen},doMsync(addr,stream,len,flags,offset){if(!FS.isFile(stream.node.mode)){throw new FS.ErrnoError(43)}if(flags&2){return 0}var buffer=HEAPU8.slice(addr,addr+len);FS.msync(stream,buffer,offset,len,flags)},getStreamFromFD(fd){var stream=FS.getStreamChecked(fd);return stream},varargs:undefined,getStr(ptr){var ret=UTF8ToString(ptr);return ret}};function ___syscall_fcntl64(fd,cmd,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(fd);switch(cmd){case 0:{var arg=syscallGetVarargI();if(arg<0){return-28}while(FS.streams[arg]){arg++}var newStream;newStream=FS.dupStream(stream,arg);return newStream.fd}case 1:case 2:return 0;case 3:return stream.flags;case 4:{var arg=syscallGetVarargI();stream.flags|=arg;return 0}case 12:{var arg=syscallGetVarargP();var offset=0;HEAP16[arg+offset>>1]=2;return 0}case 13:case 14:return 0}return-28}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_fstat64(fd,buf){try{var stream=SYSCALLS.getStreamFromFD(fd);return SYSCALLS.writeStat(buf,FS.stat(stream.path))}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);function ___syscall_getcwd(buf,size){try{if(size===0)return-28;var cwd=FS.cwd();var cwdLengthInBytes=lengthBytesUTF8(cwd)+1;if(size<cwdLengthInBytes)return-68;stringToUTF8(cwd,buf,size);return cwdLengthInBytes}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_getdents64(fd,dirp,count){try{var stream=SYSCALLS.getStreamFromFD(fd);stream.getdents||=FS.readdir(stream.path);var struct_size=280;var pos=0;var off=FS.llseek(stream,0,1);var startIdx=Math.floor(off/struct_size);var endIdx=Math.min(stream.getdents.length,startIdx+Math.floor(count/struct_size));for(var idx=startIdx;idx<endIdx;idx++){var id;var type;var name=stream.getdents[idx];if(name==="."){id=stream.node.id;type=4}else if(name===".."){var lookup=FS.lookupPath(stream.path,{parent:true});id=lookup.node.id;type=4}else{var child;try{child=FS.lookupNode(stream.node,name)}catch(e){if(e?.errno===28){continue}throw e}id=child.id;type=FS.isChrdev(child.mode)?2:FS.isDir(child.mode)?4:FS.isLink(child.mode)?10:8}HEAP64[dirp+pos>>3]=BigInt(id);HEAP64[dirp+pos+8>>3]=BigInt((idx+1)*struct_size);HEAP16[dirp+pos+16>>1]=280;HEAP8[dirp+pos+18]=type;stringToUTF8(name,dirp+pos+19,256);pos+=struct_size}FS.llseek(stream,idx*struct_size,0);return pos}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_ioctl(fd,op,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(fd);switch(op){case 21509:{if(!stream.tty)return-59;return 0}case 21505:{if(!stream.tty)return-59;if(stream.tty.ops.ioctl_tcgets){var termios=stream.tty.ops.ioctl_tcgets(stream);var argp=syscallGetVarargP();HEAP32[argp>>2]=termios.c_iflag||0;HEAP32[argp+4>>2]=termios.c_oflag||0;HEAP32[argp+8>>2]=termios.c_cflag||0;HEAP32[argp+12>>2]=termios.c_lflag||0;for(var i=0;i<32;i++){HEAP8[argp+i+17]=termios.c_cc[i]||0}return 0}return 0}case 21510:case 21511:case 21512:{if(!stream.tty)return-59;return 0}case 21506:case 21507:case 21508:{if(!stream.tty)return-59;if(stream.tty.ops.ioctl_tcsets){var argp=syscallGetVarargP();var c_iflag=HEAP32[argp>>2];var c_oflag=HEAP32[argp+4>>2];var c_cflag=HEAP32[argp+8>>2];var c_lflag=HEAP32[argp+12>>2];var c_cc=[];for(var i=0;i<32;i++){c_cc.push(HEAP8[argp+i+17])}return stream.tty.ops.ioctl_tcsets(stream.tty,op,{c_iflag,c_oflag,c_cflag,c_lflag,c_cc})}return 0}case 21519:{if(!stream.tty)return-59;var argp=syscallGetVarargP();HEAP32[argp>>2]=0;return 0}case 21520:{if(!stream.tty)return-59;return-28}case 21531:{var argp=syscallGetVarargP();return FS.ioctl(stream,op,argp)}case 21523:{if(!stream.tty)return-59;if(stream.tty.ops.ioctl_tiocgwinsz){var winsize=stream.tty.ops.ioctl_tiocgwinsz(stream.tty);var argp=syscallGetVarargP();HEAP16[argp>>1]=winsize[0];HEAP16[argp+2>>1]=winsize[1]}return 0}case 21524:{if(!stream.tty)return-59;return 0}case 21515:{if(!stream.tty)return-59;return 0}default:return-28}}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_lstat64(path,buf){try{path=SYSCALLS.getStr(path);return SYSCALLS.writeStat(buf,FS.lstat(path))}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_mkdirat(dirfd,path,mode){try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);FS.mkdir(path,mode,0);return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_newfstatat(dirfd,path,buf,flags){try{path=SYSCALLS.getStr(path);var nofollow=flags&256;var allowEmpty=flags&4096;flags=flags&~6400;path=SYSCALLS.calculateAt(dirfd,path,allowEmpty);return SYSCALLS.writeStat(buf,nofollow?FS.lstat(path):FS.stat(path))}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_openat(dirfd,path,flags,varargs){SYSCALLS.varargs=varargs;try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);var mode=varargs?syscallGetVarargI():0;return FS.open(path,flags,mode).fd}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_readlinkat(dirfd,path,buf,bufsize){try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);if(bufsize<=0)return-28;var ret=FS.readlink(path);var len=Math.min(bufsize,lengthBytesUTF8(ret));var endChar=HEAP8[buf+len];stringToUTF8(ret,buf,bufsize+1);HEAP8[buf+len]=endChar;return len}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_rmdir(path){try{path=SYSCALLS.getStr(path);FS.rmdir(path);return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_stat64(path,buf){try{path=SYSCALLS.getStr(path);return SYSCALLS.writeStat(buf,FS.stat(path))}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function ___syscall_unlinkat(dirfd,path,flags){try{path=SYSCALLS.getStr(path);path=SYSCALLS.calculateAt(dirfd,path);if(flags===0){FS.unlink(path)}else if(flags===512){FS.rmdir(path)}else{abort("Invalid flags passed to unlinkat")}return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}var __abort_js=()=>abort("");var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>num<INT53_MIN||num>INT53_MAX?NaN:Number(num);function __gmtime_js(time,tmPtr){time=bigintToI53Checked(time);var date=new Date(time*1e3);HEAP32[tmPtr>>2]=date.getUTCSeconds();HEAP32[tmPtr+4>>2]=date.getUTCMinutes();HEAP32[tmPtr+8>>2]=date.getUTCHours();HEAP32[tmPtr+12>>2]=date.getUTCDate();HEAP32[tmPtr+16>>2]=date.getUTCMonth();HEAP32[tmPtr+20>>2]=date.getUTCFullYear()-1900;HEAP32[tmPtr+24>>2]=date.getUTCDay();var start=Date.UTC(date.getUTCFullYear(),0,1,0,0,0,0);var yday=(date.getTime()-start)/(1e3*60*60*24)|0;HEAP32[tmPtr+28>>2]=yday}var isLeapYear=year=>year%4===0&&(year%100!==0||year%400===0);var MONTH_DAYS_LEAP_CUMULATIVE=[0,31,60,91,121,152,182,213,244,274,305,335];var MONTH_DAYS_REGULAR_CUMULATIVE=[0,31,59,90,120,151,181,212,243,273,304,334];var ydayFromDate=date=>{var leap=isLeapYear(date.getFullYear());var monthDaysCumulative=leap?MONTH_DAYS_LEAP_CUMULATIVE:MONTH_DAYS_REGULAR_CUMULATIVE;var yday=monthDaysCumulative[date.getMonth()]+date.getDate()-1;return yday};function __localtime_js(time,tmPtr){time=bigintToI53Checked(time);var date=new Date(time*1e3);HEAP32[tmPtr>>2]=date.getSeconds();HEAP32[tmPtr+4>>2]=date.getMinutes();HEAP32[tmPtr+8>>2]=date.getHours();HEAP32[tmPtr+12>>2]=date.getDate();HEAP32[tmPtr+16>>2]=date.getMonth();HEAP32[tmPtr+20>>2]=date.getFullYear()-1900;HEAP32[tmPtr+24>>2]=date.getDay();var yday=ydayFromDate(date)|0;HEAP32[tmPtr+28>>2]=yday;HEAP32[tmPtr+36>>2]=-(date.getTimezoneOffset()*60);var start=new Date(date.getFullYear(),0,1);var summerOffset=new Date(date.getFullYear(),6,1).getTimezoneOffset();var winterOffset=start.getTimezoneOffset();var dst=(summerOffset!=winterOffset&&date.getTimezoneOffset()==Math.min(winterOffset,summerOffset))|0;HEAP32[tmPtr+32>>2]=dst}var __mktime_js=function(tmPtr){var ret=(()=>{var date=new Date(HEAP32[tmPtr+20>>2]+1900,HEAP32[tmPtr+16>>2],HEAP32[tmPtr+12>>2],HEAP32[tmPtr+8>>2],HEAP32[tmPtr+4>>2],HEAP32[tmPtr>>2],0);var dst=HEAP32[tmPtr+32>>2];var guessedOffset=date.getTimezoneOffset();var start=new Date(date.getFullYear(),0,1);var summerOffset=new Date(date.getFullYear(),6,1).getTimezoneOffset();var winterOffset=start.getTimezoneOffset();var dstOffset=Math.min(winterOffset,summerOffset);if(dst<0){HEAP32[tmPtr+32>>2]=Number(summerOffset!=winterOffset&&dstOffset==guessedOffset)}else if(dst>0!=(dstOffset==guessedOffset)){var nonDstOffset=Math.max(winterOffset,summerOffset);var trueOffset=dst>0?dstOffset:nonDstOffset;date.setTime(date.getTime()+(trueOffset-guessedOffset)*6e4)}HEAP32[tmPtr+24>>2]=date.getDay();var yday=ydayFromDate(date)|0;HEAP32[tmPtr+28>>2]=yday;HEAP32[tmPtr>>2]=date.getSeconds();HEAP32[tmPtr+4>>2]=date.getMinutes();HEAP32[tmPtr+8>>2]=date.getHours();HEAP32[tmPtr+12>>2]=date.getDate();HEAP32[tmPtr+16>>2]=date.getMonth();HEAP32[tmPtr+20>>2]=date.getYear();var timeMs=date.getTime();if(isNaN(timeMs)){return-1}return timeMs/1e3})();return BigInt(ret)};function __mmap_js(len,prot,flags,fd,offset,allocated,addr){offset=bigintToI53Checked(offset);try{if(isNaN(offset))return 61;var stream=SYSCALLS.getStreamFromFD(fd);var res=FS.mmap(stream,len,offset,prot,flags);var ptr=res.ptr;HEAP32[allocated>>2]=res.allocated;HEAPU32[addr>>2]=ptr;return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}function __munmap_js(addr,len,prot,flags,fd,offset){offset=bigintToI53Checked(offset);try{var stream=SYSCALLS.getStreamFromFD(fd);if(prot&2){SYSCALLS.doMsync(addr,stream,len,flags,offset)}}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return-e.errno}}var __tzset_js=(timezone,daylight,std_name,dst_name)=>{var currentYear=(new Date).getFullYear();var winter=new Date(currentYear,0,1);var summer=new Date(currentYear,6,1);var winterOffset=winter.getTimezoneOffset();var summerOffset=summer.getTimezoneOffset();var stdTimezoneOffset=Math.max(winterOffset,summerOffset);HEAPU32[timezone>>2]=stdTimezoneOffset*60;HEAP32[daylight>>2]=Number(winterOffset!=summerOffset);var extractZone=timezoneOffset=>{var sign=timezoneOffset>=0?"-":"+";var absOffset=Math.abs(timezoneOffset);var hours=String(Math.floor(absOffset/60)).padStart(2,"0");var minutes=String(absOffset%60).padStart(2,"0");return`UTC${sign}${hours}${minutes}`};var winterName=extractZone(winterOffset);var summerName=extractZone(summerOffset);if(summerOffset<winterOffset){stringToUTF8(winterName,std_name,17);stringToUTF8(summerName,dst_name,17)}else{stringToUTF8(winterName,dst_name,17);stringToUTF8(summerName,std_name,17)}};var _emscripten_get_now=()=>performance.now();var _emscripten_date_now=()=>Date.now();var nowIsMonotonic=1;var checkWasiClock=clock_id=>clock_id>=0&&clock_id<=3;function _clock_time_get(clk_id,ignored_precision,ptime){ignored_precision=bigintToI53Checked(ignored_precision);if(!checkWasiClock(clk_id)){return 28}var now;if(clk_id===0){now=_emscripten_date_now()}else if(nowIsMonotonic){now=_emscripten_get_now()}else{return 52}var nsec=Math.round(now*1e3*1e3);HEAP64[ptime>>3]=BigInt(nsec);return 0}var readEmAsmArgsArray=[];var readEmAsmArgs=(sigPtr,buf)=>{readEmAsmArgsArray.length=0;var ch;while(ch=HEAPU8[sigPtr++]){var wide=ch!=105;wide&=ch!=112;buf+=wide&&buf%8?4:0;readEmAsmArgsArray.push(ch==112?HEAPU32[buf>>2]:ch==106?HEAP64[buf>>3]:ch==105?HEAP32[buf>>2]:HEAPF64[buf>>3]);buf+=wide?8:4}return readEmAsmArgsArray};var runEmAsmFunction=(code,sigPtr,argbuf)=>{var args=readEmAsmArgs(sigPtr,argbuf);return ASM_CONSTS[code](...args)};var _emscripten_asm_const_int=(code,sigPtr,argbuf)=>runEmAsmFunction(code,sigPtr,argbuf);var getHeapMax=()=>2147483648;var _emscripten_get_heap_max=()=>getHeapMax();var growMemory=size=>{var b=wasmMemory.buffer;var pages=(size-b.byteLength+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};var ENV={};var getExecutableName=()=>thisProgram||"./this.program";var getEnvStrings=()=>{if(!getEnvStrings.strings){var lang=(typeof navigator=="object"&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8";var env={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:lang,_:getExecutableName()};for(var x in ENV){if(ENV[x]===undefined)delete env[x];else env[x]=ENV[x]}var strings=[];for(var x in env){strings.push(`${x}=${env[x]}`)}getEnvStrings.strings=strings}return getEnvStrings.strings};var stringToAscii=(str,buffer)=>{for(var i=0;i<str.length;++i){HEAP8[buffer++]=str.charCodeAt(i)}HEAP8[buffer]=0};var _environ_get=(__environ,environ_buf)=>{var bufSize=0;getEnvStrings().forEach((string,i)=>{var ptr=environ_buf+bufSize;HEAPU32[__environ+i*4>>2]=ptr;stringToAscii(string,ptr);bufSize+=string.length+1});return 0};var _environ_sizes_get=(penviron_count,penviron_buf_size)=>{var strings=getEnvStrings();HEAPU32[penviron_count>>2]=strings.length;var bufSize=0;strings.forEach(string=>bufSize+=string.length+1);HEAPU32[penviron_buf_size>>2]=bufSize;return 0};var runtimeKeepaliveCounter=0;var keepRuntimeAlive=()=>noExitRuntime||runtimeKeepaliveCounter>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var exitJS=(status,implicit)=>{EXITSTATUS=status;_proc_exit(status)};var _exit=exitJS;function _fd_close(fd){try{var stream=SYSCALLS.getStreamFromFD(fd);FS.close(stream);return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return e.errno}}var doReadv=(stream,iov,iovcnt,offset)=>{var ret=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>2];var len=HEAPU32[iov+4>>2];iov+=8;var curr=FS.read(stream,HEAP8,ptr,len,offset);if(curr<0)return-1;ret+=curr;if(curr<len)break;if(typeof offset!="undefined"){offset+=curr}}return ret};function _fd_read(fd,iov,iovcnt,pnum){try{var stream=SYSCALLS.getStreamFromFD(fd);var num=doReadv(stream,iov,iovcnt);HEAPU32[pnum>>2]=num;return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return e.errno}}function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);try{if(isNaN(offset))return 61;var stream=SYSCALLS.getStreamFromFD(fd);FS.llseek(stream,offset,whence);HEAP64[newOffset>>3]=BigInt(stream.position);if(stream.getdents&&offset===0&&whence===0)stream.getdents=null;return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return e.errno}}var doWritev=(stream,iov,iovcnt,offset)=>{var ret=0;for(var i=0;i<iovcnt;i++){var ptr=HEAPU32[iov>>2];var len=HEAPU32[iov+4>>2];iov+=8;var curr=FS.write(stream,HEAP8,ptr,len,offset);if(curr<0)return-1;ret+=curr;if(curr<len){break}if(typeof offset!="undefined"){offset+=curr}}return ret};function _fd_write(fd,iov,iovcnt,pnum){try{var stream=SYSCALLS.getStreamFromFD(fd);var num=doWritev(stream,iov,iovcnt);HEAPU32[pnum>>2]=num;return 0}catch(e){if(typeof FS=="undefined"||!(e.name==="ErrnoError"))throw e;return e.errno}}var getCFunc=ident=>{var func=Module["_"+ident];return func};var writeArrayToMemory=(array,buffer)=>{HEAP8.set(array,buffer)};var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var ccall=(ident,returnType,argTypes,args,opts)=>{var toC={string:str=>{var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=stringToUTF8OnStack(str)}return ret},array:arr=>{var ret=stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}};function convertReturnValue(ret){if(returnType==="string"){return UTF8ToString(ret)}if(returnType==="boolean")return Boolean(ret);return ret}var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func(...cArgs);function onDone(ret){if(stack!==0)stackRestore(stack);return convertReturnValue(ret)}ret=onDone(ret);return ret};var FS_createPath=FS.createPath;var FS_unlink=path=>FS.unlink(path);var FS_createLazyFile=FS.createLazyFile;var FS_createDevice=FS.createDevice;FS.createPreloadedFile=FS_createPreloadedFile;FS.staticInit();Module["FS_createPath"]=FS.createPath;Module["FS_createDataFile"]=FS.createDataFile;Module["FS_createPreloadedFile"]=FS.createPreloadedFile;Module["FS_unlink"]=FS.unlink;Module["FS_createLazyFile"]=FS.createLazyFile;Module["FS_createDevice"]=FS.createDevice;MEMFS.doesNotExistError=new FS.ErrnoError(44);MEMFS.doesNotExistError.stack="<generic error, no stack>";var wasmImports={a:___cxa_throw,d:___syscall_fcntl64,z:___syscall_fstat64,o:___syscall_getcwd,s:___syscall_getdents64,H:___syscall_ioctl,w:___syscall_lstat64,t:___syscall_mkdirat,x:___syscall_newfstatat,g:___syscall_openat,n:___syscall_readlinkat,p:___syscall_rmdir,y:___syscall_stat64,r:___syscall_unlinkat,l:__abort_js,A:__gmtime_js,B:__localtime_js,C:__mktime_js,u:__mmap_js,v:__munmap_js,i:__tzset_js,E:_clock_time_get,m:_emscripten_asm_const_int,D:_emscripten_date_now,F:_emscripten_get_heap_max,c:_emscripten_get_now,q:_emscripten_resize_heap,j:_environ_get,k:_environ_sizes_get,b:_exit,e:_fd_close,h:_fd_read,G:_fd_seek,f:_fd_write};var wasmExports;createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["J"])();var _MyPrint=Module["_MyPrint"]=a0=>(_MyPrint=Module["_MyPrint"]=wasmExports["K"])(a0);var _CopyHeap=Module["_CopyHeap"]=(a0,a1,a2)=>(_CopyHeap=Module["_CopyHeap"]=wasmExports["L"])(a0,a1,a2);var _SherpaOnnxCreateOnlineRecognizer=Module["_SherpaOnnxCreateOnlineRecognizer"]=a0=>(_SherpaOnnxCreateOnlineRecognizer=Module["_SherpaOnnxCreateOnlineRecognizer"]=wasmExports["M"])(a0);var _SherpaOnnxDestroyOnlineRecognizer=Module["_SherpaOnnxDestroyOnlineRecognizer"]=a0=>(_SherpaOnnxDestroyOnlineRecognizer=Module["_SherpaOnnxDestroyOnlineRecognizer"]=wasmExports["N"])(a0);var _SherpaOnnxCreateOnlineStream=Module["_SherpaOnnxCreateOnlineStream"]=a0=>(_SherpaOnnxCreateOnlineStream=Module["_SherpaOnnxCreateOnlineStream"]=wasmExports["O"])(a0);var _SherpaOnnxDestroyOnlineStream=Module["_SherpaOnnxDestroyOnlineStream"]=a0=>(_SherpaOnnxDestroyOnlineStream=Module["_SherpaOnnxDestroyOnlineStream"]=wasmExports["P"])(a0);var _SherpaOnnxOnlineStreamAcceptWaveform=Module["_SherpaOnnxOnlineStreamAcceptWaveform"]=(a0,a1,a2,a3)=>(_SherpaOnnxOnlineStreamAcceptWaveform=Module["_SherpaOnnxOnlineStreamAcceptWaveform"]=wasmExports["Q"])(a0,a1,a2,a3);var _SherpaOnnxIsOnlineStreamReady=Module["_SherpaOnnxIsOnlineStreamReady"]=(a0,a1)=>(_SherpaOnnxIsOnlineStreamReady=Module["_SherpaOnnxIsOnlineStreamReady"]=wasmExports["R"])(a0,a1);var _SherpaOnnxDecodeOnlineStream=Module["_SherpaOnnxDecodeOnlineStream"]=(a0,a1)=>(_SherpaOnnxDecodeOnlineStream=Module["_SherpaOnnxDecodeOnlineStream"]=wasmExports["S"])(a0,a1);var _SherpaOnnxGetOnlineStreamResult=Module["_SherpaOnnxGetOnlineStreamResult"]=(a0,a1)=>(_SherpaOnnxGetOnlineStreamResult=Module["_SherpaOnnxGetOnlineStreamResult"]=wasmExports["T"])(a0,a1);var _SherpaOnnxDestroyOnlineRecognizerResult=Module["_SherpaOnnxDestroyOnlineRecognizerResult"]=a0=>(_SherpaOnnxDestroyOnlineRecognizerResult=Module["_SherpaOnnxDestroyOnlineRecognizerResult"]=wasmExports["U"])(a0);var _SherpaOnnxGetOnlineStreamResultAsJson=Module["_SherpaOnnxGetOnlineStreamResultAsJson"]=(a0,a1)=>(_SherpaOnnxGetOnlineStreamResultAsJson=Module["_SherpaOnnxGetOnlineStreamResultAsJson"]=wasmExports["V"])(a0,a1);var _SherpaOnnxDestroyOnlineStreamResultJson=Module["_SherpaOnnxDestroyOnlineStreamResultJson"]=a0=>(_SherpaOnnxDestroyOnlineStreamResultJson=Module["_SherpaOnnxDestroyOnlineStreamResultJson"]=wasmExports["W"])(a0);var _SherpaOnnxOnlineStreamReset=Module["_SherpaOnnxOnlineStreamReset"]=(a0,a1)=>(_SherpaOnnxOnlineStreamReset=Module["_SherpaOnnxOnlineStreamReset"]=wasmExports["X"])(a0,a1);var _SherpaOnnxOnlineStreamInputFinished=Module["_SherpaOnnxOnlineStreamInputFinished"]=a0=>(_SherpaOnnxOnlineStreamInputFinished=Module["_SherpaOnnxOnlineStreamInputFinished"]=wasmExports["Y"])(a0);var _SherpaOnnxOnlineStreamIsEndpoint=Module["_SherpaOnnxOnlineStreamIsEndpoint"]=(a0,a1)=>(_SherpaOnnxOnlineStreamIsEndpoint=Module["_SherpaOnnxOnlineStreamIsEndpoint"]=wasmExports["Z"])(a0,a1);var _SherpaOnnxGetOfflineStreamResultAsJson=Module["_SherpaOnnxGetOfflineStreamResultAsJson"]=a0=>(_SherpaOnnxGetOfflineStreamResultAsJson=Module["_SherpaOnnxGetOfflineStreamResultAsJson"]=wasmExports["_"])(a0);var _SherpaOnnxDestroyOfflineStreamResultJson=Module["_SherpaOnnxDestroyOfflineStreamResultJson"]=a0=>(_SherpaOnnxDestroyOfflineStreamResultJson=Module["_SherpaOnnxDestroyOfflineStreamResultJson"]=wasmExports["$"])(a0);var _emscripten_builtin_memalign=(a0,a1)=>(_emscripten_builtin_memalign=wasmExports["ba"])(a0,a1);var _malloc=Module["_malloc"]=a0=>(_malloc=Module["_malloc"]=wasmExports["ca"])(a0);var _free=Module["_free"]=a0=>(_free=Module["_free"]=wasmExports["da"])(a0);var __emscripten_stack_restore=a0=>(__emscripten_stack_restore=wasmExports["ea"])(a0);var __emscripten_stack_alloc=a0=>(__emscripten_stack_alloc=wasmExports["fa"])(a0);var _emscripten_stack_get_current=()=>(_emscripten_stack_get_current=wasmExports["ga"])();Module["addRunDependency"]=addRunDependency;Module["removeRunDependency"]=removeRunDependency;Module["ccall"]=ccall;Module["setValue"]=setValue;Module["getValue"]=getValue;Module["UTF8ToString"]=UTF8ToString;Module["stringToUTF8"]=stringToUTF8;Module["lengthBytesUTF8"]=lengthBytesUTF8;Module["FS_createPreloadedFile"]=FS_createPreloadedFile;Module["FS_unlink"]=FS_unlink;Module["FS_createPath"]=FS_createPath;Module["FS_createDevice"]=FS_createDevice;Module["FS_createDataFile"]=FS_createDataFile;Module["FS_createLazyFile"]=FS_createLazyFile;function run(){if(runDependencies>0){dependenciesFulfilled=run;return}preRun();if(runDependencies>0){dependenciesFulfilled=run;return}function doRun(){Module["calledRun"]=true;if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}run();
|
sherpa-onnx-wasm-main-asr.wasm
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:47a5b704a9f0e17cc6da262d7c3ddfa26fd361f7639a6f81f1055ec016c1295f
|
3 |
+
size 11293044
|