Every component in Swamp UI has a little sound — a plop, a chime, a croak.
This is that machine, extracted. Drop one <script> on your page and any element can speak.
<script src="https://sophieren.com/swamp-sounds/swamp-sounds.js"></script>
1. Direct call — call after any user gesture (browsers block audio until then).
<script src="https://sophieren.com/swamp-sounds/swamp-sounds.js"></script> <button onclick="swampSounds.plop()">Press me</button> <script> // Or wire up listeners directly: document.querySelector('#submit').addEventListener('click', () => { swampSounds.chime(); }); </script>
2. Selector-attach — one-liner to bind a sound to any selector.
swampSounds.attach('button', 'plop'); swampSounds.attach('.card', 'firefly'); swampSounds.attach('#easter-egg', 'croak'); // With options: swampSounds.attach('.win', 'riserun', { volume: 0.2 });
3. Per-call options — every sound takes { volume, pitch }.
swampSounds.plop({ volume: 0.3 }); // louder swampSounds.croak({ pitch: 0.6 }); // big lazy bullfrog swampSounds.firefly({ pitch: 1.5 }); // tiny sparkle // Global controls: swampSounds.mute(true); // silence everything swampSounds.setVolume(0.5); // master volume (0-1) // Play by name (useful for data-driven UI): swampSounds.play('chime'); swampSounds.names(); // ['plop','chime','croak', ...]
| Sound | Vibe | Best for |
|---|---|---|
plop() | soft drop, 180→55 Hz | buttons, taps, ripples |
chime() | bell-like single note + octave | success, confirmation |
croak() | sawtooth wobble + thunk | easter eggs, frog things |
buzz() | detuned saws, ~220 Hz | insects, idle / loading |
splash() | bandpass noise + low tone | splash, water impact |
firefly() | high blip + harmonic | catch, collect, notification |
bite() | sharp two-note (square → sine) | strike, alert, hook-set |
splat() | square thud + lowpass noise | swat, impact, hit |
hop() | two-tone arc (4→6th) | jump, advance, step |
riserun() | 5-note pentatonic ladder | win, level-up, celebrate |
tarot() | low bell + sparkle stack | reveal, mystical, important |
rip() | low sine sweep 90→40 Hz | ripple, ambient bass moment |
lure() | highpass noise whoosh | cast, swipe, send |
| Control | Behavior |
|---|---|
mute(bool) | Silence all sounds. Pass true/false. |
setVolume(0..1) | Master gain. 0.5 is roughly comfortable for ambient use. |
attach(selector, name, opts) | Bind a sound to all matching elements' click. Returns unbind fn. |
play(name, opts) | Play any sound by string name. |
names() | Returns the list of available sound names. |
isMuted() | Returns current mute state. |
Use it in personal projects, commercial work, paid products, side hustles. Fork it, remix the sounds, add your own. Attribution appreciated but not required.
v1.0.0 · 2026-05-29 · initial release with 13 sounds: plop, chime, croak, buzz, splash, firefly, bite, splat, hop, riserun, tarot, rip, lure.