Fix #29 by removing compression altogether
This commit is contained in:
File diff suppressed because one or more lines are too long
Binary file not shown.
@@ -48,19 +48,20 @@ class CommonModel extends EventTarget {
|
||||
resolve(mdl)
|
||||
}
|
||||
else reject(ev.detail)
|
||||
}, { once: true })
|
||||
}, { once: true });
|
||||
});
|
||||
let cache = await caches.open('Vosklet');
|
||||
let req = (await cache.keys(storepath, { ignoreSearch: true }))[0]
|
||||
let tar, res;
|
||||
let req = (await cache.keys(storepath, { ignoreSearch: true }))[0];
|
||||
let res;
|
||||
if (typeof req == 'undefined' || req.url.split('?')[1] != id) {
|
||||
|
||||
// Caching already handled explicitly
|
||||
res = await fetch(url, { cache: 'no-store' });
|
||||
if (!res.ok) throw 'Unable to fetch model, status: ' + res.status;
|
||||
await cache.put(storepath + '?' + id, res.clone());
|
||||
await cache.put(storepath + '?' + id, new Response(res.body.pipeThrough(new DecompressionStream('gzip'))));
|
||||
}
|
||||
else res = await cache.match(req)
|
||||
tar = await new Response(res.body.pipeThrough(new DecompressionStream('gzip'))).arrayBuffer();
|
||||
let tar = await res.arrayBuffer();
|
||||
let tarStart = _malloc(tar.byteLength);
|
||||
HEAPU8.set(new Uint8Array(tar), tarStart);
|
||||
mdl.obj = new Module['CommonModel'](objs.length - 1, normalMdl, tarStart, tar.byteLength);
|
||||
@@ -70,6 +71,7 @@ class CommonModel extends EventTarget {
|
||||
class Recognizer extends EventTarget {
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
// Closure workaround to prevent acceptWaveform from getting removed
|
||||
this['acceptWaveform'] = audioData => {
|
||||
let start = _malloc(audioData.length * 4);
|
||||
|
||||
@@ -4,18 +4,18 @@
|
||||
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.2.1/Examples/Vosklet.js" async defer></script>
|
||||
<script>
|
||||
async function start() {
|
||||
|
||||
// All data is collected and transfered to the main thread so the AudioContext won't output anything. Set sinkId type to none to save power
|
||||
let ctx = new AudioContext({sinkId: {type: "none"}});
|
||||
let module = await loadVosklet();
|
||||
let model = await module.createModel("https://ccoreilly.github.io/vosk-browser/models/vosk-model-small-en-us-0.15.tar.gz", "English", "vosk-model-small-en-us-0.15");
|
||||
let recognizer = await module.createRecognizer(model, ctx.sampleRate);
|
||||
|
||||
// Listen for result and partial result
|
||||
recognizer.addEventListener("result", ev => console.log("Result: ", ev.detail));
|
||||
recognizer.addEventListener("partialResult", ev => console.log("Partial result: ", ev.detail));
|
||||
|
||||
// Fetch, decode, and recognize the .wav
|
||||
let wav = await fetch("https://cdn.jsdelivr.net/gh/msqr1/Vosklet/examples/1to10-en.wav");
|
||||
let wav = await fetch("https://cdn.jsdelivr.net/gh/msqr1/Vosklet/Examples/1to10-en.wav");
|
||||
let audioBuf = await ctx.decodeAudioData(await wav.arrayBuffer());
|
||||
recognizer.acceptWaveform(audioBuf.getChannelData(0));
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<script src="https://cdn.jsdelivr.net/gh/msqr1/Vosklet@1.2.1/Examples/Vosklet.js" async defer></script>
|
||||
<script>
|
||||
async function start() {
|
||||
|
||||
// All data is collected and transfered to the main thread so the AudioContext won't output anything. Set sinkId type to none to save power
|
||||
let ctx = new AudioContext({sinkId: {type: "none"}});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user