Urgent.News

What's breaking now, across hundreds of outlets.

Tech

How Water-Eject Sounds Work: Building a Speaker Cleaner with the Web Audio API

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…

To clean a phone's speaker, press a button, and listen for a buzzing sweep. Water droplets emerge from the speaker grille – it seems like magic, yet it's just physics and some JavaScript code. Sound waves can push water out of the mesh because speakers are tiny pumps, moving their cones back and forth to push air. Low-frequency tones make the cone move the most, resulting in the strongest air pulses.

When water in the mesh is subjected to these pulses, it gets shaken and pushed outwards, using the same principle found in smartwatches' water-eject feature.

The core of this effect uses the Web Audio API, which consists of an oscillator, a gain node, and a short frequency sweep. The code begins by creating an AudioContext, then generates an oscillator and a gain node. The oscillator is set to a sine wave, and its frequency is gradually increased and decreased within a 2-second timeframe.

The gain node's volume is also modulated during this period, starting at 0.9 and staying there. Finally, the oscillator is connected to the gain node, which in turn is connected to the device's audio output. The oscillator then starts and stops after the 2-second timeframe.

Building a real cleaner involves repeating this sequence as a timed series of pulses, ramping the volume safely, and displaying progress so the user knows when to stop. A few small details are crucial, such as initiating the AudioContext from a user gesture (mobile browsers block autoplay), keeping the peak gain below clipping, and allowing the user to cancel mid-sequence.

For a fully functional example, check out Fix My Speaker, which runs the entire sequence in the browser without requiring any installation – it works on both iPhone and Android devices. Additionally, the author wrote about troubleshooting phone speakers that keep cutting out, detailing the causes in order of importance: dust, moisture, and software issues.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Vertical scaling vs horizontal scaling for VMs: what's the difference?

Most teams reach for more servers when a bigger one would do. That is not a criticism, since "just add more" sounds like the cloud way.

  • Vertical scaling increases resources of a single machine, requiring downtime.
  • Horizontal scaling adds more machines, minimizing downtime and requiring stateless design.
  • Hybrid approach combines vertical and horizontal scaling for optimal performance.

Big apps don't show more paywalls, they just test more

View this post on Instagram Today I read Superwall's "State of App Monetization 2026" report, which I found through GeekNews.

  • Larger apps don't increase paywalls, focus on post-paywall revenue
  • Top apps earn 12x more per install than less successful ones
  • Conversion rates increase significantly after paywall implementation

Validate the Whole Quantity String Before Converting It to a Number

A warehouse import can receive a quantity as text. If its contract requires a non-negative whole number, parsing a numeric prefix is too permissive: parseInt("12pcs", 10) returns 12 rather than…

  • Validate quantity string before conversion to prevent invalid input issues
  • Check if input matches required pattern using regular expression
  • Throw TypeError if input is not a string or doesn't match pattern

Healing Messy Hand-Drawn Floor Plan Graphs into Watertight CAD Geometry in TypeScript

If you ask a vision model to extract wall segments from a photograph of a hand-drawn floor plan — or let a human sketch walls freely with a mouse — the output looks plausible at a glance and fails…

  • Connected-component vertex welding groups vertices within weldRadiusIn
  • Walls snapped to angles within 6-degree range
  • Openings clamped inside host wall endpoints for watertight geometry

More from Thursday 26 November →