Press a button, hear a buzzing sweep, and droplets of water jump out of your phone's speaker grill. It looks like a trick, but it is just physics plus a few lines of JavaScript.

Why sound can push water out

A speaker is a small pump: its cone moves back and forth and pushes air. Low frequencies move the cone the furthest, so a low, loud tone creates the strongest air pulses. Water sitting in the speaker mesh gets shaken and pushed outward by those pulses — the same principle smartwatches use for their water-eject feature.

The core code

With the Web Audio API, the whole effect is an oscillator, a gain node and a short frequency sweep:

const ctx = new AudioContext(); const osc = ctx.createOscillator(); const gain = ctx.createGain(); osc.type = 'sine'; osc.frequency.setValueAtTime(165, ctx.currentTime); osc.frequency.linearRampToValueAtTime(180, ctx.currentTime + 2); gain.gain.setValueAtTime(0.9, ctx.currentTime); osc.connect(gain).connect(ctx.destination); osc.start(); osc.stop(ctx.currentTime + 2); 

A real cleaner repeats this as a timed sequence of pulses, ramps the volume safely, and shows progress so the user knows when to stop. Small details matter: start the AudioContext from a user gesture (mobile browsers block autoplay), keep the peak gain below clipping, and let the user cancel mid-sequence.

Try a finished version

If you want to see a production version of this idea, Fix My Speaker runs the full sequence in the browser — no install, works on iPhone and Android. I also wrote up the troubleshooting side here: why a phone speaker keeps cutting out — dust, moisture and software causes, in that order.

Have you built anything fun with Web Audio? I would love to hear what worked (and what clipped horribly).