The sound layer your product deserves
852 interaction sounds, synthesized in the browser with the Web Audio API. No audio files, no dependencies, nothing to load.
npm install sonic-flow
Click a pad, or press 1–9 on your keyboard.Tap a pad to hear it.
- Sounds
- 852
- Categories
- 27
- Gzipped, all sounds
- <20 kB
- Dependencies
- 0
Sounds
Click any sound to hear it, then use the arrow keys to audition its neighbours. Copy gives you the exact play() call.
One attribute. Instant feedback.
Add a data-sf-* attribute to any element and call bind() once. These three are live.
play(liked ? "like" : "unlike")
A distinct cue for each state, fired from your own handler.
data-sf-toggle
Alternates between toggle-on and toggle-off. Works on any checkbox or switch.
data-sf-press data-sf-release
A paired down and up sound, like pressing a physical key.
Ship sound in under a minute.
-
Install the package
npm install sonic-flowyarn add sonic-flowpnpm add sonic-flow<!-- No build step: load it as an ES module --> <script type="module"> import { bind } from "https://unpkg.com/sonic-flow"; bind(); </script>
-
Tag your elements
Add
data-sf-*to anything interactive and callbind()once after the page loads. -
Or play on demand
Call
play("name")from any handler. Names are exactly what you see in the library above.
<!-- Tag any element with a behavior --> <button data-sf-press data-sf-release>Save</button> <a href="/docs" data-sf-hover="hover-soft">Docs</a> <input type="checkbox" data-sf-toggle> <button data-sf="success">Publish</button>
import { bind, play, setVolume } from "sonic-flow";
bind(); // wire every data-sf-* element
setVolume(0.7); // master volume, 0 to 1
play("success"); // at master volume
play("error", { volume: 0.3 }); // quieter, this call only
import { useEffect } from "react";
import { bind, play } from "sonic-flow";
export default function App() {
useEffect(() => { bind(); }, []);
return (
<button data-sf-press onClick={() => play("success")}>
Save
</button>
);
}
<script setup>
import { onMounted } from "vue";
import { bind } from "sonic-flow";
onMounted(() => bind());
</script>
<template>
<button data-sf-press data-sf-release>Save</button>
</template>
API
Five functions and a handful of attributes. That’s the whole surface.
Functions
play(name, options?)Plays a sound by name. Pass
{ volume }(0 to 1) to override the master volume for that call.bind(options?)Wires every
data-sf-*element on the page. Call it once when the DOM is ready.{ volume }also sets the master volume.setVolume(value)Sets the master volume, from 0 to 1. The default is 0.7.
setPitch(semitones)Shifts every sound up or down. 0 is the original pitch.
getSounds()Returns an array with the name of every sound.
Attributes
| Attribute | Plays on | Default sound |
|---|---|---|
data-sf-hover | Pointer enter | hover |
data-sf-press | Mouse down, touch start | press |
data-sf-release | Mouse up, touch end | release |
data-sf-toggle | Click, alternating | toggle-on / toggle-off |
data-sf-focus | Focus | focus |
data-sf-blur | Blur | blur |
data-sf="name" | Click | The named sound |
Hover, press and release take a sound name as their value, for example data-sf-hover="hover-soft".
Sounds stay silent for visitors who have prefers-reduced-motion turned on. Loaded from a CDN, the same functions are on window.SonicFlow.