Multi-model · Silero VAD (2.2 MB CPU WASM) → Gemma 4 E2B (2,603.9 MB WebGPU) · MIT + Apache-2.0

Silero VAD → Gemma 4 E2B: stop paying audio tokens for silence

Gemma 4 spends one <|audio|> soft token on every 40 ms of input — silence included. A 2.2 MB Silero VAD running on the CPU finds where speech actually is, the clip is cut to that window, and Gemma 4 E2B transcribes both the untrimmed and the trimmed clip with the same prompt so the token, prefill and time-to-first-token savings are measured, not estimated.

1. Two independent stage loaders

Stage 1 · Silero VAD (2.2 MB CPU WASM)

Reuses ../../silero-vad/worker.js (onnx-community/silero-vad, MIT, onnxruntime-web).

Stage 2 · Gemma 4 E2B (2,603.9 MB WebGPU)

Uses ../worker.js (onnx-community/gemma-4-E2B-it-qat-mobile-ONNX, Apache-2.0, Transformers.js 4.3.2).

2. Pad → detect speech → trim → transcribe twice

…or drop an audio file here. Files never leave this tab.

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)…

Padded → trimmed–
Stage 1 VAD–
<|audio|> tokens raw → trimmed–
Audio tokens saved–
TTFT raw → trimmed–
TTFT saved–
Preprocess raw → trimmed–
Total NaN (VAD probs + tensors)–

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?

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