Spaces:
Running
Running
ORT 1.29: WASM live pass, WebGPU correction pass
Browse files26 unmodified lines2728293031323334353637383940416 unmodified lines4849505152535426 unmodified lineselse if (m.type === 'flushed') { if (state.accept) onFlushed(m); }else if (m.type === 'corrected') onCorrected(m);else if (m.type === 'log') console.log(m.msg);else if (m.type === 'backend') { state.backend[name] = m.backend; if (name === 'stream') { const b = m.backend === 'webgpu' ? 'WebGPU ⚡' : 'WASM'; $('#backend').textContent = b; setStatus('آماده · ' + b, 'ok'); } }else if (m.type === 'error') { console.error(m.msg, m.stack || ''); setStatus('⚠ ' + m.msg, 'err'); }};w.postMessage({ type: 'init', role: name, gpu });}function onReady() {$('#loader').classList.add('done');const b = state.backend.stream === 'webgpu' ? 'WebGPU ⚡' : 'WASM';setStatus('آماده · ' + b, 'ok'); $('#backend').textContent = b;document.body.classList.add('ready');}6 unmodified linesstate.chunkMs.push(m.ms); if (state.chunkMs.length > 50) state.chunkMs.shift();state.audioSec = m.audioSec;let s = cur();for (let i = 0; i < m.toks.length; i++) { s.toks.push(m.toks[i]); s.frames.push(m.frames[i]); }endpointCheck(false);render(); stats();}26 unmodified lines2728293031323334353637383940416 unmodified lines484950515253545556575826 unmodified lineselse if (m.type === 'flushed') { if (state.accept) onFlushed(m); }else if (m.type === 'corrected') onCorrected(m);else if (m.type === 'log') console.log(m.msg);else if (m.type === 'backend') { state.backend[name] = m.backend; $('#backend').textContent = beLabel(); setStatus('آماده · ' + beLabel(), 'ok'); }else if (m.type === 'error') { console.error(m.msg, m.stack || ''); setStatus('⚠ ' + m.msg, 'err'); }};w.postMessage({ type: 'init', role: name, gpu });}const beLabel = () => 'live: ' + (state.backend.stream === 'webgpu' ? 'WebGPU' : 'WASM') + ' · fix: ' + (state.backend.correct === 'webgpu' ? 'WebGPU ⚡' : 'WASM');function onReady() {$('#loader').classList.add('done');setStatus('آماده · ' + beLabel(), 'ok'); $('#backend').textContent = beLabel();document.body.classList.add('ready');}6 unmodified linesstate.chunkMs.push(m.ms); if (state.chunkMs.length > 50) state.chunkMs.shift();state.audioSec = m.audioSec;let s = cur();for (let i = 0; i < m.toks.length; i++) {// punctuation that trails an endpoint belongs to the previous (already corrected) phraseif (!s.toks.length && state.segs.length > 1 && !/[\p{L}\p{N}]/u.test(state.pieces[m.toks[i]])) continue;s.toks.push(m.toks[i]); s.frames.push(m.frames[i]);}endpointCheck(false);render(); stats();}
123457 unmodified lines1314151617181959 unmodified lines79808182838485// One module worker per role: 'stream' (live first pass) or 'correct' (full-context second pass + LM).import * as ort from 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/ort.webgpu.min.mjs';import { Engine, parseTokens } from './asr.js';import { NgramLM } from './lm.js';import { fbankAll, frameAt, readyFrames, numFrames } from './fbank.js';7 unmodified linestokens: HF + 'tokens.txt',lm: './shenava-web-3gram.bin',};ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.22.0/dist/';let role, eng, lm, backend = 'wasm';const post = (m, t) => self.postMessage(m, t || []);59 unmodified linesconst pieces = parseTokens(new TextDecoder().decode(bufs.tokens));const cfg = await (await fetch('./stream_config.json')).json();const sess = {streamEnc: role === 'stream' ? await session(bufs.stream, m.gpu) : null,offEnc: role === 'correct' ? await session(bufs.offline, m.gpu) : null,dec: await session(bufs.dec, false), joi: await session(bufs.joi, false),};123457 unmodified lines1314151617181959 unmodified lines79808182838485// One module worker per role: 'stream' (live first pass) or 'correct' (full-context second pass + LM).import * as ort from 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.29.0/dist/ort.webgpu.min.mjs';import { Engine, parseTokens } from './asr.js';import { NgramLM } from './lm.js';import { fbankAll, frameAt, readyFrames, numFrames } from './fbank.js';7 unmodified linestokens: HF + 'tokens.txt',lm: './shenava-web-3gram.bin',};ort.env.wasm.wasmPaths = 'https://cdn.jsdelivr.net/npm/onnxruntime-web@1.29.0/dist/';let role, eng, lm, backend = 'wasm';const post = (m, t) => self.postMessage(m, t || []);59 unmodified linesconst pieces = parseTokens(new TextDecoder().decode(bufs.tokens));const cfg = await (await fetch('./stream_config.json')).json();const sess = {streamEnc: role === 'stream' ? await session(bufs.stream, false) : null, // small 320 ms chunks: WASM has lower latency than WebGPU hereoffEnc: role === 'correct' ? await session(bufs.offline, m.gpu) : null,dec: await session(bufs.dec, false), joi: await session(bufs.joi, false),};
app.js+8-4
worker.js+3-3