Hangul Blocks

Why my recorded voice wouldn't play only on the phone

Jamo sounds that were fine on PC played late or not at all in the phone's WebView. I dropped HTMLAudio and switched to Web Audio buffers.

The jamo sounds in Hangul Blocks (ㄱ, ㄴ, ㅏ…) aren't TTS. They're my own recorded voice. I recorded everything in one take, then split it into per-letter mp3s at the silent gaps. (Threshold: -36dB, 0.12 seconds. A few lines with pauses in the middle were grouped and handled separately.)

Symptoms

  • PC browser: perfect
  • Android phone (WebView wrapper): the sound is about 0.5 seconds late, or doesn't play at all

Cause

I was creating a new Audio(url) every time I played a sound. In a WebView, that re-decodes from scratch each time, which made it slow, and short clips sometimes got swallowed entirely.

Fix

  1. When the game starts, pre-decode all voice clips into Web Audio buffers.
  2. Play them through AudioBufferSourceNode. The delay practically disappeared.
  3. The sound that says a letter's name gets a priority lock, so sound effects can't override it.

Bonus: WebView has no speechSynthesis

Letters without a recording yet get read aloud by TTS instead, but Android WebView has no speechSynthesis. So I built an AndroidTTS bridge on the Kotlin side and call it from JS.

When handling sound in a mobile WebView, going with Web Audio buffers from the start saves you a lot of headaches.

The app in this postHangul BlocksA Hangul Tetris where you stack colored bars to build letters
Try the demo