1. Two independent stage loaders
Stage 1 · Silero VAD (2.2 MB CPU WASM)
Stage 2 · Gemma 4 E2B (2,603.9 MB WebGPU)
2. Pad → detect speech → trim → transcribe twice
Loading clip…
Stage 2 compares the untrimmed clip with the Stage 1 trimmed clip, so it needs a Stage 1 window first (Run full pipeline does both).
Initialising Stage 1 (Silero VAD) and Stage 2 (Gemma 4 E2B)…
Stage 1 · padded clip, VAD curve & speech window
Run Stage 1 to overlay the per-frame speech probability (amber) and the trimmed window (green).
Trimmed clip sent to Gemma
No trim yet.
Stage 2 · measured cost, untrimmed vs trimmed
Run Stage 2 to compare measured audio tokens, preprocess, TTFT and total generation time.
Transcript · untrimmed (padded)
Transcript · VAD-trimmed
Why chain a VAD in front of an omni model?
- Cost is linear in audio length. Gemma4Processor emits one
<|audio|>token per 40 ms (≤750 tokens = 30 s), and every token runs through the conformer encoder and the 35-layer decoder prefill. - Real recordings are mostly silence. Voice memos, push-to-talk and meeting snippets carry lead-in and trailing dead air; trimming it shortens prefill and frees context.
- The VAD is nearly free. 2.2 MB, CPU-only, runs in a separate worker in tens of milliseconds, and works even where WebGPU does not.
Honesty notes. The dead air is synthetic: procedural −60 dBFS room tone generated by a
seeded PRNG and wrapped around a real public-domain / CC BY clip — it is not a field recording. Trimmed runs
first and untrimmed second, so any first-run warm-up cost lands on the trimmed side and the reported TTFT
saving is conservative. Token counts come from the real input_ids of each run; the keyword recall
line is a heuristic check that trimming did not cut off speech, not a word-error rate.
Show the code
Show the code — gemma4-core.mjs: deriveSpeechWindow() (Silero segments → padded speech window)
Show the code — gemma4-core.mjs: computeTrimSavings() (measured audio tokens + TTFT saved)
References & media
- onnx-community/silero-vad (MIT) · Silero VAD model page
- onnx-community/gemma-4-E2B-it-qat-mobile-ONNX (Apache-2.0)
- JFK inaugural address excerpt, 20 Jan 1961 — public-domain U.S. government work
- LibriSpeech test-clean 61-70968-0000 — Panayotov et al., OpenSLR SLR12, CC BY 4.0