| earcon | Howler.js | Tone.js | ZzFX | |
|---|---|---|---|---|
| No audio files | β | β | β | β |
| Notification-specific API | β | β | β | β |
| TypeScript native | β | via @types | β | β |
| Zero dependencies | β | β | β | β |
| Bundle size | ~3 KB | 318 KB | 5.4 MB | <1 KB |
| Semantic sound names | β | β | β | β |
| Customizable | β | β | β | β |
An earcon is an auditory icon β a short, meaningful sound signal used in user interfaces. This library provides a curated set of them, generated entirely in code.
npm install earcons<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/earcons/dist/earcon.min.global.js"></script>
<!-- unpkg -->
<script src="https://unpkg.com/earcons/dist/earcon.min.global.js"></script>All functions are available under the global Earcon object:
<button onclick="Earcon.playSuccess()">β
</button>
<button onclick="Earcon.playError()">β</button>
<script>
// or
Earcon.earcon("notification", { volume: 0.8 });
</script>import { playSuccess, playError, playWarning } from "earcons";
// Defaults β medium variant, volume 0.5
await playSuccess();
await playError();
await playWarning();Each function accepts an optional SoundOptions object.
import {
playSuccess,
playError,
playWarning,
playNotification,
playClick,
playInfo,
} from "earcons";
await playSuccess();
await playError({ variant: "long", volume: 0.8 });
await playWarning({ variant: "short" });
await playNotification({ pitch: 7 }); // +7 semitones
await playClick({ variant: "short" });
await playInfo({ volume: 0.3 });import { earcon } from "earcons";
await earcon("success");
await earcon("error", { variant: "long" });Built-in sound names: success Β· error Β· warning Β· notification Β· click Β· info
import { registerSound, earcon } from "earcons";
import type { SoundPreset } from "earcons";
const chirp: SoundPreset = (_variant, _pitch) => ({
name: "chirp",
duration: 0.15,
notes: [
{ frequency: 1200, duration: 0.07, startAt: 0, waveShape: "sine" },
{ frequency: 1600, duration: 0.08, startAt: 0.07, waveShape: "sine" },
],
});
registerSound("chirp", chirp);
await earcon("chirp");| Option | Type | Default | Description |
|---|---|---|---|
volume |
number |
0.5 |
Master volume, 0β1 |
variant |
"short" | "medium" | "long" |
"medium" |
Duration variant |
pitch |
number |
0 |
Semitone offset (Β±) |
audioContext |
AudioContext |
shared singleton | Bring your own context |
onEnded |
() => void |
β | Called when the sound finishes |
import { closeAudioContext, setAudioContext } from "earcons";
// Provide your own AudioContext (useful in frameworks)
const myCtx = new AudioContext();
setAudioContext(myCtx);
// Tear down (e.g. on unmount)
await closeAudioContext();| Name | Waveform | Character |
|---|---|---|
success |
sine | Ascending major triad β bright, positive |
error |
sawtooth | Descending tritone β harsh, attention-grabbing |
warning |
triangle | Flat then descending minor second β cautious |
notification |
sine | Soft descending two-tone ding β neutral |
click |
sine | Very short transient β tactile UI feedback |
info |
sine | Single soft tone β informational, non-intrusive |
toggle |
triangle | Short tactile pop β on/off switch |
delete |
sawtooth | Rapid descending β destructive action |
message |
sine | Soft high ping β incoming chat message |
plugIn |
sine | Ascending sweep β inserted / connected |
plugOut |
sine | Descending sweep β removed / disconnected |
| Name | Waveform | Character |
|---|---|---|
eightBit |
square | Chiptune arpeggio β retro 8-bit |
police |
sawtooth | Alternating wee-woo siren |
coin |
square | Classic pickup coin |
boing |
sine | Comedy spring drop |
Any browser that supports the Web Audio API (all modern browsers since 2014).
Autoplay policy: earcon automatically calls
AudioContext.resume()before playing. Make sure you call a play function in response to a user gesture on first load, or the browser may suppress audio.
MIT
