Spaces:
Running
Running
Adapt to using Kroko SDK and the new models
Browse files- .gitattributes +1 -0
- app-asr.js +400 -272
- await-lock.js +85 -0
- de.js +0 -374
- de.json +0 -1
- de1.mp3 +0 -3
- de2.mp3 +0 -3
- de3.mp3 +0 -3
- de4.mp3 +0 -3
- de5.mp3 +0 -3
- en.data +0 -3
- en.js +0 -374
- en.json +0 -1
- en1.mp3 +0 -3
- en2.mp3 +0 -3
- en3.mp3 +0 -3
- en4.mp3 +0 -3
- en5.mp3 +0 -3
- fr.data +0 -3
- fr.js +0 -374
- fr.json +0 -1
- fr1.mp3 +0 -3
- fr2.mp3 +0 -3
- fr3.mp3 +0 -3
- fr4.mp3 +0 -3
- fr5.mp3 +0 -3
- index.html +80 -81
- de.data → kroko-sdk.js +2 -2
- sherpa-onnx-asr.js +0 -1030
- sherpa-onnx-wasm-main-asr.js +0 -1
- sherpa-onnx-wasm-main-asr.wasm +0 -3
.gitattributes
CHANGED
|
@@ -35,3 +35,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
*.data filter=lfs diff=lfs merge=lfs -text
|
| 37 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
*.data filter=lfs diff=lfs merge=lfs -text
|
| 37 |
*.mp3 filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
kroko-sdk.js filter=lfs diff=lfs merge=lfs -text
|
app-asr.js
CHANGED
|
@@ -2,29 +2,34 @@
|
|
| 2 |
// from https://mdn.github.io/web-dictaphone/scripts/app.js
|
| 3 |
// and https://gist.github.com/meziantou/edb7217fddfbb70e899e
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = '';
|
|
@@ -43,47 +48,6 @@ function getDisplayResult() {
|
|
| 43 |
return ans;
|
| 44 |
}
|
| 45 |
|
| 46 |
-
Module = {};
|
| 47 |
-
Module.locateFile = function(path, scriptDirectory = '') {
|
| 48 |
-
if (path.endsWith('.js.metadata')) {
|
| 49 |
-
return scriptDirectory + path.replace('.js.metadata', '.json');
|
| 50 |
-
}
|
| 51 |
-
return scriptDirectory + path;
|
| 52 |
-
};
|
| 53 |
-
Module.setStatus = function(status) {
|
| 54 |
-
const statusElement = document.getElementById('status');
|
| 55 |
-
statusElement.textContent = status;
|
| 56 |
-
if (status === '') {
|
| 57 |
-
statusElement.style.display = 'none';
|
| 58 |
-
document.querySelectorAll('.tab-content').forEach((tabContentElement) => {
|
| 59 |
-
tabContentElement.classList.remove('loading');
|
| 60 |
-
});
|
| 61 |
-
} else {
|
| 62 |
-
statusElement.style.display = 'block';
|
| 63 |
-
document.querySelectorAll('.tab-content').forEach((tabContentElement) => {
|
| 64 |
-
tabContentElement.classList.add('loading');
|
| 65 |
-
});
|
| 66 |
-
}
|
| 67 |
-
};
|
| 68 |
-
Module.onRuntimeInitialized = function() {
|
| 69 |
-
console.log('inited!');
|
| 70 |
-
//hint.innerText = 'Model loaded! Please click start';
|
| 71 |
-
|
| 72 |
-
started = false;
|
| 73 |
-
|
| 74 |
-
recognizer = createOnlineRecognizer(Module);
|
| 75 |
-
console.log('recognizer is created!', recognizer);
|
| 76 |
-
};
|
| 77 |
-
|
| 78 |
-
function loadScript(src) {
|
| 79 |
-
const scriptElement = document.createElement('script');
|
| 80 |
-
scriptElement.src = src;
|
| 81 |
-
document.body.append(scriptElement);
|
| 82 |
-
}
|
| 83 |
-
|
| 84 |
-
loadScript('./' + lang + '.js');
|
| 85 |
-
loadScript('./sherpa-onnx-wasm-main-asr.js');
|
| 86 |
-
|
| 87 |
let audioCtx;
|
| 88 |
let mediaStream;
|
| 89 |
|
|
@@ -94,8 +58,366 @@ let leftchannel = []; // TODO: Use a single channel
|
|
| 94 |
|
| 95 |
let recordingLength = 0; // number of samples so far
|
| 96 |
|
|
|
|
| 97 |
let recognizer = null;
|
| 98 |
let recognizer_stream = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
if (navigator.mediaDevices.getUserMedia) {
|
| 101 |
console.log('getUserMedia supported.');
|
|
@@ -129,32 +451,24 @@ if (navigator.mediaDevices.getUserMedia) {
|
|
| 129 |
}
|
| 130 |
console.log('recorder', recorder);
|
| 131 |
|
| 132 |
-
recorder.onaudioprocess = function(e) {
|
|
|
|
|
|
|
| 133 |
let samples = new Float32Array(e.inputBuffer.getChannelData(0))
|
| 134 |
samples = downsampleBuffer(samples, expectedSampleRate);
|
| 135 |
|
| 136 |
if (recognizer_stream == null) {
|
| 137 |
-
recognizer_stream = recognizer.createStream();
|
| 138 |
}
|
| 139 |
|
| 140 |
-
recognizer_stream.acceptWaveform(expectedSampleRate, samples);
|
| 141 |
-
while (recognizer.isReady(recognizer_stream)) {
|
| 142 |
-
recognizer.decode(recognizer_stream);
|
| 143 |
}
|
| 144 |
|
| 145 |
-
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
| 146 |
-
|
| 147 |
-
let result = recognizer.getResult(recognizer_stream).text;
|
| 148 |
-
|
| 149 |
-
if (recognizer.config.modelConfig.paraformer.encoder != '') {
|
| 150 |
-
let tailPaddings = new Float32Array(expectedSampleRate);
|
| 151 |
-
recognizer_stream.acceptWaveform(expectedSampleRate, tailPaddings);
|
| 152 |
-
while (recognizer.isReady(recognizer_stream)) {
|
| 153 |
-
recognizer.decode(recognizer_stream);
|
| 154 |
-
}
|
| 155 |
-
result = recognizer.getResult(recognizer_stream).text;
|
| 156 |
-
}
|
| 157 |
|
|
|
|
| 158 |
|
| 159 |
if (result.length > 0 && lastResult != result) {
|
| 160 |
lastResult = result;
|
|
@@ -165,7 +479,7 @@ if (navigator.mediaDevices.getUserMedia) {
|
|
| 165 |
resultList.push(lastResult);
|
| 166 |
lastResult = '';
|
| 167 |
}
|
| 168 |
-
recognizer.reset(recognizer_stream);
|
| 169 |
}
|
| 170 |
|
| 171 |
textArea.value = getDisplayResult();
|
|
@@ -185,6 +499,8 @@ if (navigator.mediaDevices.getUserMedia) {
|
|
| 185 |
|
| 186 |
leftchannel.push(buf);
|
| 187 |
recordingLength += bufferSize;
|
|
|
|
|
|
|
| 188 |
};
|
| 189 |
|
| 190 |
startBtn.onclick = function() {
|
|
@@ -260,38 +576,6 @@ if (navigator.mediaDevices.getUserMedia) {
|
|
| 260 |
alert('getUserMedia not supported on your browser!');
|
| 261 |
}
|
| 262 |
|
| 263 |
-
playAllBtn.onclick = function() {
|
| 264 |
-
if(!multistreamStarted) {
|
| 265 |
-
multistreamStarted = true;
|
| 266 |
-
playAllBtn.textContent = "Stop All Streams";
|
| 267 |
-
playAllBtn.style.backgroundColor = "#d9534f";
|
| 268 |
-
|
| 269 |
-
transcribe(audioSources[lang][0], 'transcript1', 0);
|
| 270 |
-
transcribe(audioSources[lang][1], 'transcript2', 1);
|
| 271 |
-
transcribe(audioSources[lang][2], 'transcript3', 2);
|
| 272 |
-
transcribe(audioSources[lang][3], 'transcript4', 3);
|
| 273 |
-
transcribe(audioSources[lang][4], 'transcript5', 4);
|
| 274 |
-
}
|
| 275 |
-
else {
|
| 276 |
-
audios[0].pause();
|
| 277 |
-
audios[1].pause();
|
| 278 |
-
audios[2].pause();
|
| 279 |
-
audios[3].pause();
|
| 280 |
-
audios[4].pause();
|
| 281 |
-
audios[0].currentTime = 0;
|
| 282 |
-
audios[1].currentTime = 0;
|
| 283 |
-
audios[2].currentTime = 0;
|
| 284 |
-
audios[3].currentTime = 0;
|
| 285 |
-
audios[4].currentTime = 0;
|
| 286 |
-
|
| 287 |
-
playAllBtn.textContent = "Play All Streams";
|
| 288 |
-
playAllBtn.style.backgroundColor = "#007bff";
|
| 289 |
-
|
| 290 |
-
multistreamStarted = false;
|
| 291 |
-
}
|
| 292 |
-
}
|
| 293 |
-
|
| 294 |
-
|
| 295 |
// this function is copied/modified from
|
| 296 |
// https://gist.github.com/meziantou/edb7217fddfbb70e899e
|
| 297 |
function flatten(listOfSamples) {
|
|
@@ -368,54 +652,6 @@ function downsampleBuffer(buffer, exportSampleRate) {
|
|
| 368 |
return result;
|
| 369 |
};
|
| 370 |
|
| 371 |
-
async function processArrayBufferWithASR(arrayBuffer, file) {
|
| 372 |
-
// Check if recognizer is ready.
|
| 373 |
-
if (recognizer === null) {
|
| 374 |
-
console.error("Recognizer not yet initialized! Please wait for WASM to load.");
|
| 375 |
-
//resultsTextarea.value = "Error: Recognizer not ready.";
|
| 376 |
-
return;
|
| 377 |
-
}
|
| 378 |
-
// Create an AudioContext. (On some platforms, creating multiple AudioContexts can be problematic.
|
| 379 |
-
// If needed, consider reusing a global AudioContext.)
|
| 380 |
-
const audioCtx = new (window.AudioContext || window.webkitAudioContext)({
|
| 381 |
-
sampleRate: expectedSampleRate
|
| 382 |
-
});
|
| 383 |
-
try {
|
| 384 |
-
const audioBuffer = await audioCtx.decodeAudioData(arrayBuffer);
|
| 385 |
-
console.log("AudioBuffer decoded. Duration (s):", audioBuffer.duration);
|
| 386 |
-
let channelData = audioBuffer.getChannelData(0);
|
| 387 |
-
console.log("Channel data length:", channelData.length);
|
| 388 |
-
// Downsample if necessary.
|
| 389 |
-
if (audioBuffer.sampleRate !== expectedSampleRate) {
|
| 390 |
-
console.log("Downsampling from", audioBuffer.sampleRate, "to", expectedSampleRate);
|
| 391 |
-
channelData = downsampleBuffer(channelData, expectedSampleRate, audioBuffer.sampleRate);
|
| 392 |
-
console.log("Downsampled channel data length:", channelData.length);
|
| 393 |
-
}
|
| 394 |
-
// Create a new recognizer stream.
|
| 395 |
-
const stream = recognizer.createStream();
|
| 396 |
-
const chunkSize = expectedSampleRate; // assume 1 second worth of samples per chunk.
|
| 397 |
-
for (let i = 0; i < channelData.length; i += chunkSize) {
|
| 398 |
-
const chunk = channelData.subarray(i, i + chunkSize);
|
| 399 |
-
stream.acceptWaveform(expectedSampleRate, chunk);
|
| 400 |
-
while (recognizer.isReady(stream)) {
|
| 401 |
-
recognizer.decode(stream);
|
| 402 |
-
}
|
| 403 |
-
}
|
| 404 |
-
// Flush any tail data if necessary.
|
| 405 |
-
const tail = new Float32Array(expectedSampleRate);
|
| 406 |
-
stream.acceptWaveform(expectedSampleRate, tail);
|
| 407 |
-
while (recognizer.isReady(stream)) {
|
| 408 |
-
recognizer.decode(stream);
|
| 409 |
-
}
|
| 410 |
-
const fileResult = recognizer.getResult(stream).text || "";
|
| 411 |
-
console.log("ASR result for file:", fileResult);
|
| 412 |
-
textArea.value = fileResult;
|
| 413 |
-
} catch (err) {
|
| 414 |
-
console.error("Error decoding audio data:", err);
|
| 415 |
-
//resultsTextarea.value = "Error processing audio: " + err.message;
|
| 416 |
-
}
|
| 417 |
-
}
|
| 418 |
-
|
| 419 |
const audios = []
|
| 420 |
const recorders = []
|
| 421 |
|
|
@@ -434,15 +670,8 @@ async function loadAudio(url) {
|
|
| 434 |
}
|
| 435 |
|
| 436 |
async function transcribe(url, output, index) {
|
| 437 |
-
let urlLabel = document.createElement('h2');
|
| 438 |
-
//urlLabel.textContent = url;
|
| 439 |
let textarea = document.getElementById(output);
|
| 440 |
textarea.value = '';
|
| 441 |
-
|
| 442 |
-
//textarea.readOnly = true;
|
| 443 |
-
//textarea.rows = 10;
|
| 444 |
-
//document.querySelector('#container').append(urlLabel);
|
| 445 |
-
//document.querySelector('#container').append(textarea);
|
| 446 |
|
| 447 |
let lastResult = '';
|
| 448 |
let resultList = [];
|
|
@@ -489,23 +718,26 @@ async function transcribe(url, output, index) {
|
|
| 489 |
|
| 490 |
|
| 491 |
let recognizer_stream = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 492 |
|
| 493 |
-
recorders[index].onaudioprocess = function(e) {
|
| 494 |
let samples = new Float32Array(e.inputBuffer.getChannelData(0))
|
| 495 |
e.outputBuffer.copyToChannel(samples, 0);
|
| 496 |
|
| 497 |
if (recognizer_stream == null) {
|
| 498 |
-
recognizer_stream = recognizer.createStream();
|
| 499 |
}
|
| 500 |
|
| 501 |
-
recognizer_stream.acceptWaveform(expectedSampleRate, samples);
|
| 502 |
-
while (recognizer.isReady(recognizer_stream)) {
|
| 503 |
-
recognizer.decode(recognizer_stream);
|
| 504 |
}
|
| 505 |
|
| 506 |
-
let isEndpoint = recognizer.isEndpoint(recognizer_stream);
|
| 507 |
|
| 508 |
-
let result = recognizer.getResult(recognizer_stream).text;
|
| 509 |
|
| 510 |
if (result.length > 0 && lastResult != result) {
|
| 511 |
lastResult = result;
|
|
@@ -516,7 +748,7 @@ async function transcribe(url, output, index) {
|
|
| 516 |
resultList.push(lastResult);
|
| 517 |
lastResult = '';
|
| 518 |
}
|
| 519 |
-
recognizer.reset(recognizer_stream);
|
| 520 |
}
|
| 521 |
|
| 522 |
textarea.value = getDisplayResult();
|
|
@@ -533,6 +765,8 @@ async function transcribe(url, output, index) {
|
|
| 533 |
samples[i] = s;
|
| 534 |
buf[i] = s * 32767;
|
| 535 |
}
|
|
|
|
|
|
|
| 536 |
};
|
| 537 |
|
| 538 |
recorders[index]?.addEventListener("recordingStopped", () => {
|
|
@@ -555,7 +789,6 @@ soundClips.addEventListener("change", function (event) {
|
|
| 555 |
console.log("ArrayBuffer length:", arrayBuffer.byteLength);
|
| 556 |
var url = URL.createObjectURL(file);
|
| 557 |
transcribe(url, 'results');
|
| 558 |
-
//processArrayBufferWithASR(arrayBuffer, file);
|
| 559 |
};
|
| 560 |
reader.onerror = function (err) {
|
| 561 |
console.error("FileReader error:", err);
|
|
@@ -564,84 +797,9 @@ soundClips.addEventListener("change", function (event) {
|
|
| 564 |
reader.readAsArrayBuffer(file);
|
| 565 |
});
|
| 566 |
|
| 567 |
-
const singleAudioTab = document.getElementById("singleAudioTab");
|
| 568 |
-
const multistreamTab = document.getElementById("multistreamTab");
|
| 569 |
-
const singleAudioContent = document.getElementById("singleAudioContent");
|
| 570 |
-
const multistreamContent = document.getElementById("multistreamContent");
|
| 571 |
-
|
| 572 |
-
const audioElements = [
|
| 573 |
-
document.getElementById("audio1"),
|
| 574 |
-
document.getElementById("audio2"),
|
| 575 |
-
document.getElementById("audio3"),
|
| 576 |
-
document.getElementById("audio4"),
|
| 577 |
-
document.getElementById("audio5"),
|
| 578 |
-
];
|
| 579 |
-
|
| 580 |
-
const audioSources = {
|
| 581 |
-
"de": [
|
| 582 |
-
"./de1.mp3",
|
| 583 |
-
"./de2.mp3",
|
| 584 |
-
"./de3.mp3",
|
| 585 |
-
"./de4.mp3",
|
| 586 |
-
"./de5.mp3",
|
| 587 |
-
],
|
| 588 |
-
"en": [
|
| 589 |
-
"./en1.mp3",
|
| 590 |
-
"./en2.mp3",
|
| 591 |
-
"./en3.mp3",
|
| 592 |
-
"./en4.mp3",
|
| 593 |
-
"./en5.mp3",
|
| 594 |
-
],
|
| 595 |
-
"fr": [
|
| 596 |
-
"./fr1.mp3",
|
| 597 |
-
"./fr2.mp3",
|
| 598 |
-
"./fr3.mp3",
|
| 599 |
-
"./fr4.mp3",
|
| 600 |
-
"./fr5.mp3",
|
| 601 |
-
],
|
| 602 |
-
};
|
| 603 |
-
|
| 604 |
-
// Tab switching logic
|
| 605 |
-
singleAudioTab.addEventListener("click", () => {
|
| 606 |
-
singleAudioTab.classList.add("active");
|
| 607 |
-
multistreamTab.classList.remove("active");
|
| 608 |
-
singleAudioContent.style.display = "block";
|
| 609 |
-
multistreamContent.style.display = "none";
|
| 610 |
-
|
| 611 |
-
singleAudioTab.style.borderBottomColor = "#007bff";
|
| 612 |
-
multistreamTab.style.borderBottomColor = "transparent";
|
| 613 |
-
singleAudioTab.style.color = "#007bff";
|
| 614 |
-
multistreamTab.style.color = "#6c757d";
|
| 615 |
-
|
| 616 |
-
const url = new URL(window.location.href);
|
| 617 |
-
url.searchParams.set("tab", "single");
|
| 618 |
-
window.history.pushState({}, "", url.toString());
|
| 619 |
-
});
|
| 620 |
-
|
| 621 |
-
multistreamTab.addEventListener("click", () => {
|
| 622 |
-
multistreamTab.classList.add("active");
|
| 623 |
-
singleAudioTab.classList.remove("active");
|
| 624 |
-
multistreamContent.style.display = "block";
|
| 625 |
-
singleAudioContent.style.display = "none";
|
| 626 |
-
|
| 627 |
-
multistreamTab.style.borderBottomColor = "#007bff";
|
| 628 |
-
singleAudioTab.style.borderBottomColor = "transparent";
|
| 629 |
-
multistreamTab.style.color = "#007bff";
|
| 630 |
-
singleAudioTab.style.color = "#6c757d";
|
| 631 |
-
|
| 632 |
-
const url = new URL(window.location.href);
|
| 633 |
-
url.searchParams.set("tab", "multi");
|
| 634 |
-
window.history.pushState({}, "", url.toString());
|
| 635 |
-
});
|
| 636 |
-
|
| 637 |
// Load audio sources
|
| 638 |
-
audioElements.forEach((audio, index) => {
|
| 639 |
-
audio.src = audioSources[lang][index];
|
| 640 |
-
});
|
| 641 |
-
|
| 642 |
// Microphone recording logic
|
| 643 |
const recordBtn = document.getElementById("recordBtn");
|
| 644 |
-
const outputText = document.getElementById("outputText");
|
| 645 |
const audioPlayback = document.getElementById("audioPlayback");
|
| 646 |
|
| 647 |
let mediaRecorder;
|
|
@@ -679,33 +837,3 @@ recordBtn.addEventListener("click", async () => {
|
|
| 679 |
recordBtn.style.color = "#d9534f";
|
| 680 |
}
|
| 681 |
});
|
| 682 |
-
|
| 683 |
-
// Function to handle language change and update URL
|
| 684 |
-
document.querySelectorAll('input[name="language"]').forEach((input) => {
|
| 685 |
-
input.addEventListener('change', function() {
|
| 686 |
-
const selectedLang = this.value;
|
| 687 |
-
|
| 688 |
-
// Update URL with new language parameter
|
| 689 |
-
const url = new URL(window.location.href);
|
| 690 |
-
url.searchParams.set('lang', selectedLang);
|
| 691 |
-
|
| 692 |
-
// Reload the page with new language setting
|
| 693 |
-
window.location.href = url.toString();
|
| 694 |
-
});
|
| 695 |
-
});
|
| 696 |
-
|
| 697 |
-
document.querySelectorAll('input[name="language"]').forEach((input) => {
|
| 698 |
-
input.checked = input.value === lang;
|
| 699 |
-
});
|
| 700 |
-
|
| 701 |
-
if (activeTab === "multi") {
|
| 702 |
-
multistreamTab.classList.add("active");
|
| 703 |
-
singleAudioTab.classList.remove("active");
|
| 704 |
-
multistreamContent.style.display = "block";
|
| 705 |
-
singleAudioContent.style.display = "none";
|
| 706 |
-
|
| 707 |
-
multistreamTab.style.borderBottomColor = "#007bff";
|
| 708 |
-
singleAudioTab.style.borderBottomColor = "transparent";
|
| 709 |
-
multistreamTab.style.color = "#007bff";
|
| 710 |
-
singleAudioTab.style.color = "#6c757d";
|
| 711 |
-
}
|
|
|
|
| 2 |
// from https://mdn.github.io/web-dictaphone/scripts/app.js
|
| 3 |
// and https://gist.github.com/meziantou/edb7217fddfbb70e899e
|
| 4 |
|
| 5 |
+
import AwaitLock from './await-lock.js';
|
| 6 |
+
import { KrokoWorker } from './kroko-sdk.js';
|
|
|
|
| 7 |
|
| 8 |
+
const languageSelect = document.getElementById('languageSelect');
|
| 9 |
+
const modelTypeToggle = document.getElementById('modelType');
|
| 10 |
+
const modelList = document.getElementById('modelList');
|
| 11 |
const startBtn = document.getElementById('recordBtn');
|
|
|
|
| 12 |
const soundClips = document.getElementById('fileInput');
|
| 13 |
+
|
| 14 |
+
function applyFilters() {
|
| 15 |
+
const lang = languageSelect.options[languageSelect.selectedIndex].value;
|
| 16 |
+
const type = modelTypeToggle.checked ? 'pro' : 'free';
|
| 17 |
+
filterModels(lang, type);
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
function filterModels(lang, type) {
|
| 21 |
+
for (const modelDiv of modelList.children) {
|
| 22 |
+
modelDiv.classList.toggle('hidden', modelDiv.dataset.lang !== lang || modelDiv.dataset.type !== type);
|
| 23 |
+
}
|
| 24 |
+
}
|
| 25 |
|
| 26 |
let started = false;
|
|
|
|
| 27 |
|
| 28 |
let textArea = document.getElementById('results');
|
| 29 |
|
| 30 |
let lastResult = '';
|
| 31 |
let resultList = [];
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
function getDisplayResult() {
|
| 34 |
let i = 0;
|
| 35 |
let ans = '';
|
|
|
|
| 48 |
return ans;
|
| 49 |
}
|
| 50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
let audioCtx;
|
| 52 |
let mediaStream;
|
| 53 |
|
|
|
|
| 58 |
|
| 59 |
let recordingLength = 0; // number of samples so far
|
| 60 |
|
| 61 |
+
let krokoWorker = new KrokoWorker();
|
| 62 |
let recognizer = null;
|
| 63 |
let recognizer_stream = null;
|
| 64 |
+
let streamLock = new AwaitLock;
|
| 65 |
+
|
| 66 |
+
async function getLanguages() {
|
| 67 |
+
const req = await fetch('https://license.kroko.ai/api/public/v1/languages');
|
| 68 |
+
if (!req.ok) {
|
| 69 |
+
throw new Error((await req.text()).trim());
|
| 70 |
+
}
|
| 71 |
+
return req.json();
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
async function getModels() {
|
| 75 |
+
const req = await fetch('https://license.kroko.ai/api/public/v1/models');
|
| 76 |
+
if (!req.ok) {
|
| 77 |
+
throw new Error((await req.text()).trim());
|
| 78 |
+
}
|
| 79 |
+
return req.json();
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
async function getModelUrl(modelId, license) {
|
| 83 |
+
const url = new URL('https://license.kroko.ai/api/public/v1/models');
|
| 84 |
+
url.searchParams.set('model_id', modelId);
|
| 85 |
+
url.searchParams.set('license', license);
|
| 86 |
+
const req = await fetch(url.toString());
|
| 87 |
+
if (!req.ok) {
|
| 88 |
+
throw new Error((await req.text()).trim());
|
| 89 |
+
}
|
| 90 |
+
const model = (await req.json())[0];
|
| 91 |
+
if (model === undefined) {
|
| 92 |
+
throw new Error('Invalid license key');
|
| 93 |
+
}
|
| 94 |
+
return model.url;
|
| 95 |
+
}
|
| 96 |
+
|
| 97 |
+
const languages = (await getLanguages()).sort((language1, language2) => language1.name.localeCompare(language2.name));
|
| 98 |
+
const models = (await getModels()).filter(model => model.streaming).sort((model1, model2) => model1.name.localeCompare(model2.name));
|
| 99 |
+
|
| 100 |
+
// #region languages
|
| 101 |
+
languages.forEach(language => {
|
| 102 |
+
const languageOption = document.createElement('option');
|
| 103 |
+
languageOption.value = language.iso;
|
| 104 |
+
languageOption.textContent = language.name;
|
| 105 |
+
languageSelect.appendChild(languageOption);
|
| 106 |
+
});
|
| 107 |
+
languageSelect.addEventListener('change', applyFilters);
|
| 108 |
+
// #endregion languages
|
| 109 |
+
|
| 110 |
+
// #region model type
|
| 111 |
+
modelTypeToggle.addEventListener('change', applyFilters);
|
| 112 |
+
// #endregion model type
|
| 113 |
+
|
| 114 |
+
// #region models
|
| 115 |
+
models.forEach(model => {
|
| 116 |
+
const modelDiv = document.createElement('div');
|
| 117 |
+
modelDiv.style.display = 'flex';
|
| 118 |
+
modelDiv.style.flexDirection = 'column';
|
| 119 |
+
modelDiv.style.gap = '0.5rem';
|
| 120 |
+
modelDiv.classList.add('hidden');
|
| 121 |
+
modelDiv.dataset.lang = model.language_iso;
|
| 122 |
+
modelDiv.dataset.type = model.type;
|
| 123 |
+
|
| 124 |
+
const nameDiv = document.createElement('div');
|
| 125 |
+
nameDiv.style.fontSize = 'larger';
|
| 126 |
+
nameDiv.style.fontWeight = 'bold';
|
| 127 |
+
nameDiv.textContent = model.name;
|
| 128 |
+
modelDiv.appendChild(nameDiv);
|
| 129 |
+
|
| 130 |
+
const streamingDiv = document.createElement('div');
|
| 131 |
+
streamingDiv.textContent = 'Streaming';
|
| 132 |
+
modelDiv.appendChild(streamingDiv);
|
| 133 |
+
|
| 134 |
+
const infoDiv = document.createElement('div');
|
| 135 |
+
const sizeMB = Math.round(model.file_size / 1000 / 1000);
|
| 136 |
+
const typeLabel = model.type === 'pro' ? 'Pro' : 'Community';
|
| 137 |
+
infoDiv.innerHTML = `<strong>Size:</strong> ${sizeMB}MB <strong>Type:</strong> ${typeLabel}`;
|
| 138 |
+
modelDiv.appendChild(infoDiv);
|
| 139 |
+
|
| 140 |
+
if (model.type === 'pro') {
|
| 141 |
+
const licenseDiv = document.createElement('div');
|
| 142 |
+
licenseDiv.style.color = 'darkred';
|
| 143 |
+
licenseDiv.textContent = 'Requires license key';
|
| 144 |
+
modelDiv.appendChild(licenseDiv);
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
const buttonDiv = document.createElement('div');
|
| 148 |
+
const button = document.createElement('button');
|
| 149 |
+
button.style.padding = '0.5rem 1rem';
|
| 150 |
+
button.style.border = '1px solid #e9ecef';
|
| 151 |
+
button.style.borderRadius = '4px';
|
| 152 |
+
button.style.backgroundColor = '#fff';
|
| 153 |
+
button.style.color = 'goldenrod';
|
| 154 |
+
button.style.cursor = 'pointer';
|
| 155 |
+
button.style.fontSize = '1rem';
|
| 156 |
+
button.classList.add('selectModel');
|
| 157 |
+
button.innerHTML = '✓ Select';
|
| 158 |
+
button.onclick = async () => {
|
| 159 |
+
try {
|
| 160 |
+
let url = model.url;
|
| 161 |
+
let license = undefined;
|
| 162 |
+
|
| 163 |
+
if (model.type !== 'free') {
|
| 164 |
+
const license = prompt('Add license key');
|
| 165 |
+
if (license === null) return;
|
| 166 |
+
url = await getModelUrl(model.model_id, license);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
document.getElementById('selectLanguageContent').classList.add('hidden');
|
| 170 |
+
document.getElementById('status').classList.remove('hidden');
|
| 171 |
+
document.getElementById('status').innerHTML = 'Downloading and loading model<b-dot>.</b-dot><b-dot>.</b-dot><b-dot>.</b-dot>';
|
| 172 |
+
|
| 173 |
+
await loadModel(url, license);
|
| 174 |
+
|
| 175 |
+
const modelInfoDiv = modelDiv.cloneNode(true);
|
| 176 |
+
const buttonRefreshDiv = document.createElement('div');
|
| 177 |
+
const buttonRefresh = document.createElement('button');
|
| 178 |
+
buttonRefresh.style.padding = '0.5rem 1rem';
|
| 179 |
+
buttonRefresh.style.border = '1px solid #e9ecef';
|
| 180 |
+
buttonRefresh.style.borderRadius = '4px';
|
| 181 |
+
buttonRefresh.style.backgroundColor = '#fff';
|
| 182 |
+
buttonRefresh.style.color = '#5cb85c';
|
| 183 |
+
buttonRefresh.style.cursor = 'pointer';
|
| 184 |
+
buttonRefresh.style.fontSize = '1rem';
|
| 185 |
+
buttonRefresh.innerHTML = 'Select another';
|
| 186 |
+
buttonRefresh.onclick = () => {
|
| 187 |
+
location.reload();
|
| 188 |
+
};
|
| 189 |
+
modelInfoDiv.querySelector('.selectModel').remove();
|
| 190 |
+
buttonRefreshDiv.appendChild(buttonRefresh);
|
| 191 |
+
modelInfoDiv.appendChild(buttonRefreshDiv);
|
| 192 |
+
document.getElementById('selectedModel').prepend(modelInfoDiv);
|
| 193 |
+
|
| 194 |
+
document.getElementById('selectedModelContent').classList.remove('hidden');
|
| 195 |
+
document.getElementById('singleAudioContent').classList.remove('hidden');
|
| 196 |
+
document.getElementById('status').classList.add('hidden');
|
| 197 |
+
} catch (ex) {
|
| 198 |
+
if (ex.message === 'Invalid license key') {
|
| 199 |
+
alert(ex.message);
|
| 200 |
+
} else {
|
| 201 |
+
document.getElementById('status').innerText = ex.message;
|
| 202 |
+
}
|
| 203 |
+
}
|
| 204 |
+
};
|
| 205 |
+
buttonDiv.appendChild(button);
|
| 206 |
+
modelDiv.appendChild(buttonDiv);
|
| 207 |
+
|
| 208 |
+
modelList.appendChild(modelDiv);
|
| 209 |
+
});
|
| 210 |
+
// #endregion models
|
| 211 |
+
|
| 212 |
+
document.getElementById('status').classList.add('hidden');
|
| 213 |
+
document.getElementById('selectLanguageContent').classList.remove('hidden');
|
| 214 |
+
|
| 215 |
+
// #region new to old model format tranformation
|
| 216 |
+
async function loadUnpackAndCacheModel(url, key) {
|
| 217 |
+
async function fetchWithCache(url) {
|
| 218 |
+
const cache = await caches.open('kroko-sdk');
|
| 219 |
+
let response = await cache.match?.(url);
|
| 220 |
+
|
| 221 |
+
if (response === undefined) {
|
| 222 |
+
response = await fetch(url);
|
| 223 |
+
if (!response.ok) {
|
| 224 |
+
throw new Error('Failed to fetch the file');
|
| 225 |
+
}
|
| 226 |
+
await cache.put(url, response.clone());
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
return response;
|
| 230 |
+
}
|
| 231 |
+
|
| 232 |
+
class ModelData {
|
| 233 |
+
constructor() {
|
| 234 |
+
this.filePath = "";
|
| 235 |
+
this.header = {};
|
| 236 |
+
this.blob = new Uint8Array(0);
|
| 237 |
+
this.encoder = null;
|
| 238 |
+
this.decoder = null;
|
| 239 |
+
this.joiner = null;
|
| 240 |
+
this.tokens = null;
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
async loadHeader(url) {
|
| 244 |
+
this.filePath = url;
|
| 245 |
+
const res = await fetchWithCache(url);
|
| 246 |
+
if (!res.ok) return false;
|
| 247 |
+
|
| 248 |
+
const arrayBuf = await res.arrayBuffer();
|
| 249 |
+
const data = new Uint8Array(arrayBuf);
|
| 250 |
+
|
| 251 |
+
if (data.byteLength < 4) return false;
|
| 252 |
+
const view = new DataView(data.buffer);
|
| 253 |
+
|
| 254 |
+
const headerLen = view.getUint32(0, true);
|
| 255 |
+
if (data.byteLength < 4 + headerLen) return false;
|
| 256 |
+
|
| 257 |
+
const headerBytes = data.slice(4, 4 + headerLen);
|
| 258 |
+
try {
|
| 259 |
+
const headerText = new TextDecoder().decode(headerBytes);
|
| 260 |
+
const j = JSON.parse(headerText);
|
| 261 |
+
this.header = j;
|
| 262 |
+
} catch (_) {
|
| 263 |
+
return false;
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
this.blob = data.slice(4 + headerLen);
|
| 267 |
+
return true;
|
| 268 |
+
}
|
| 269 |
+
|
| 270 |
+
async decryptPayload(password) {
|
| 271 |
+
if (!this.blob || this.blob.byteLength < 16) return false;
|
| 272 |
+
|
| 273 |
+
const iv = this.blob.slice(0, 16);
|
| 274 |
+
const ciphertext = this.blob.slice(16);
|
| 275 |
+
|
| 276 |
+
const keyBytes = new Uint8Array(32).fill("0".charCodeAt(0));
|
| 277 |
+
for (let i = 0; i < password.length && i < 32; i++) {
|
| 278 |
+
keyBytes[i] = password.charCodeAt(i);
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
let key;
|
| 282 |
+
try {
|
| 283 |
+
key = await window.crypto.subtle.importKey(
|
| 284 |
+
"raw",
|
| 285 |
+
keyBytes,
|
| 286 |
+
{ name: "AES-CBC" },
|
| 287 |
+
false,
|
| 288 |
+
["decrypt"]
|
| 289 |
+
);
|
| 290 |
+
} catch (e) {
|
| 291 |
+
console.error("Key import error:", e);
|
| 292 |
+
return false;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
let plaintext;
|
| 296 |
+
try {
|
| 297 |
+
plaintext = await window.crypto.subtle.decrypt(
|
| 298 |
+
{ name: "AES-CBC", iv },
|
| 299 |
+
key,
|
| 300 |
+
ciphertext
|
| 301 |
+
);
|
| 302 |
+
} catch (e) {
|
| 303 |
+
console.error("Decryption error:", e);
|
| 304 |
+
return false;
|
| 305 |
+
}
|
| 306 |
+
|
| 307 |
+
const plainU8 = new Uint8Array(plaintext);
|
| 308 |
+
let offset = 0;
|
| 309 |
+
|
| 310 |
+
const readBlock = () => {
|
| 311 |
+
if (offset + 4 > plainU8.length) throw new Error("Invalid block header");
|
| 312 |
+
const len = new DataView(plainU8.buffer).getUint32(offset, true);
|
| 313 |
+
offset += 4;
|
| 314 |
+
|
| 315 |
+
if (offset + len > plainU8.length) throw new Error("Block size mismatch");
|
| 316 |
+
const buf = plainU8.slice(offset, offset + len);
|
| 317 |
+
offset += len;
|
| 318 |
+
return buf;
|
| 319 |
+
};
|
| 320 |
+
|
| 321 |
+
try {
|
| 322 |
+
this.encoder = readBlock();
|
| 323 |
+
this.decoder = readBlock();
|
| 324 |
+
this.joiner = readBlock();
|
| 325 |
+
this.tokens = readBlock();
|
| 326 |
+
} catch (e) {
|
| 327 |
+
console.error("Payload parsing error:", e);
|
| 328 |
+
return false;
|
| 329 |
+
}
|
| 330 |
+
|
| 331 |
+
return true;
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
+
loadPayload() {
|
| 335 |
+
if (!this.blob || this.blob.byteLength < 4) return false;
|
| 336 |
+
|
| 337 |
+
const data = this.blob;
|
| 338 |
+
let offset = 0;
|
| 339 |
+
|
| 340 |
+
const readBlock = () => {
|
| 341 |
+
if (offset + 4 > data.length) throw new Error("Invalid block header");
|
| 342 |
+
const len = new DataView(data.buffer).getUint32(offset, true);
|
| 343 |
+
offset += 4;
|
| 344 |
+
|
| 345 |
+
if (offset + len > data.length) throw new Error("Block size mismatch");
|
| 346 |
+
const buf = data.slice(offset, offset + len);
|
| 347 |
+
offset += len;
|
| 348 |
+
return buf;
|
| 349 |
+
};
|
| 350 |
+
|
| 351 |
+
try {
|
| 352 |
+
this.encoder = readBlock();
|
| 353 |
+
this.decoder = readBlock();
|
| 354 |
+
this.joiner = readBlock();
|
| 355 |
+
this.tokens = readBlock();
|
| 356 |
+
} catch (e) {
|
| 357 |
+
console.error("Payload parsing error:", e);
|
| 358 |
+
return false;
|
| 359 |
+
}
|
| 360 |
+
|
| 361 |
+
return true;
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
getHeaderValue(key) {
|
| 365 |
+
const val = this.header[key];
|
| 366 |
+
if (val === undefined) return "";
|
| 367 |
+
if (typeof val === "string") return val;
|
| 368 |
+
return JSON.stringify(val);
|
| 369 |
+
}
|
| 370 |
+
}
|
| 371 |
+
|
| 372 |
+
async function createDummyCacheEntry(name, contents) {
|
| 373 |
+
const dummyUrl = url + '/' + name;
|
| 374 |
+
const cache = await caches.open('kroko-sdk');
|
| 375 |
+
let response = await cache.match?.(dummyUrl);
|
| 376 |
+
|
| 377 |
+
if (response === undefined) {
|
| 378 |
+
response = new Response(contents, {status: 200, statusText: 'OK'});
|
| 379 |
+
await cache.put(dummyUrl, response.clone());
|
| 380 |
+
}
|
| 381 |
+
return dummyUrl;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
const modelData = new ModelData();
|
| 385 |
+
await modelData.loadHeader(url);
|
| 386 |
+
|
| 387 |
+
if (key) {
|
| 388 |
+
await modelData.decryptPayload(key);
|
| 389 |
+
} else {
|
| 390 |
+
modelData.loadPayload();
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
return [
|
| 394 |
+
await createDummyCacheEntry('encoder', modelData.encoder),
|
| 395 |
+
await createDummyCacheEntry('decoder', modelData.decoder),
|
| 396 |
+
await createDummyCacheEntry('joiner', modelData.joiner),
|
| 397 |
+
await createDummyCacheEntry('tokens', modelData.tokens),
|
| 398 |
+
];
|
| 399 |
+
}
|
| 400 |
+
// #endregion new to old model format tranformation
|
| 401 |
+
|
| 402 |
+
async function loadModel(url, license) {
|
| 403 |
+
const [encoder, decoder, joiner, tokens] = await loadUnpackAndCacheModel(url);
|
| 404 |
+
|
| 405 |
+
recognizer = await krokoWorker.createOnlineRecognizer({
|
| 406 |
+
modelConfig: {
|
| 407 |
+
transducer: {
|
| 408 |
+
encoder: encoder,
|
| 409 |
+
decoder: decoder,
|
| 410 |
+
joiner: joiner,
|
| 411 |
+
},
|
| 412 |
+
tokens: tokens,
|
| 413 |
+
},
|
| 414 |
+
});
|
| 415 |
+
|
| 416 |
+
started = false;
|
| 417 |
+
|
| 418 |
+
console.log('recognizer is created!', recognizer);
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
|
| 422 |
if (navigator.mediaDevices.getUserMedia) {
|
| 423 |
console.log('getUserMedia supported.');
|
|
|
|
| 451 |
}
|
| 452 |
console.log('recorder', recorder);
|
| 453 |
|
| 454 |
+
recorder.onaudioprocess = async function(e) {
|
| 455 |
+
await streamLock.acquireAsync();
|
| 456 |
+
|
| 457 |
let samples = new Float32Array(e.inputBuffer.getChannelData(0))
|
| 458 |
samples = downsampleBuffer(samples, expectedSampleRate);
|
| 459 |
|
| 460 |
if (recognizer_stream == null) {
|
| 461 |
+
recognizer_stream = await recognizer.createStream();
|
| 462 |
}
|
| 463 |
|
| 464 |
+
await recognizer_stream.acceptWaveform(expectedSampleRate, samples);
|
| 465 |
+
while (await recognizer.isReady(recognizer_stream)) {
|
| 466 |
+
await recognizer.decode(recognizer_stream);
|
| 467 |
}
|
| 468 |
|
| 469 |
+
let isEndpoint = await recognizer.isEndpoint(recognizer_stream);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 470 |
|
| 471 |
+
let result = (await recognizer.getResult(recognizer_stream)).text;
|
| 472 |
|
| 473 |
if (result.length > 0 && lastResult != result) {
|
| 474 |
lastResult = result;
|
|
|
|
| 479 |
resultList.push(lastResult);
|
| 480 |
lastResult = '';
|
| 481 |
}
|
| 482 |
+
await recognizer.reset(recognizer_stream);
|
| 483 |
}
|
| 484 |
|
| 485 |
textArea.value = getDisplayResult();
|
|
|
|
| 499 |
|
| 500 |
leftchannel.push(buf);
|
| 501 |
recordingLength += bufferSize;
|
| 502 |
+
|
| 503 |
+
streamLock.release();
|
| 504 |
};
|
| 505 |
|
| 506 |
startBtn.onclick = function() {
|
|
|
|
| 576 |
alert('getUserMedia not supported on your browser!');
|
| 577 |
}
|
| 578 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 579 |
// this function is copied/modified from
|
| 580 |
// https://gist.github.com/meziantou/edb7217fddfbb70e899e
|
| 581 |
function flatten(listOfSamples) {
|
|
|
|
| 652 |
return result;
|
| 653 |
};
|
| 654 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 655 |
const audios = []
|
| 656 |
const recorders = []
|
| 657 |
|
|
|
|
| 670 |
}
|
| 671 |
|
| 672 |
async function transcribe(url, output, index) {
|
|
|
|
|
|
|
| 673 |
let textarea = document.getElementById(output);
|
| 674 |
textarea.value = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 675 |
|
| 676 |
let lastResult = '';
|
| 677 |
let resultList = [];
|
|
|
|
| 718 |
|
| 719 |
|
| 720 |
let recognizer_stream = null;
|
| 721 |
+
let streamLock = new AwaitLock;
|
| 722 |
+
|
| 723 |
+
recorders[index].onaudioprocess = async function(e) {
|
| 724 |
+
await streamLock.acquireAsync();
|
| 725 |
|
|
|
|
| 726 |
let samples = new Float32Array(e.inputBuffer.getChannelData(0))
|
| 727 |
e.outputBuffer.copyToChannel(samples, 0);
|
| 728 |
|
| 729 |
if (recognizer_stream == null) {
|
| 730 |
+
recognizer_stream = await recognizer.createStream();
|
| 731 |
}
|
| 732 |
|
| 733 |
+
await recognizer_stream.acceptWaveform(expectedSampleRate, samples);
|
| 734 |
+
while (await recognizer.isReady(recognizer_stream)) {
|
| 735 |
+
await recognizer.decode(recognizer_stream);
|
| 736 |
}
|
| 737 |
|
| 738 |
+
let isEndpoint = await recognizer.isEndpoint(recognizer_stream);
|
| 739 |
|
| 740 |
+
let result = (await recognizer.getResult(recognizer_stream)).text;
|
| 741 |
|
| 742 |
if (result.length > 0 && lastResult != result) {
|
| 743 |
lastResult = result;
|
|
|
|
| 748 |
resultList.push(lastResult);
|
| 749 |
lastResult = '';
|
| 750 |
}
|
| 751 |
+
await recognizer.reset(recognizer_stream);
|
| 752 |
}
|
| 753 |
|
| 754 |
textarea.value = getDisplayResult();
|
|
|
|
| 765 |
samples[i] = s;
|
| 766 |
buf[i] = s * 32767;
|
| 767 |
}
|
| 768 |
+
|
| 769 |
+
streamLock.release();
|
| 770 |
};
|
| 771 |
|
| 772 |
recorders[index]?.addEventListener("recordingStopped", () => {
|
|
|
|
| 789 |
console.log("ArrayBuffer length:", arrayBuffer.byteLength);
|
| 790 |
var url = URL.createObjectURL(file);
|
| 791 |
transcribe(url, 'results');
|
|
|
|
| 792 |
};
|
| 793 |
reader.onerror = function (err) {
|
| 794 |
console.error("FileReader error:", err);
|
|
|
|
| 797 |
reader.readAsArrayBuffer(file);
|
| 798 |
});
|
| 799 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 800 |
// Load audio sources
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
// Microphone recording logic
|
| 802 |
const recordBtn = document.getElementById("recordBtn");
|
|
|
|
| 803 |
const audioPlayback = document.getElementById("audioPlayback");
|
| 804 |
|
| 805 |
let mediaRecorder;
|
|
|
|
| 837 |
recordBtn.style.color = "#d9534f";
|
| 838 |
}
|
| 839 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await-lock.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* A mutex lock for coordination across async functions
|
| 3 |
+
*/
|
| 4 |
+
export default class AwaitLock {
|
| 5 |
+
#acquired = false;
|
| 6 |
+
#waitingResolvers = new Set();
|
| 7 |
+
/**
|
| 8 |
+
* Whether the lock is currently acquired or not. Accessing this property does not affect the
|
| 9 |
+
* status of the lock.
|
| 10 |
+
*/
|
| 11 |
+
get acquired() {
|
| 12 |
+
return this.#acquired;
|
| 13 |
+
}
|
| 14 |
+
/**
|
| 15 |
+
* Acquires the lock, waiting if necessary for it to become free if it is already locked. The
|
| 16 |
+
* returned promise is fulfilled once the lock is acquired.
|
| 17 |
+
*
|
| 18 |
+
* A timeout (in milliseconds) may be optionally provided. If the lock cannot be acquired before
|
| 19 |
+
* the timeout elapses, the returned promise is rejected with an error. The behavior of invalid
|
| 20 |
+
* timeout values depends on how `setTimeout` handles those values.
|
| 21 |
+
*
|
| 22 |
+
* After acquiring the lock, you **must** call `release` when you are done with it.
|
| 23 |
+
*/
|
| 24 |
+
acquireAsync({ timeout } = {}) {
|
| 25 |
+
if (!this.#acquired) {
|
| 26 |
+
this.#acquired = true;
|
| 27 |
+
return Promise.resolve();
|
| 28 |
+
}
|
| 29 |
+
if (timeout == null) {
|
| 30 |
+
return new Promise((resolve) => {
|
| 31 |
+
this.#waitingResolvers.add(resolve);
|
| 32 |
+
});
|
| 33 |
+
}
|
| 34 |
+
let resolver;
|
| 35 |
+
let timer;
|
| 36 |
+
return Promise.race([
|
| 37 |
+
new Promise((resolve) => {
|
| 38 |
+
resolver = () => {
|
| 39 |
+
clearTimeout(timer);
|
| 40 |
+
resolve();
|
| 41 |
+
};
|
| 42 |
+
this.#waitingResolvers.add(resolver);
|
| 43 |
+
}),
|
| 44 |
+
new Promise((_, reject) => {
|
| 45 |
+
timer = setTimeout(() => {
|
| 46 |
+
this.#waitingResolvers.delete(resolver);
|
| 47 |
+
reject(new Error(`Timed out waiting for lock`));
|
| 48 |
+
}, timeout);
|
| 49 |
+
}),
|
| 50 |
+
]);
|
| 51 |
+
}
|
| 52 |
+
/**
|
| 53 |
+
* Acquires the lock if it is free and otherwise returns immediately without waiting. Returns
|
| 54 |
+
* `true` if the lock was free and is now acquired, and `false` otherwise.
|
| 55 |
+
*
|
| 56 |
+
* This method differs from calling `acquireAsync` with a zero-millisecond timeout in that it runs
|
| 57 |
+
* synchronously without waiting for the JavaScript task queue.
|
| 58 |
+
*/
|
| 59 |
+
tryAcquire() {
|
| 60 |
+
if (!this.#acquired) {
|
| 61 |
+
this.#acquired = true;
|
| 62 |
+
return true;
|
| 63 |
+
}
|
| 64 |
+
return false;
|
| 65 |
+
}
|
| 66 |
+
/**
|
| 67 |
+
* Releases the lock and gives it to the next waiting acquirer, if there is one. Each acquirer
|
| 68 |
+
* must release the lock exactly once.
|
| 69 |
+
*/
|
| 70 |
+
release() {
|
| 71 |
+
if (!this.#acquired) {
|
| 72 |
+
throw new Error(`Cannot release an unacquired lock`);
|
| 73 |
+
}
|
| 74 |
+
if (this.#waitingResolvers.size > 0) {
|
| 75 |
+
// Sets preserve insertion order like a queue
|
| 76 |
+
const [resolve] = this.#waitingResolvers;
|
| 77 |
+
this.#waitingResolvers.delete(resolve);
|
| 78 |
+
resolve();
|
| 79 |
+
}
|
| 80 |
+
else {
|
| 81 |
+
this.#acquired = false;
|
| 82 |
+
}
|
| 83 |
+
}
|
| 84 |
+
}
|
| 85 |
+
//# sourceMappingURL=AwaitLock.js.map
|
de.js
DELETED
|
@@ -1,374 +0,0 @@
|
|
| 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 = 'de.data';
|
| 22 |
-
var REMOTE_PACKAGE_BASE = 'de.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 |
-
function runWithFS(Module) {
|
| 96 |
-
|
| 97 |
-
function assert(check, msg) {
|
| 98 |
-
if (!check) throw msg + new Error().stack;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/** @constructor */
|
| 102 |
-
function DataRequest(start, end, audio) {
|
| 103 |
-
this.start = start;
|
| 104 |
-
this.end = end;
|
| 105 |
-
this.audio = audio;
|
| 106 |
-
}
|
| 107 |
-
DataRequest.prototype = {
|
| 108 |
-
requests: {},
|
| 109 |
-
open: function(mode, name) {
|
| 110 |
-
this.name = name;
|
| 111 |
-
this.requests[name] = this;
|
| 112 |
-
Module['addRunDependency'](`fp ${this.name}`);
|
| 113 |
-
},
|
| 114 |
-
send: function() {},
|
| 115 |
-
onload: function() {
|
| 116 |
-
var byteArray = this.byteArray.subarray(this.start, this.end);
|
| 117 |
-
this.finish(byteArray);
|
| 118 |
-
},
|
| 119 |
-
finish: function(byteArray) {
|
| 120 |
-
var that = this;
|
| 121 |
-
// canOwn this data in the filesystem, it is a slide into the heap that will never change
|
| 122 |
-
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
|
| 123 |
-
Module['removeRunDependency'](`fp ${that.name}`);
|
| 124 |
-
this.requests[this.name] = null;
|
| 125 |
-
}
|
| 126 |
-
};
|
| 127 |
-
|
| 128 |
-
var files = metadata['files'];
|
| 129 |
-
for (var i = 0; i < files.length; ++i) {
|
| 130 |
-
new DataRequest(files[i]['start'], files[i]['end'], files[i]['audio'] || 0).open('GET', files[i]['filename']);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
var PACKAGE_UUID = metadata['package_uuid'];
|
| 134 |
-
var IDB_RO = "readonly";
|
| 135 |
-
var IDB_RW = "readwrite";
|
| 136 |
-
var DB_NAME = "EM_PRELOAD_CACHE";
|
| 137 |
-
var DB_VERSION = 1;
|
| 138 |
-
var METADATA_STORE_NAME = 'METADATA';
|
| 139 |
-
var PACKAGE_STORE_NAME = 'PACKAGES';
|
| 140 |
-
function openDatabase(callback, errback) {
|
| 141 |
-
if (isNode) {
|
| 142 |
-
return errback();
|
| 143 |
-
}
|
| 144 |
-
var indexedDB;
|
| 145 |
-
if (typeof window === 'object') {
|
| 146 |
-
indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
| 147 |
-
} else if (typeof location !== 'undefined') {
|
| 148 |
-
// worker
|
| 149 |
-
indexedDB = self.indexedDB;
|
| 150 |
-
} else {
|
| 151 |
-
throw 'using IndexedDB to cache data can only be done on a web page or in a web worker';
|
| 152 |
-
}
|
| 153 |
-
try {
|
| 154 |
-
var openRequest = indexedDB.open(DB_NAME, DB_VERSION);
|
| 155 |
-
} catch (e) {
|
| 156 |
-
return errback(e);
|
| 157 |
-
}
|
| 158 |
-
openRequest.onupgradeneeded = (event) => {
|
| 159 |
-
var db = /** @type {IDBDatabase} */ (event.target.result);
|
| 160 |
-
|
| 161 |
-
if (db.objectStoreNames.contains(PACKAGE_STORE_NAME)) {
|
| 162 |
-
db.deleteObjectStore(PACKAGE_STORE_NAME);
|
| 163 |
-
}
|
| 164 |
-
var packages = db.createObjectStore(PACKAGE_STORE_NAME);
|
| 165 |
-
|
| 166 |
-
if (db.objectStoreNames.contains(METADATA_STORE_NAME)) {
|
| 167 |
-
db.deleteObjectStore(METADATA_STORE_NAME);
|
| 168 |
-
}
|
| 169 |
-
var metadata = db.createObjectStore(METADATA_STORE_NAME);
|
| 170 |
-
};
|
| 171 |
-
openRequest.onsuccess = (event) => {
|
| 172 |
-
var db = /** @type {IDBDatabase} */ (event.target.result);
|
| 173 |
-
callback(db);
|
| 174 |
-
};
|
| 175 |
-
openRequest.onerror = (error) => errback(error);
|
| 176 |
-
};
|
| 177 |
-
|
| 178 |
-
// This is needed as chromium has a limit on per-entry files in IndexedDB
|
| 179 |
-
// https://cs.chromium.org/chromium/src/content/renderer/indexed_db/webidbdatabase_impl.cc?type=cs&sq=package:chromium&g=0&l=177
|
| 180 |
-
// https://cs.chromium.org/chromium/src/out/Debug/gen/third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h?type=cs&sq=package:chromium&g=0&l=60
|
| 181 |
-
// We set the chunk size to 64MB to stay well-below the limit
|
| 182 |
-
var CHUNK_SIZE = 64 * 1024 * 1024;
|
| 183 |
-
|
| 184 |
-
function cacheRemotePackage(
|
| 185 |
-
db,
|
| 186 |
-
packageName,
|
| 187 |
-
packageData,
|
| 188 |
-
packageMeta,
|
| 189 |
-
callback,
|
| 190 |
-
errback
|
| 191 |
-
) {
|
| 192 |
-
var transactionPackages = db.transaction([PACKAGE_STORE_NAME], IDB_RW);
|
| 193 |
-
var packages = transactionPackages.objectStore(PACKAGE_STORE_NAME);
|
| 194 |
-
var chunkSliceStart = 0;
|
| 195 |
-
var nextChunkSliceStart = 0;
|
| 196 |
-
var chunkCount = Math.ceil(packageData.byteLength / CHUNK_SIZE);
|
| 197 |
-
var finishedChunks = 0;
|
| 198 |
-
for (var chunkId = 0; chunkId < chunkCount; chunkId++) {
|
| 199 |
-
nextChunkSliceStart += CHUNK_SIZE;
|
| 200 |
-
var putPackageRequest = packages.put(
|
| 201 |
-
packageData.slice(chunkSliceStart, nextChunkSliceStart),
|
| 202 |
-
`package/${packageName}/${chunkId}`
|
| 203 |
-
);
|
| 204 |
-
chunkSliceStart = nextChunkSliceStart;
|
| 205 |
-
putPackageRequest.onsuccess = (event) => {
|
| 206 |
-
finishedChunks++;
|
| 207 |
-
if (finishedChunks == chunkCount) {
|
| 208 |
-
var transaction_metadata = db.transaction(
|
| 209 |
-
[METADATA_STORE_NAME],
|
| 210 |
-
IDB_RW
|
| 211 |
-
);
|
| 212 |
-
var metadata = transaction_metadata.objectStore(METADATA_STORE_NAME);
|
| 213 |
-
var putMetadataRequest = metadata.put(
|
| 214 |
-
{
|
| 215 |
-
'uuid': packageMeta.uuid,
|
| 216 |
-
'chunkCount': chunkCount
|
| 217 |
-
},
|
| 218 |
-
`metadata/${packageName}`
|
| 219 |
-
);
|
| 220 |
-
putMetadataRequest.onsuccess = (event) => callback(packageData);
|
| 221 |
-
putMetadataRequest.onerror = (error) => errback(error);
|
| 222 |
-
}
|
| 223 |
-
};
|
| 224 |
-
putPackageRequest.onerror = (error) => errback(error);
|
| 225 |
-
}
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
/* Check if there's a cached package, and if so whether it's the latest available */
|
| 229 |
-
function checkCachedPackage(db, packageName, callback, errback) {
|
| 230 |
-
var transaction = db.transaction([METADATA_STORE_NAME], IDB_RO);
|
| 231 |
-
var metadata = transaction.objectStore(METADATA_STORE_NAME);
|
| 232 |
-
var getRequest = metadata.get(`metadata/${packageName}`);
|
| 233 |
-
getRequest.onsuccess = (event) => {
|
| 234 |
-
var result = event.target.result;
|
| 235 |
-
if (!result) {
|
| 236 |
-
return callback(false, null);
|
| 237 |
-
} else {
|
| 238 |
-
return callback(PACKAGE_UUID === result['uuid'], result);
|
| 239 |
-
}
|
| 240 |
-
};
|
| 241 |
-
getRequest.onerror = (error) => errback(error);
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
function fetchCachedPackage(db, packageName, metadata, callback, errback) {
|
| 245 |
-
var transaction = db.transaction([PACKAGE_STORE_NAME], IDB_RO);
|
| 246 |
-
var packages = transaction.objectStore(PACKAGE_STORE_NAME);
|
| 247 |
-
|
| 248 |
-
var chunksDone = 0;
|
| 249 |
-
var totalSize = 0;
|
| 250 |
-
var chunkCount = metadata['chunkCount'];
|
| 251 |
-
var chunks = new Array(chunkCount);
|
| 252 |
-
|
| 253 |
-
for (var chunkId = 0; chunkId < chunkCount; chunkId++) {
|
| 254 |
-
var getRequest = packages.get(`package/${packageName}/${chunkId}`);
|
| 255 |
-
getRequest.onsuccess = (event) => {
|
| 256 |
-
if (!event.target.result) {
|
| 257 |
-
errback(new Error(`CachedPackageNotFound for: ${packageName}`));
|
| 258 |
-
return;
|
| 259 |
-
}
|
| 260 |
-
// If there's only 1 chunk, there's nothing to concatenate it with so we can just return it now
|
| 261 |
-
if (chunkCount == 1) {
|
| 262 |
-
callback(event.target.result);
|
| 263 |
-
} else {
|
| 264 |
-
chunksDone++;
|
| 265 |
-
totalSize += event.target.result.byteLength;
|
| 266 |
-
chunks.push(event.target.result);
|
| 267 |
-
if (chunksDone == chunkCount) {
|
| 268 |
-
if (chunksDone == 1) {
|
| 269 |
-
callback(event.target.result);
|
| 270 |
-
} else {
|
| 271 |
-
var tempTyped = new Uint8Array(totalSize);
|
| 272 |
-
var byteOffset = 0;
|
| 273 |
-
for (var chunkId in chunks) {
|
| 274 |
-
var buffer = chunks[chunkId];
|
| 275 |
-
tempTyped.set(new Uint8Array(buffer), byteOffset);
|
| 276 |
-
byteOffset += buffer.byteLength;
|
| 277 |
-
buffer = undefined;
|
| 278 |
-
}
|
| 279 |
-
chunks = undefined;
|
| 280 |
-
callback(tempTyped.buffer);
|
| 281 |
-
tempTyped = undefined;
|
| 282 |
-
}
|
| 283 |
-
}
|
| 284 |
-
}
|
| 285 |
-
};
|
| 286 |
-
getRequest.onerror = (error) => errback(error);
|
| 287 |
-
}
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
function processPackageData(arrayBuffer) {
|
| 291 |
-
assert(arrayBuffer, 'Loading data file failed.');
|
| 292 |
-
assert(arrayBuffer.constructor.name === ArrayBuffer.name, 'bad input to processPackageData');
|
| 293 |
-
var byteArray = new Uint8Array(arrayBuffer);
|
| 294 |
-
var curr;
|
| 295 |
-
// Reuse the bytearray from the XHR as the source for file reads.
|
| 296 |
-
DataRequest.prototype.byteArray = byteArray;
|
| 297 |
-
var files = metadata['files'];
|
| 298 |
-
for (var i = 0; i < files.length; ++i) {
|
| 299 |
-
DataRequest.prototype.requests[files[i].filename].onload();
|
| 300 |
-
} Module['removeRunDependency']('datafile_de.data');
|
| 301 |
-
|
| 302 |
-
};
|
| 303 |
-
Module['addRunDependency']('datafile_de.data');
|
| 304 |
-
|
| 305 |
-
Module['preloadResults'] ??= {};
|
| 306 |
-
|
| 307 |
-
function preloadFallback(error) {
|
| 308 |
-
console.error(error);
|
| 309 |
-
console.error('falling back to default preload behavior');
|
| 310 |
-
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, processPackageData, handleError);
|
| 311 |
-
};
|
| 312 |
-
|
| 313 |
-
openDatabase(
|
| 314 |
-
(db) => checkCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME,
|
| 315 |
-
(useCached, metadata) => {
|
| 316 |
-
Module['preloadResults'][PACKAGE_NAME] = {fromCache: useCached};
|
| 317 |
-
if (useCached) {
|
| 318 |
-
fetchCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME, metadata, processPackageData, preloadFallback);
|
| 319 |
-
} else {
|
| 320 |
-
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE,
|
| 321 |
-
(packageData) => {
|
| 322 |
-
cacheRemotePackage(db, PACKAGE_PATH + PACKAGE_NAME, packageData, {uuid:PACKAGE_UUID}, processPackageData,
|
| 323 |
-
(error) => {
|
| 324 |
-
console.error(error);
|
| 325 |
-
processPackageData(packageData);
|
| 326 |
-
});
|
| 327 |
-
}
|
| 328 |
-
, preloadFallback);
|
| 329 |
-
}
|
| 330 |
-
}, preloadFallback)
|
| 331 |
-
, preloadFallback);
|
| 332 |
-
|
| 333 |
-
Module['setStatus']?.('Downloading...');
|
| 334 |
-
|
| 335 |
-
}
|
| 336 |
-
if (Module['calledRun']) {
|
| 337 |
-
runWithFS(Module);
|
| 338 |
-
} else {
|
| 339 |
-
(Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
Module['removeRunDependency']('de.js.metadata');
|
| 343 |
-
}
|
| 344 |
-
|
| 345 |
-
function runMetaWithFS() {
|
| 346 |
-
Module['addRunDependency']('de.js.metadata');
|
| 347 |
-
var metadataUrl = Module['locateFile'] ? Module['locateFile']('de.js.metadata', '') : 'de.js.metadata';
|
| 348 |
-
if (isNode) {
|
| 349 |
-
require('fs').readFile(metadataUrl, 'utf8', (err, contents) => {
|
| 350 |
-
if (err) {
|
| 351 |
-
return Promise.reject(err);
|
| 352 |
-
} else {
|
| 353 |
-
loadPackage(JSON.parse(contents));
|
| 354 |
-
}
|
| 355 |
-
});
|
| 356 |
-
return;
|
| 357 |
-
}
|
| 358 |
-
fetch(metadataUrl)
|
| 359 |
-
.then((response) => {
|
| 360 |
-
if (response.ok) {
|
| 361 |
-
return response.json();
|
| 362 |
-
}
|
| 363 |
-
return Promise.reject(new Error(`${response.status}: ${response.url}`));
|
| 364 |
-
})
|
| 365 |
-
.then(loadPackage);
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
if (Module['calledRun']) {
|
| 369 |
-
runMetaWithFS();
|
| 370 |
-
} else {
|
| 371 |
-
(Module['preRun'] ??= []).push(runMetaWithFS);
|
| 372 |
-
}
|
| 373 |
-
|
| 374 |
-
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
de.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
{"files":[{"filename":"/.gitignore","start":0,"end":0},{"filename":"/README.md","start":0,"end":3029},{"filename":"/decoder.onnx","start":3029,"end":620518},{"filename":"/encoder.onnx","start":620518,"end":70712075},{"filename":"/joiner.onnx","start":70712075,"end":71048892},{"filename":"/tokens.txt","start":71048892,"end":71054498}],"remote_package_size":71054498,"package_uuid":"sha256-18d2e7f52fb932018b08f444f4f5fbbdba4404454c023d5d443e13ac6eb4110b"}
|
|
|
|
|
|
de1.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:58f5d846eb58e76d86b6e74f68459518939239f35cbe518bac895e6790f31253
|
| 3 |
-
size 34605
|
|
|
|
|
|
|
|
|
|
|
|
de2.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:08fb88c6a4dce4a1911fbc616ac54df38e9d0e4687ee2701ed578577df0a95c7
|
| 3 |
-
size 31617
|
|
|
|
|
|
|
|
|
|
|
|
de3.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:cec963082e1a6fb936f3d16a803c4dd5b5648302af3d2232924274bf7f2b2820
|
| 3 |
-
size 15309
|
|
|
|
|
|
|
|
|
|
|
|
de4.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:766d4b4b03697ff63dd60c1214893e8cedd2e184bc451cf19d93d48b7675f71f
|
| 3 |
-
size 10701
|
|
|
|
|
|
|
|
|
|
|
|
de5.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:62b699120379363299db355ae621d42903bf773a2061a72585ad8e4e44032a9a
|
| 3 |
-
size 25965
|
|
|
|
|
|
|
|
|
|
|
|
en.data
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:1838b94374576507f0efaaf3aa91bb921072cdf46c8802a7c12acc527b7e1f0e
|
| 3 |
-
size 71056243
|
|
|
|
|
|
|
|
|
|
|
|
en.js
DELETED
|
@@ -1,374 +0,0 @@
|
|
| 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 = 'en.data';
|
| 22 |
-
var REMOTE_PACKAGE_BASE = 'en.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 |
-
function runWithFS(Module) {
|
| 96 |
-
|
| 97 |
-
function assert(check, msg) {
|
| 98 |
-
if (!check) throw msg + new Error().stack;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/** @constructor */
|
| 102 |
-
function DataRequest(start, end, audio) {
|
| 103 |
-
this.start = start;
|
| 104 |
-
this.end = end;
|
| 105 |
-
this.audio = audio;
|
| 106 |
-
}
|
| 107 |
-
DataRequest.prototype = {
|
| 108 |
-
requests: {},
|
| 109 |
-
open: function(mode, name) {
|
| 110 |
-
this.name = name;
|
| 111 |
-
this.requests[name] = this;
|
| 112 |
-
Module['addRunDependency'](`fp ${this.name}`);
|
| 113 |
-
},
|
| 114 |
-
send: function() {},
|
| 115 |
-
onload: function() {
|
| 116 |
-
var byteArray = this.byteArray.subarray(this.start, this.end);
|
| 117 |
-
this.finish(byteArray);
|
| 118 |
-
},
|
| 119 |
-
finish: function(byteArray) {
|
| 120 |
-
var that = this;
|
| 121 |
-
// canOwn this data in the filesystem, it is a slide into the heap that will never change
|
| 122 |
-
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
|
| 123 |
-
Module['removeRunDependency'](`fp ${that.name}`);
|
| 124 |
-
this.requests[this.name] = null;
|
| 125 |
-
}
|
| 126 |
-
};
|
| 127 |
-
|
| 128 |
-
var files = metadata['files'];
|
| 129 |
-
for (var i = 0; i < files.length; ++i) {
|
| 130 |
-
new DataRequest(files[i]['start'], files[i]['end'], files[i]['audio'] || 0).open('GET', files[i]['filename']);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
var PACKAGE_UUID = metadata['package_uuid'];
|
| 134 |
-
var IDB_RO = "readonly";
|
| 135 |
-
var IDB_RW = "readwrite";
|
| 136 |
-
var DB_NAME = "EM_PRELOAD_CACHE";
|
| 137 |
-
var DB_VERSION = 1;
|
| 138 |
-
var METADATA_STORE_NAME = 'METADATA';
|
| 139 |
-
var PACKAGE_STORE_NAME = 'PACKAGES';
|
| 140 |
-
function openDatabase(callback, errback) {
|
| 141 |
-
if (isNode) {
|
| 142 |
-
return errback();
|
| 143 |
-
}
|
| 144 |
-
var indexedDB;
|
| 145 |
-
if (typeof window === 'object') {
|
| 146 |
-
indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
| 147 |
-
} else if (typeof location !== 'undefined') {
|
| 148 |
-
// worker
|
| 149 |
-
indexedDB = self.indexedDB;
|
| 150 |
-
} else {
|
| 151 |
-
throw 'using IndexedDB to cache data can only be done on a web page or in a web worker';
|
| 152 |
-
}
|
| 153 |
-
try {
|
| 154 |
-
var openRequest = indexedDB.open(DB_NAME, DB_VERSION);
|
| 155 |
-
} catch (e) {
|
| 156 |
-
return errback(e);
|
| 157 |
-
}
|
| 158 |
-
openRequest.onupgradeneeded = (event) => {
|
| 159 |
-
var db = /** @type {IDBDatabase} */ (event.target.result);
|
| 160 |
-
|
| 161 |
-
if (db.objectStoreNames.contains(PACKAGE_STORE_NAME)) {
|
| 162 |
-
db.deleteObjectStore(PACKAGE_STORE_NAME);
|
| 163 |
-
}
|
| 164 |
-
var packages = db.createObjectStore(PACKAGE_STORE_NAME);
|
| 165 |
-
|
| 166 |
-
if (db.objectStoreNames.contains(METADATA_STORE_NAME)) {
|
| 167 |
-
db.deleteObjectStore(METADATA_STORE_NAME);
|
| 168 |
-
}
|
| 169 |
-
var metadata = db.createObjectStore(METADATA_STORE_NAME);
|
| 170 |
-
};
|
| 171 |
-
openRequest.onsuccess = (event) => {
|
| 172 |
-
var db = /** @type {IDBDatabase} */ (event.target.result);
|
| 173 |
-
callback(db);
|
| 174 |
-
};
|
| 175 |
-
openRequest.onerror = (error) => errback(error);
|
| 176 |
-
};
|
| 177 |
-
|
| 178 |
-
// This is needed as chromium has a limit on per-entry files in IndexedDB
|
| 179 |
-
// https://cs.chromium.org/chromium/src/content/renderer/indexed_db/webidbdatabase_impl.cc?type=cs&sq=package:chromium&g=0&l=177
|
| 180 |
-
// https://cs.chromium.org/chromium/src/out/Debug/gen/third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h?type=cs&sq=package:chromium&g=0&l=60
|
| 181 |
-
// We set the chunk size to 64MB to stay well-below the limit
|
| 182 |
-
var CHUNK_SIZE = 64 * 1024 * 1024;
|
| 183 |
-
|
| 184 |
-
function cacheRemotePackage(
|
| 185 |
-
db,
|
| 186 |
-
packageName,
|
| 187 |
-
packageData,
|
| 188 |
-
packageMeta,
|
| 189 |
-
callback,
|
| 190 |
-
errback
|
| 191 |
-
) {
|
| 192 |
-
var transactionPackages = db.transaction([PACKAGE_STORE_NAME], IDB_RW);
|
| 193 |
-
var packages = transactionPackages.objectStore(PACKAGE_STORE_NAME);
|
| 194 |
-
var chunkSliceStart = 0;
|
| 195 |
-
var nextChunkSliceStart = 0;
|
| 196 |
-
var chunkCount = Math.ceil(packageData.byteLength / CHUNK_SIZE);
|
| 197 |
-
var finishedChunks = 0;
|
| 198 |
-
for (var chunkId = 0; chunkId < chunkCount; chunkId++) {
|
| 199 |
-
nextChunkSliceStart += CHUNK_SIZE;
|
| 200 |
-
var putPackageRequest = packages.put(
|
| 201 |
-
packageData.slice(chunkSliceStart, nextChunkSliceStart),
|
| 202 |
-
`package/${packageName}/${chunkId}`
|
| 203 |
-
);
|
| 204 |
-
chunkSliceStart = nextChunkSliceStart;
|
| 205 |
-
putPackageRequest.onsuccess = (event) => {
|
| 206 |
-
finishedChunks++;
|
| 207 |
-
if (finishedChunks == chunkCount) {
|
| 208 |
-
var transaction_metadata = db.transaction(
|
| 209 |
-
[METADATA_STORE_NAME],
|
| 210 |
-
IDB_RW
|
| 211 |
-
);
|
| 212 |
-
var metadata = transaction_metadata.objectStore(METADATA_STORE_NAME);
|
| 213 |
-
var putMetadataRequest = metadata.put(
|
| 214 |
-
{
|
| 215 |
-
'uuid': packageMeta.uuid,
|
| 216 |
-
'chunkCount': chunkCount
|
| 217 |
-
},
|
| 218 |
-
`metadata/${packageName}`
|
| 219 |
-
);
|
| 220 |
-
putMetadataRequest.onsuccess = (event) => callback(packageData);
|
| 221 |
-
putMetadataRequest.onerror = (error) => errback(error);
|
| 222 |
-
}
|
| 223 |
-
};
|
| 224 |
-
putPackageRequest.onerror = (error) => errback(error);
|
| 225 |
-
}
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
/* Check if there's a cached package, and if so whether it's the latest available */
|
| 229 |
-
function checkCachedPackage(db, packageName, callback, errback) {
|
| 230 |
-
var transaction = db.transaction([METADATA_STORE_NAME], IDB_RO);
|
| 231 |
-
var metadata = transaction.objectStore(METADATA_STORE_NAME);
|
| 232 |
-
var getRequest = metadata.get(`metadata/${packageName}`);
|
| 233 |
-
getRequest.onsuccess = (event) => {
|
| 234 |
-
var result = event.target.result;
|
| 235 |
-
if (!result) {
|
| 236 |
-
return callback(false, null);
|
| 237 |
-
} else {
|
| 238 |
-
return callback(PACKAGE_UUID === result['uuid'], result);
|
| 239 |
-
}
|
| 240 |
-
};
|
| 241 |
-
getRequest.onerror = (error) => errback(error);
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
function fetchCachedPackage(db, packageName, metadata, callback, errback) {
|
| 245 |
-
var transaction = db.transaction([PACKAGE_STORE_NAME], IDB_RO);
|
| 246 |
-
var packages = transaction.objectStore(PACKAGE_STORE_NAME);
|
| 247 |
-
|
| 248 |
-
var chunksDone = 0;
|
| 249 |
-
var totalSize = 0;
|
| 250 |
-
var chunkCount = metadata['chunkCount'];
|
| 251 |
-
var chunks = new Array(chunkCount);
|
| 252 |
-
|
| 253 |
-
for (var chunkId = 0; chunkId < chunkCount; chunkId++) {
|
| 254 |
-
var getRequest = packages.get(`package/${packageName}/${chunkId}`);
|
| 255 |
-
getRequest.onsuccess = (event) => {
|
| 256 |
-
if (!event.target.result) {
|
| 257 |
-
errback(new Error(`CachedPackageNotFound for: ${packageName}`));
|
| 258 |
-
return;
|
| 259 |
-
}
|
| 260 |
-
// If there's only 1 chunk, there's nothing to concatenate it with so we can just return it now
|
| 261 |
-
if (chunkCount == 1) {
|
| 262 |
-
callback(event.target.result);
|
| 263 |
-
} else {
|
| 264 |
-
chunksDone++;
|
| 265 |
-
totalSize += event.target.result.byteLength;
|
| 266 |
-
chunks.push(event.target.result);
|
| 267 |
-
if (chunksDone == chunkCount) {
|
| 268 |
-
if (chunksDone == 1) {
|
| 269 |
-
callback(event.target.result);
|
| 270 |
-
} else {
|
| 271 |
-
var tempTyped = new Uint8Array(totalSize);
|
| 272 |
-
var byteOffset = 0;
|
| 273 |
-
for (var chunkId in chunks) {
|
| 274 |
-
var buffer = chunks[chunkId];
|
| 275 |
-
tempTyped.set(new Uint8Array(buffer), byteOffset);
|
| 276 |
-
byteOffset += buffer.byteLength;
|
| 277 |
-
buffer = undefined;
|
| 278 |
-
}
|
| 279 |
-
chunks = undefined;
|
| 280 |
-
callback(tempTyped.buffer);
|
| 281 |
-
tempTyped = undefined;
|
| 282 |
-
}
|
| 283 |
-
}
|
| 284 |
-
}
|
| 285 |
-
};
|
| 286 |
-
getRequest.onerror = (error) => errback(error);
|
| 287 |
-
}
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
function processPackageData(arrayBuffer) {
|
| 291 |
-
assert(arrayBuffer, 'Loading data file failed.');
|
| 292 |
-
assert(arrayBuffer.constructor.name === ArrayBuffer.name, 'bad input to processPackageData');
|
| 293 |
-
var byteArray = new Uint8Array(arrayBuffer);
|
| 294 |
-
var curr;
|
| 295 |
-
// Reuse the bytearray from the XHR as the source for file reads.
|
| 296 |
-
DataRequest.prototype.byteArray = byteArray;
|
| 297 |
-
var files = metadata['files'];
|
| 298 |
-
for (var i = 0; i < files.length; ++i) {
|
| 299 |
-
DataRequest.prototype.requests[files[i].filename].onload();
|
| 300 |
-
} Module['removeRunDependency']('datafile_en.data');
|
| 301 |
-
|
| 302 |
-
};
|
| 303 |
-
Module['addRunDependency']('datafile_en.data');
|
| 304 |
-
|
| 305 |
-
Module['preloadResults'] ??= {};
|
| 306 |
-
|
| 307 |
-
function preloadFallback(error) {
|
| 308 |
-
console.error(error);
|
| 309 |
-
console.error('falling back to default preload behavior');
|
| 310 |
-
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, processPackageData, handleError);
|
| 311 |
-
};
|
| 312 |
-
|
| 313 |
-
openDatabase(
|
| 314 |
-
(db) => checkCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME,
|
| 315 |
-
(useCached, metadata) => {
|
| 316 |
-
Module['preloadResults'][PACKAGE_NAME] = {fromCache: useCached};
|
| 317 |
-
if (useCached) {
|
| 318 |
-
fetchCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME, metadata, processPackageData, preloadFallback);
|
| 319 |
-
} else {
|
| 320 |
-
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE,
|
| 321 |
-
(packageData) => {
|
| 322 |
-
cacheRemotePackage(db, PACKAGE_PATH + PACKAGE_NAME, packageData, {uuid:PACKAGE_UUID}, processPackageData,
|
| 323 |
-
(error) => {
|
| 324 |
-
console.error(error);
|
| 325 |
-
processPackageData(packageData);
|
| 326 |
-
});
|
| 327 |
-
}
|
| 328 |
-
, preloadFallback);
|
| 329 |
-
}
|
| 330 |
-
}, preloadFallback)
|
| 331 |
-
, preloadFallback);
|
| 332 |
-
|
| 333 |
-
Module['setStatus']?.('Downloading...');
|
| 334 |
-
|
| 335 |
-
}
|
| 336 |
-
if (Module['calledRun']) {
|
| 337 |
-
runWithFS(Module);
|
| 338 |
-
} else {
|
| 339 |
-
(Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
Module['removeRunDependency']('en.js.metadata');
|
| 343 |
-
}
|
| 344 |
-
|
| 345 |
-
function runMetaWithFS() {
|
| 346 |
-
Module['addRunDependency']('en.js.metadata');
|
| 347 |
-
var metadataUrl = Module['locateFile'] ? Module['locateFile']('en.js.metadata', '') : 'en.js.metadata';
|
| 348 |
-
if (isNode) {
|
| 349 |
-
require('fs').readFile(metadataUrl, 'utf8', (err, contents) => {
|
| 350 |
-
if (err) {
|
| 351 |
-
return Promise.reject(err);
|
| 352 |
-
} else {
|
| 353 |
-
loadPackage(JSON.parse(contents));
|
| 354 |
-
}
|
| 355 |
-
});
|
| 356 |
-
return;
|
| 357 |
-
}
|
| 358 |
-
fetch(metadataUrl)
|
| 359 |
-
.then((response) => {
|
| 360 |
-
if (response.ok) {
|
| 361 |
-
return response.json();
|
| 362 |
-
}
|
| 363 |
-
return Promise.reject(new Error(`${response.status}: ${response.url}`));
|
| 364 |
-
})
|
| 365 |
-
.then(loadPackage);
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
if (Module['calledRun']) {
|
| 369 |
-
runMetaWithFS();
|
| 370 |
-
} else {
|
| 371 |
-
(Module['preRun'] ??= []).push(runMetaWithFS);
|
| 372 |
-
}
|
| 373 |
-
|
| 374 |
-
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
en.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 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,"package_uuid":"sha256-1838b94374576507f0efaaf3aa91bb921072cdf46c8802a7c12acc527b7e1f0e"}
|
|
|
|
|
|
en1.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:89147d7f58c668dcfe2c888273178ed8139cf326ac024a655e4fe2f6446c818e
|
| 3 |
-
size 24093
|
|
|
|
|
|
|
|
|
|
|
|
en2.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:8dfe5b22502a279470a5ac891e742f85a1691d432d14ea91234771afd6ab83d9
|
| 3 |
-
size 42849
|
|
|
|
|
|
|
|
|
|
|
|
en3.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:d7cb8825a3258d7db06933a47c0a76ba63909453b0722dc510c5847a97059766
|
| 3 |
-
size 44685
|
|
|
|
|
|
|
|
|
|
|
|
en4.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:1dfe856ebf14712388bf85c6bb85cd0cf1038d4d4c7426c07765de74522b5c36
|
| 3 |
-
size 39213
|
|
|
|
|
|
|
|
|
|
|
|
en5.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:bef1c5a970e6f06f917010d6fdba2da4501870a78a05659d5565daab2e1d7cca
|
| 3 |
-
size 32301
|
|
|
|
|
|
|
|
|
|
|
|
fr.data
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:97d77f564f21cad9487ace162b7c4f4f42d2077f0a9bb0bc87d0f4964b5b59fc
|
| 3 |
-
size 71055348
|
|
|
|
|
|
|
|
|
|
|
|
fr.js
DELETED
|
@@ -1,374 +0,0 @@
|
|
| 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 = 'fr.data';
|
| 22 |
-
var REMOTE_PACKAGE_BASE = 'fr.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 |
-
function runWithFS(Module) {
|
| 96 |
-
|
| 97 |
-
function assert(check, msg) {
|
| 98 |
-
if (!check) throw msg + new Error().stack;
|
| 99 |
-
}
|
| 100 |
-
|
| 101 |
-
/** @constructor */
|
| 102 |
-
function DataRequest(start, end, audio) {
|
| 103 |
-
this.start = start;
|
| 104 |
-
this.end = end;
|
| 105 |
-
this.audio = audio;
|
| 106 |
-
}
|
| 107 |
-
DataRequest.prototype = {
|
| 108 |
-
requests: {},
|
| 109 |
-
open: function(mode, name) {
|
| 110 |
-
this.name = name;
|
| 111 |
-
this.requests[name] = this;
|
| 112 |
-
Module['addRunDependency'](`fp ${this.name}`);
|
| 113 |
-
},
|
| 114 |
-
send: function() {},
|
| 115 |
-
onload: function() {
|
| 116 |
-
var byteArray = this.byteArray.subarray(this.start, this.end);
|
| 117 |
-
this.finish(byteArray);
|
| 118 |
-
},
|
| 119 |
-
finish: function(byteArray) {
|
| 120 |
-
var that = this;
|
| 121 |
-
// canOwn this data in the filesystem, it is a slide into the heap that will never change
|
| 122 |
-
Module['FS_createDataFile'](this.name, null, byteArray, true, true, true);
|
| 123 |
-
Module['removeRunDependency'](`fp ${that.name}`);
|
| 124 |
-
this.requests[this.name] = null;
|
| 125 |
-
}
|
| 126 |
-
};
|
| 127 |
-
|
| 128 |
-
var files = metadata['files'];
|
| 129 |
-
for (var i = 0; i < files.length; ++i) {
|
| 130 |
-
new DataRequest(files[i]['start'], files[i]['end'], files[i]['audio'] || 0).open('GET', files[i]['filename']);
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
-
var PACKAGE_UUID = metadata['package_uuid'];
|
| 134 |
-
var IDB_RO = "readonly";
|
| 135 |
-
var IDB_RW = "readwrite";
|
| 136 |
-
var DB_NAME = "EM_PRELOAD_CACHE";
|
| 137 |
-
var DB_VERSION = 1;
|
| 138 |
-
var METADATA_STORE_NAME = 'METADATA';
|
| 139 |
-
var PACKAGE_STORE_NAME = 'PACKAGES';
|
| 140 |
-
function openDatabase(callback, errback) {
|
| 141 |
-
if (isNode) {
|
| 142 |
-
return errback();
|
| 143 |
-
}
|
| 144 |
-
var indexedDB;
|
| 145 |
-
if (typeof window === 'object') {
|
| 146 |
-
indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
|
| 147 |
-
} else if (typeof location !== 'undefined') {
|
| 148 |
-
// worker
|
| 149 |
-
indexedDB = self.indexedDB;
|
| 150 |
-
} else {
|
| 151 |
-
throw 'using IndexedDB to cache data can only be done on a web page or in a web worker';
|
| 152 |
-
}
|
| 153 |
-
try {
|
| 154 |
-
var openRequest = indexedDB.open(DB_NAME, DB_VERSION);
|
| 155 |
-
} catch (e) {
|
| 156 |
-
return errback(e);
|
| 157 |
-
}
|
| 158 |
-
openRequest.onupgradeneeded = (event) => {
|
| 159 |
-
var db = /** @type {IDBDatabase} */ (event.target.result);
|
| 160 |
-
|
| 161 |
-
if (db.objectStoreNames.contains(PACKAGE_STORE_NAME)) {
|
| 162 |
-
db.deleteObjectStore(PACKAGE_STORE_NAME);
|
| 163 |
-
}
|
| 164 |
-
var packages = db.createObjectStore(PACKAGE_STORE_NAME);
|
| 165 |
-
|
| 166 |
-
if (db.objectStoreNames.contains(METADATA_STORE_NAME)) {
|
| 167 |
-
db.deleteObjectStore(METADATA_STORE_NAME);
|
| 168 |
-
}
|
| 169 |
-
var metadata = db.createObjectStore(METADATA_STORE_NAME);
|
| 170 |
-
};
|
| 171 |
-
openRequest.onsuccess = (event) => {
|
| 172 |
-
var db = /** @type {IDBDatabase} */ (event.target.result);
|
| 173 |
-
callback(db);
|
| 174 |
-
};
|
| 175 |
-
openRequest.onerror = (error) => errback(error);
|
| 176 |
-
};
|
| 177 |
-
|
| 178 |
-
// This is needed as chromium has a limit on per-entry files in IndexedDB
|
| 179 |
-
// https://cs.chromium.org/chromium/src/content/renderer/indexed_db/webidbdatabase_impl.cc?type=cs&sq=package:chromium&g=0&l=177
|
| 180 |
-
// https://cs.chromium.org/chromium/src/out/Debug/gen/third_party/blink/public/mojom/indexeddb/indexeddb.mojom.h?type=cs&sq=package:chromium&g=0&l=60
|
| 181 |
-
// We set the chunk size to 64MB to stay well-below the limit
|
| 182 |
-
var CHUNK_SIZE = 64 * 1024 * 1024;
|
| 183 |
-
|
| 184 |
-
function cacheRemotePackage(
|
| 185 |
-
db,
|
| 186 |
-
packageName,
|
| 187 |
-
packageData,
|
| 188 |
-
packageMeta,
|
| 189 |
-
callback,
|
| 190 |
-
errback
|
| 191 |
-
) {
|
| 192 |
-
var transactionPackages = db.transaction([PACKAGE_STORE_NAME], IDB_RW);
|
| 193 |
-
var packages = transactionPackages.objectStore(PACKAGE_STORE_NAME);
|
| 194 |
-
var chunkSliceStart = 0;
|
| 195 |
-
var nextChunkSliceStart = 0;
|
| 196 |
-
var chunkCount = Math.ceil(packageData.byteLength / CHUNK_SIZE);
|
| 197 |
-
var finishedChunks = 0;
|
| 198 |
-
for (var chunkId = 0; chunkId < chunkCount; chunkId++) {
|
| 199 |
-
nextChunkSliceStart += CHUNK_SIZE;
|
| 200 |
-
var putPackageRequest = packages.put(
|
| 201 |
-
packageData.slice(chunkSliceStart, nextChunkSliceStart),
|
| 202 |
-
`package/${packageName}/${chunkId}`
|
| 203 |
-
);
|
| 204 |
-
chunkSliceStart = nextChunkSliceStart;
|
| 205 |
-
putPackageRequest.onsuccess = (event) => {
|
| 206 |
-
finishedChunks++;
|
| 207 |
-
if (finishedChunks == chunkCount) {
|
| 208 |
-
var transaction_metadata = db.transaction(
|
| 209 |
-
[METADATA_STORE_NAME],
|
| 210 |
-
IDB_RW
|
| 211 |
-
);
|
| 212 |
-
var metadata = transaction_metadata.objectStore(METADATA_STORE_NAME);
|
| 213 |
-
var putMetadataRequest = metadata.put(
|
| 214 |
-
{
|
| 215 |
-
'uuid': packageMeta.uuid,
|
| 216 |
-
'chunkCount': chunkCount
|
| 217 |
-
},
|
| 218 |
-
`metadata/${packageName}`
|
| 219 |
-
);
|
| 220 |
-
putMetadataRequest.onsuccess = (event) => callback(packageData);
|
| 221 |
-
putMetadataRequest.onerror = (error) => errback(error);
|
| 222 |
-
}
|
| 223 |
-
};
|
| 224 |
-
putPackageRequest.onerror = (error) => errback(error);
|
| 225 |
-
}
|
| 226 |
-
}
|
| 227 |
-
|
| 228 |
-
/* Check if there's a cached package, and if so whether it's the latest available */
|
| 229 |
-
function checkCachedPackage(db, packageName, callback, errback) {
|
| 230 |
-
var transaction = db.transaction([METADATA_STORE_NAME], IDB_RO);
|
| 231 |
-
var metadata = transaction.objectStore(METADATA_STORE_NAME);
|
| 232 |
-
var getRequest = metadata.get(`metadata/${packageName}`);
|
| 233 |
-
getRequest.onsuccess = (event) => {
|
| 234 |
-
var result = event.target.result;
|
| 235 |
-
if (!result) {
|
| 236 |
-
return callback(false, null);
|
| 237 |
-
} else {
|
| 238 |
-
return callback(PACKAGE_UUID === result['uuid'], result);
|
| 239 |
-
}
|
| 240 |
-
};
|
| 241 |
-
getRequest.onerror = (error) => errback(error);
|
| 242 |
-
}
|
| 243 |
-
|
| 244 |
-
function fetchCachedPackage(db, packageName, metadata, callback, errback) {
|
| 245 |
-
var transaction = db.transaction([PACKAGE_STORE_NAME], IDB_RO);
|
| 246 |
-
var packages = transaction.objectStore(PACKAGE_STORE_NAME);
|
| 247 |
-
|
| 248 |
-
var chunksDone = 0;
|
| 249 |
-
var totalSize = 0;
|
| 250 |
-
var chunkCount = metadata['chunkCount'];
|
| 251 |
-
var chunks = new Array(chunkCount);
|
| 252 |
-
|
| 253 |
-
for (var chunkId = 0; chunkId < chunkCount; chunkId++) {
|
| 254 |
-
var getRequest = packages.get(`package/${packageName}/${chunkId}`);
|
| 255 |
-
getRequest.onsuccess = (event) => {
|
| 256 |
-
if (!event.target.result) {
|
| 257 |
-
errback(new Error(`CachedPackageNotFound for: ${packageName}`));
|
| 258 |
-
return;
|
| 259 |
-
}
|
| 260 |
-
// If there's only 1 chunk, there's nothing to concatenate it with so we can just return it now
|
| 261 |
-
if (chunkCount == 1) {
|
| 262 |
-
callback(event.target.result);
|
| 263 |
-
} else {
|
| 264 |
-
chunksDone++;
|
| 265 |
-
totalSize += event.target.result.byteLength;
|
| 266 |
-
chunks.push(event.target.result);
|
| 267 |
-
if (chunksDone == chunkCount) {
|
| 268 |
-
if (chunksDone == 1) {
|
| 269 |
-
callback(event.target.result);
|
| 270 |
-
} else {
|
| 271 |
-
var tempTyped = new Uint8Array(totalSize);
|
| 272 |
-
var byteOffset = 0;
|
| 273 |
-
for (var chunkId in chunks) {
|
| 274 |
-
var buffer = chunks[chunkId];
|
| 275 |
-
tempTyped.set(new Uint8Array(buffer), byteOffset);
|
| 276 |
-
byteOffset += buffer.byteLength;
|
| 277 |
-
buffer = undefined;
|
| 278 |
-
}
|
| 279 |
-
chunks = undefined;
|
| 280 |
-
callback(tempTyped.buffer);
|
| 281 |
-
tempTyped = undefined;
|
| 282 |
-
}
|
| 283 |
-
}
|
| 284 |
-
}
|
| 285 |
-
};
|
| 286 |
-
getRequest.onerror = (error) => errback(error);
|
| 287 |
-
}
|
| 288 |
-
}
|
| 289 |
-
|
| 290 |
-
function processPackageData(arrayBuffer) {
|
| 291 |
-
assert(arrayBuffer, 'Loading data file failed.');
|
| 292 |
-
assert(arrayBuffer.constructor.name === ArrayBuffer.name, 'bad input to processPackageData');
|
| 293 |
-
var byteArray = new Uint8Array(arrayBuffer);
|
| 294 |
-
var curr;
|
| 295 |
-
// Reuse the bytearray from the XHR as the source for file reads.
|
| 296 |
-
DataRequest.prototype.byteArray = byteArray;
|
| 297 |
-
var files = metadata['files'];
|
| 298 |
-
for (var i = 0; i < files.length; ++i) {
|
| 299 |
-
DataRequest.prototype.requests[files[i].filename].onload();
|
| 300 |
-
} Module['removeRunDependency']('datafile_fr.data');
|
| 301 |
-
|
| 302 |
-
};
|
| 303 |
-
Module['addRunDependency']('datafile_fr.data');
|
| 304 |
-
|
| 305 |
-
Module['preloadResults'] ??= {};
|
| 306 |
-
|
| 307 |
-
function preloadFallback(error) {
|
| 308 |
-
console.error(error);
|
| 309 |
-
console.error('falling back to default preload behavior');
|
| 310 |
-
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE, processPackageData, handleError);
|
| 311 |
-
};
|
| 312 |
-
|
| 313 |
-
openDatabase(
|
| 314 |
-
(db) => checkCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME,
|
| 315 |
-
(useCached, metadata) => {
|
| 316 |
-
Module['preloadResults'][PACKAGE_NAME] = {fromCache: useCached};
|
| 317 |
-
if (useCached) {
|
| 318 |
-
fetchCachedPackage(db, PACKAGE_PATH + PACKAGE_NAME, metadata, processPackageData, preloadFallback);
|
| 319 |
-
} else {
|
| 320 |
-
fetchRemotePackage(REMOTE_PACKAGE_NAME, REMOTE_PACKAGE_SIZE,
|
| 321 |
-
(packageData) => {
|
| 322 |
-
cacheRemotePackage(db, PACKAGE_PATH + PACKAGE_NAME, packageData, {uuid:PACKAGE_UUID}, processPackageData,
|
| 323 |
-
(error) => {
|
| 324 |
-
console.error(error);
|
| 325 |
-
processPackageData(packageData);
|
| 326 |
-
});
|
| 327 |
-
}
|
| 328 |
-
, preloadFallback);
|
| 329 |
-
}
|
| 330 |
-
}, preloadFallback)
|
| 331 |
-
, preloadFallback);
|
| 332 |
-
|
| 333 |
-
Module['setStatus']?.('Downloading...');
|
| 334 |
-
|
| 335 |
-
}
|
| 336 |
-
if (Module['calledRun']) {
|
| 337 |
-
runWithFS(Module);
|
| 338 |
-
} else {
|
| 339 |
-
(Module['preRun'] ??= []).push(runWithFS); // FS is not initialized yet, wait for it
|
| 340 |
-
}
|
| 341 |
-
|
| 342 |
-
Module['removeRunDependency']('fr.js.metadata');
|
| 343 |
-
}
|
| 344 |
-
|
| 345 |
-
function runMetaWithFS() {
|
| 346 |
-
Module['addRunDependency']('fr.js.metadata');
|
| 347 |
-
var metadataUrl = Module['locateFile'] ? Module['locateFile']('fr.js.metadata', '') : 'fr.js.metadata';
|
| 348 |
-
if (isNode) {
|
| 349 |
-
require('fs').readFile(metadataUrl, 'utf8', (err, contents) => {
|
| 350 |
-
if (err) {
|
| 351 |
-
return Promise.reject(err);
|
| 352 |
-
} else {
|
| 353 |
-
loadPackage(JSON.parse(contents));
|
| 354 |
-
}
|
| 355 |
-
});
|
| 356 |
-
return;
|
| 357 |
-
}
|
| 358 |
-
fetch(metadataUrl)
|
| 359 |
-
.then((response) => {
|
| 360 |
-
if (response.ok) {
|
| 361 |
-
return response.json();
|
| 362 |
-
}
|
| 363 |
-
return Promise.reject(new Error(`${response.status}: ${response.url}`));
|
| 364 |
-
})
|
| 365 |
-
.then(loadPackage);
|
| 366 |
-
}
|
| 367 |
-
|
| 368 |
-
if (Module['calledRun']) {
|
| 369 |
-
runMetaWithFS();
|
| 370 |
-
} else {
|
| 371 |
-
(Module['preRun'] ??= []).push(runMetaWithFS);
|
| 372 |
-
}
|
| 373 |
-
|
| 374 |
-
})();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fr.json
DELETED
|
@@ -1 +0,0 @@
|
|
| 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,"package_uuid":"sha256-97d77f564f21cad9487ace162b7c4f4f42d2077f0a9bb0bc87d0f4964b5b59fc"}
|
|
|
|
|
|
fr1.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:d04afe1a7330543289b2c6d9a9758376d35d16f2ccf4fcbb94ef088bc68413ed
|
| 3 |
-
size 38565
|
|
|
|
|
|
|
|
|
|
|
|
fr2.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:2a95295ec129eb278bfddd4f50c98d17499bc2a0185889e6a8b940d2f29571a5
|
| 3 |
-
size 43749
|
|
|
|
|
|
|
|
|
|
|
|
fr3.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:a9229e6962aed169d90ef5886fb8ae5ac6e2b6afc72fff31370382c7205a0729
|
| 3 |
-
size 23085
|
|
|
|
|
|
|
|
|
|
|
|
fr4.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:bb3d55b91a863c51f665d68eae5d483599419063ce36585547e3f66c7598dfb1
|
| 3 |
-
size 41733
|
|
|
|
|
|
|
|
|
|
|
|
fr5.mp3
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:761512c8c50406106adc114abded18426b773eb9184cba3878602d1eabbb3d01
|
| 3 |
-
size 22545
|
|
|
|
|
|
|
|
|
|
|
|
index.html
CHANGED
|
@@ -5,60 +5,102 @@
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<title>Audio Input with Tabs and Features</title>
|
| 7 |
<style>
|
| 8 |
-
.
|
| 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 |
-
<
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
</div>
|
| 22 |
|
| 23 |
-
<
|
| 24 |
-
|
| 25 |
-
<
|
| 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="de" style="margin: 0;" />
|
| 31 |
-
<img src="https://flagcdn.com/de.svg" alt="Germany Flag" style="width: 20px; height: 14px;" /> German
|
| 32 |
-
</label>
|
| 33 |
-
<label style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; border: 1px solid #ced4da; border-radius: 4px; cursor: pointer;">
|
| 34 |
-
<input type="radio" name="language" value="fr" style="margin: 0;" />
|
| 35 |
-
<img src="https://flagcdn.com/fr.svg" alt="France Flag" style="width: 20px; height: 14px;" /> French
|
| 36 |
-
</label>
|
| 37 |
</div>
|
| 38 |
|
| 39 |
-
<
|
| 40 |
-
<div id="singleAudioContent" class="tab-content loading">
|
| 41 |
<div style="display: flex; gap: 1.5rem;">
|
| 42 |
-
<!-- Input Section -->
|
| 43 |
<div style="flex: 1; display: flex; flex-direction: column; gap: 1rem;">
|
| 44 |
<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;">
|
| 45 |
<span style="line-height: 1;">🎵</span> Input
|
| 46 |
</div>
|
| 47 |
|
| 48 |
-
<!-- Drag and Drop / File Upload -->
|
| 49 |
<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;">
|
| 50 |
<input type="file" id="fileInput" accept="audio/*" style="position: absolute; top: 0; left: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;" />
|
| 51 |
<p style="margin: 0;">Drop Audio Here<br>- or -<br>Click to Upload</p>
|
| 52 |
</div>
|
| 53 |
|
| 54 |
-
<!-- Record Microphone Button -->
|
| 55 |
<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;">
|
| 56 |
<span style="font-size: 0.8rem; border-radius: 50%; background-color: #d9534f; width: 10px; height: 10px; display: inline-block;"></span>
|
| 57 |
Use Microphone
|
| 58 |
</button>
|
| 59 |
</div>
|
| 60 |
|
| 61 |
-
<!-- Output Section -->
|
| 62 |
<div style="flex: 1; display: flex; flex-direction: column; gap: 1rem;">
|
| 63 |
<div style="font-size: 1rem; font-weight: bold; padding: 0.5rem 1rem; background-color: #f8f9fa; border-radius: 8px; color: #6c757d;">Transcript</div>
|
| 64 |
<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>
|
|
@@ -67,72 +109,29 @@
|
|
| 67 |
</div>
|
| 68 |
</div>
|
| 69 |
|
| 70 |
-
<
|
| 71 |
-
|
| 72 |
-
<div style="text-align: center; padding: 1rem;">
|
| 73 |
-
<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>
|
| 74 |
-
</div>
|
| 75 |
-
<div style="display: flex; flex-wrap: wrap; gap: 1rem;">
|
| 76 |
-
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
| 77 |
-
<audio id="audio1" controls style="width: 100%;"></audio>
|
| 78 |
-
<textarea id="transcript1" readonly placeholder="Transcript for Audio 1"
|
| 79 |
-
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
| 80 |
-
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
| 81 |
-
</div>
|
| 82 |
-
|
| 83 |
-
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
| 84 |
-
<audio id="audio2" controls style="width: 100%;"></audio>
|
| 85 |
-
<textarea id="transcript2" readonly placeholder="Transcript for Audio 2"
|
| 86 |
-
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
| 87 |
-
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
| 88 |
-
</div>
|
| 89 |
-
|
| 90 |
-
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
| 91 |
-
<audio id="audio3" controls style="width: 100%;"></audio>
|
| 92 |
-
<textarea id="transcript3" readonly placeholder="Transcript for Audio 3"
|
| 93 |
-
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
| 94 |
-
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
| 95 |
-
</div>
|
| 96 |
-
|
| 97 |
-
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
| 98 |
-
<audio id="audio4" controls style="width: 100%;"></audio>
|
| 99 |
-
<textarea id="transcript4" readonly placeholder="Transcript for Audio 4"
|
| 100 |
-
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
| 101 |
-
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
| 102 |
-
</div>
|
| 103 |
-
|
| 104 |
-
<div class="audio-container" style="flex: 1; min-width: 250px;">
|
| 105 |
-
<audio id="audio5" controls style="width: 100%;"></audio>
|
| 106 |
-
<textarea id="transcript5" readonly placeholder="Transcript for Audio 5"
|
| 107 |
-
style="width: 100%; height: 4rem; margin-top: 0.5rem; font-size: 0.9rem; padding: 0.5rem;
|
| 108 |
-
border: 1px solid #ced4da; border-radius: 4px; resize: none;"></textarea>
|
| 109 |
-
</div>
|
| 110 |
-
</div>
|
| 111 |
</div>
|
| 112 |
|
| 113 |
-
<div id="status">Loading...</div>
|
| 114 |
-
|
| 115 |
</div>
|
| 116 |
|
| 117 |
-
<!-- Footer Section -->
|
| 118 |
<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;">
|
| 119 |
<h3>Welcome to Kroko</h3>
|
| 120 |
|
| 121 |
<strong>
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
|
| 133 |
</div>
|
| 134 |
|
| 135 |
-
<script src="./
|
| 136 |
-
<script src="./app-asr.js"></script>
|
| 137 |
</body>
|
| 138 |
</html>
|
|
|
|
| 5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
<title>Audio Input with Tabs and Features</title>
|
| 7 |
<style>
|
| 8 |
+
.hidden {
|
| 9 |
display: none !important;
|
| 10 |
}
|
| 11 |
+
|
| 12 |
+
b-dot {
|
| 13 |
+
opacity: 0;
|
| 14 |
+
animation: blink 1.5s infinite;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
b-dot:nth-child(1) { animation-delay: 0s; }
|
| 18 |
+
b-dot:nth-child(2) { animation-delay: 0.5s; }
|
| 19 |
+
b-dot:nth-child(3) { animation-delay: 1s; }
|
| 20 |
+
|
| 21 |
+
@keyframes blink {
|
| 22 |
+
0%, 100% { opacity: 0; }
|
| 23 |
+
20%, 40% { opacity: 1; }
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
#modelType {
|
| 27 |
+
appearance: none;
|
| 28 |
+
background: #e9ecef;
|
| 29 |
+
border-radius: 10px;
|
| 30 |
+
position: relative;
|
| 31 |
+
outline: none;
|
| 32 |
+
transition: background 0.3s;
|
| 33 |
+
}
|
| 34 |
+
#modelType:checked {
|
| 35 |
+
background: #ffd700;
|
| 36 |
+
}
|
| 37 |
+
#modelType::before {
|
| 38 |
+
content: '';
|
| 39 |
+
display: block;
|
| 40 |
+
width: 18px;
|
| 41 |
+
height: 18px;
|
| 42 |
+
background: #fff;
|
| 43 |
+
border-radius: 50%;
|
| 44 |
+
position: absolute;
|
| 45 |
+
left: 1px;
|
| 46 |
+
top: 1px;
|
| 47 |
+
transition: left 0.3s;
|
| 48 |
+
}
|
| 49 |
+
#modelType:checked::before {
|
| 50 |
+
left: 21px;
|
| 51 |
+
}
|
| 52 |
+
label:has(#modelType:disabled), label:has(#modelType:disabled) * {
|
| 53 |
+
cursor: not-allowed !important;
|
| 54 |
+
}
|
| 55 |
</style>
|
| 56 |
</head>
|
| 57 |
<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;">
|
| 58 |
|
| 59 |
<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;">
|
| 60 |
|
| 61 |
+
<div id="selectLanguageContent" class="hidden">
|
| 62 |
+
<div style="font-size: 1rem; font-weight: bold; padding: 0.5rem 1rem; background-color: #f8f9fa; border-radius: 8px; color: #6c757d;">Languages & models</div>
|
| 63 |
+
|
| 64 |
+
<div style="margin: 1rem 0; text-align: center; display: flex; justify-content: center; gap: 1rem; flex-wrap: wrap;">
|
| 65 |
+
<label style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; border: 1px solid #ced4da; border-radius: 4px; cursor: pointer;">
|
| 66 |
+
<span style="display: flex; align-items: center; gap: 0.5rem;">🌐</span>
|
| 67 |
+
<select id="languageSelect" name="language" style="border: none; background: transparent; font-size: 1rem; padding: 0.5rem 1rem; outline: none; cursor: pointer;">
|
| 68 |
+
<option value="" selected disabled>Select a language</option>
|
| 69 |
+
</select>
|
| 70 |
+
</label>
|
| 71 |
+
<label style="display: inline-flex; align-items: center; gap: 0.5rem; padding: 0.5rem 1rem; border: 1px solid #ced4da; border-radius: 4px; cursor: pointer;" title="Pro models are not available here yet">
|
| 72 |
+
<span>Community</span>
|
| 73 |
+
<input type="checkbox" id="modelType" style="width: 40px; height: 20px; accent-color: goldenrod;" disabled>
|
| 74 |
+
<span>Pro</span>
|
| 75 |
+
</label>
|
| 76 |
+
</div>
|
| 77 |
+
|
| 78 |
+
<div id="modelList" style="display: flex; flex-direction: column; gap: 1rem; padding: 0.5rem 1rem;"></div>
|
| 79 |
</div>
|
| 80 |
|
| 81 |
+
<div id="selectedModelContent" class="hidden">
|
| 82 |
+
<div style="font-size: 1rem; font-weight: bold; padding: 0.5rem 1rem; background-color: #f8f9fa; border-radius: 8px; color: #6c757d;">Selected model</div>
|
| 83 |
+
<div id="selectedModel" style="display: flex; flex-direction: column; gap: 1rem; padding: 0.5rem 1rem;"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
</div>
|
| 85 |
|
| 86 |
+
<div id="singleAudioContent" class="hidden">
|
|
|
|
| 87 |
<div style="display: flex; gap: 1.5rem;">
|
|
|
|
| 88 |
<div style="flex: 1; display: flex; flex-direction: column; gap: 1rem;">
|
| 89 |
<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;">
|
| 90 |
<span style="line-height: 1;">🎵</span> Input
|
| 91 |
</div>
|
| 92 |
|
|
|
|
| 93 |
<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;">
|
| 94 |
<input type="file" id="fileInput" accept="audio/*" style="position: absolute; top: 0; left: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer;" />
|
| 95 |
<p style="margin: 0;">Drop Audio Here<br>- or -<br>Click to Upload</p>
|
| 96 |
</div>
|
| 97 |
|
|
|
|
| 98 |
<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;">
|
| 99 |
<span style="font-size: 0.8rem; border-radius: 50%; background-color: #d9534f; width: 10px; height: 10px; display: inline-block;"></span>
|
| 100 |
Use Microphone
|
| 101 |
</button>
|
| 102 |
</div>
|
| 103 |
|
|
|
|
| 104 |
<div style="flex: 1; display: flex; flex-direction: column; gap: 1rem;">
|
| 105 |
<div style="font-size: 1rem; font-weight: bold; padding: 0.5rem 1rem; background-color: #f8f9fa; border-radius: 8px; color: #6c757d;">Transcript</div>
|
| 106 |
<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>
|
|
|
|
| 109 |
</div>
|
| 110 |
</div>
|
| 111 |
|
| 112 |
+
<div id="status" style="display: flex; justify-content: center; align-items: center; height: 100%; font-size: 2rem;">
|
| 113 |
+
Preparing<b-dot>.</b-dot><b-dot>.</b-dot><b-dot>.</b-dot>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 114 |
</div>
|
| 115 |
|
|
|
|
|
|
|
| 116 |
</div>
|
| 117 |
|
|
|
|
| 118 |
<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;">
|
| 119 |
<h3>Welcome to Kroko</h3>
|
| 120 |
|
| 121 |
<strong>
|
| 122 |
+
This demo uses older versions of our models. We're working on a new one—stay tuned!
|
| 123 |
+
</strong>
|
| 124 |
+
<div style="margin-top: 8px; font-weight: normal;">
|
| 125 |
+
In the meantime, you can:
|
| 126 |
+
<ul style="margin: 6px 0 0 16px; padding: 0;">
|
| 127 |
+
<li><a href="https://kroko.ai/" target="_blank">Visit our website</a></li>
|
| 128 |
+
<li><a href="https://github.com/kroko-ai/kroko-onnx" target="_blank">Explore our GitHub repo</a></li>
|
| 129 |
+
<li><a href="https://discord.gg/JT7wdtnK79" target="_blank">Join our community</a> to get the latest updates first</li>
|
| 130 |
+
</ul>
|
| 131 |
+
</div>
|
| 132 |
|
| 133 |
</div>
|
| 134 |
|
| 135 |
+
<script src="./app-asr.js" type="module"></script>
|
|
|
|
| 136 |
</body>
|
| 137 |
</html>
|
de.data → kroko-sdk.js
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4e7af59a5e655e3f719cd33abdc1e43c57175fcd62e264239fd06acb9272b150
|
| 3 |
+
size 20219733
|
sherpa-onnx-asr.js
DELETED
|
@@ -1,1030 +0,0 @@
|
|
| 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: 'modified_beam_search',
|
| 422 |
-
maxActivePaths: 4,
|
| 423 |
-
enableEndpoint: 0,
|
| 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
DELETED
|
@@ -1 +0,0 @@
|
|
| 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
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:47a5b704a9f0e17cc6da262d7c3ddfa26fd361f7639a6f81f1055ec016c1295f
|
| 3 |
-
size 11293044
|
|
|
|
|
|
|
|
|
|
|
|