DEV Community

Melbin J Paulose
Melbin J Paulose

Posted on

Why Kokoro-82M sounded like static on WebGPU (and dropping hardcoded language lists)

While building Voice Notes, an offline browser voice studio on GitHub Pages (source), I hit a nasty audio bug on WebGPU.

Every spoken note came back as radio static.

1. WebGPU fp16 and q8 break Kokoro-82M output

My first worker setup loaded Kokoro-82M on WebGPU with dtype: "fp16" and fell back to WebGPU q8 when half-precision failed. Both settings ran without throwing an error, and both produced unintelligible noise on WebGPU.

The fix in tts-worker.js was simple once isolated:

  • Use dtype: "fp32" whenever WebGPU is active.
  • Fall back to WASM q8 when WebGPU is unavailable.

If your browser TTS pipeline suddenly outputs static after a quantization tweak, check the device and dtype pair before debugging audio buffers or sample rates.

2. Reading all 99 languages from the model config

Hardcoded language dropdowns go stale or miss locales that the underlying model already supports. Instead of shipping a static array, languages.js reads lang_to_id directly from Xenova/whisper-tiny's generation_config.json (99 languages):

  1. Map each ISO code to a readable label with Intl.DisplayNames.
  2. Derive the matching browser speech locale tag (such as ml-IN) using new Intl.Locale(code).maximize().
  3. Cache the resolved map in localStorage so repeat loads skip extra work.

3. Word-level click-to-seek and subtitle export

For playback follow-along, timeline.js aligns live captions onto Whisper chunk word timings with longest common subsequence (LCS) matching. Clicking any word seeks audio directly to word.start (seeking slightly earlier lands on the previous word boundary), and the aligned timings export cleanly to SRT and VTT files without a backend server.

Top comments (1)

Collapse
 
userxnom profile image
Abdullah Naseer •

The silent-failure detail is the part that would have cost me the most time — fp16 and q8 both ran without throwing an error, so the bug looked like an audio-buffer or sample-rate problem when it was really the device/dtype pair. Your rule to check that pair first is worth keeping as step one in any browser TTS debugging checklist.

The 99-language point is the one I would steal: reading lang_to_id straight from generation_config.json, plus Intl.DisplayNames for the labels, means the dropdown can never go stale the way a hardcoded list does. Deriving the browser speech locale tag with Intl.Locale(code).maximize() is a neat bridge to the speech side too.

One thing I am curious about: with the LCS alignment for click-to-seek, how does it behave when Whisper's chunk word timings drift on longer notes — do you re-align per chunk, or does the offset accumulate? And does the localStorage cache for the resolved language map get invalidated when the model config changes, or does it just live on once it is resolved?