Why web app sound effects feel broken, and the 155-line TypeScript engine I built to fix them
Drop an <audio> tag into a React button handler, click the button twice fast, and you hear two things go wrong immediately. The second click either clips the first one mid-tail or waits for a fresh decode, and every clic
Drop an <audio> tag into a React button handler, click the button twice fast, and you hear two things go wrong immediately. The second click either clips the first one mid-tail or waits for a fresh decode, and every click sounds identical like a stuck metronome. If you pull sounds from three different stock packs, the toggle switch whispers while the checkout chime rattles your user's headphones.
I ran into this while putting together a SaaS demo and a product launch video at the same time. Hardware controls on a camera or mechanical keyboard work because the tactile click is short, consistent in loudness, and varies slightly with every press. Browser UI audio almost never gets that treatment, so I built SonicLaunch: a 155-line zero-dependency TypeScript Web Audio engine paired with loudness-matched UI sound effects and launch-video soundtracks.
You can audition the engine and every sound directly in your browser on the interactive soundboard before reading the code.
When the browser blocks your first click
Most tutorials instantiate new AudioContext() at module load time. Chrome and Safari immediately place that context in a suspended state until a user gesture arrives, logging a console warning and silently dropping early triggers.
In soniclaunch.ts, the engine defers context creation until the first preload() or play() call and resumes a suspended context automatically:
private ensureContext(): AudioContext | null {
if (typeof window === "undefined") return null;
if (!this.ctx) {
const Ctx =
window.AudioContext ||
(window as unknown as { webkitAudioContext: typeof AudioContext }).webkitAudioContext;
if (!Ctx) return null;
this.ctx = new Ctx();
}
if (this.ctx.state === "suspended") {
void this.ctx.resume();
}
return this.ctx;
}
Once a sound is fetched and decoded via decodeAudioData(), it stays cached as an AudioBuffer in a Map. A second Map tracks in-flight fetches so rapid clicks on the same control never trigger duplicate network requests. Each playback spawns a lightweight AudioBufferSourceNode, which means rapid clicks overlap cleanly instead of cutting each other off.
When repeated clicks sound robotic
Playing the exact same 40-millisecond transient ten times in a row triggers what audio designers call the machine-gun effect. The human ear picks up identical waveforms instantly.
The fix takes two lines inside play(): apply a small random playbackRate offset (pitchJitter, defaulting to 0.015, or plus/minus 1.5%):
const jitter = entry.pitchJitter ?? 0.015;
const randShift = jitter > 0 ? 1 + (Math.random() * 2 - 1) * jitter : 1;
src.playbackRate.value = (overrides?.rate ?? 1) * randShift;
That tiny pitch shift keeps toggles, palette openings, and keyboard clicks feeling organic without changing the perceived note of melodic chimes (where you can set pitchJitter: 0).
When one clip is louder than the next
Mixing UI feedback and launch-video music from random stock sites usually leaves you with wildly mismatched levels. For SonicLaunch, I wanted every asset produced in a single repeatable pipeline:
- 18 UI micro-interaction sounds: synthesized with custom Python DSP envelopes (soft attack ramps, exponential decay, zero DC offset at sample boundaries so there are no pops) and exported to both 44.1 kHz WAV and 320 kbps MP3.
-
12 product-launch soundtracks: composed across four moods (Product Launch, Deep Focus, AI / Future Tech, and Founder Story) using Google's Lyria 3.5 model, then mastered through FFmpeg two-pass loudness normalization to
-14 LUFSintegrated loudness so they drop straight into Screen Studio, CapCut, or DaVinci Resolve without clipping voiceovers.
Because the master volume and per-sound gain live in the engine manifest, wiring a kit into a React or Next.js app takes five lines:
import { createSoundKit } from "./soniclaunch";
export const sfx = createSoundKit({
click: { url: "/audio/sfx-click.mp3", volume: 0.7 },
toggleOn: { url: "/audio/sfx-toggle-on.mp3", volume: 0.65 },
success: { url: "/audio/sfx-success.mp3", volume: 0.8, pitchJitter: 0 },
});
// Inside any button handler:
sfx.play("click");
Mute preferences persist to localStorage automatically via sfx.toggleMute() and sfx.isMuted(), with try/catch guards for private browsing contexts.
Where the open-source engine and full pack live
I split SonicLaunch into two parts so developers can grab the engine immediately with zero lock-in:
-
Free MIT Lite repo:
soniclaunch.tsplus 6 core UI sounds on GitHub (khanglvm/soniclaunch), with an interactive audition board at khanglvm.github.io/soniclaunch. -
SonicLaunch Pro ($29 one-time): all 18 UI micro-interaction SFX (WAV + MP3), all 12 full-length
-14 LUFSlaunch soundtracks in both uncompressed 44.1 kHz WAV and 320 kbps MP3, the TypeScript engine, and a lifetime commercial license covering client apps, SaaS products, and monetized launch videos on Whop.
If you wire UI sounds into your own app, start by turning your gain down to 0.5–0.7 and adding 1.5% pitch jitter — most "annoying" web audio is just played twice as loud as it needs to be.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.