New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

earcons

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

earcons

Tiny vanilla TypeScript library for playing UI notification sounds via the Web Audio API — no audio files, no dependencies.

latest
Source
npmnpm
Version
0.4.0
Version published
Maintainers
1
Created
Source

earcons

Tiny vanilla TypeScript library for UI notification sounds — pure Web Audio API, no audio files, zero dependencies.

npm CI bundle size license

▶ Live demo

Why earcon?

earconHowler.jsTone.jsZzFX
No audio files
Notification-specific API
TypeScript nativevia @types
Zero dependencies
Bundle size~3 KB318 KB5.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.

Install

npm install earcons

CDN (no build step)

<!-- 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>

Quick start

import { playSuccess, playError, playWarning } from "earcons";

// Defaults — medium variant, volume 0.5
await playSuccess();
await playError();
await playWarning();

API

Named play functions

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 });

Generic earcon() — play by name

import { earcon } from "earcons";

await earcon("success");
await earcon("error", { variant: "long" });

Built-in sound names: success · error · warning · notification · click · info

Register a custom sound

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");

SoundOptions

OptionTypeDefaultDescription
volumenumber0.5Master volume, 0–1
variant"short" | "medium" | "long""medium"Duration variant
pitchnumber0Semitone offset (±)
audioContextAudioContextshared singletonBring your own context
onEnded() => voidCalled when the sound finishes

AudioContext management

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();

Sound reference

UI sounds

NameWaveformCharacter
successsineAscending major triad — bright, positive
errorsawtoothDescending tritone — harsh, attention-grabbing
warningtriangleFlat then descending minor second — cautious
notificationsineSoft descending two-tone ding — neutral
clicksineVery short transient — tactile UI feedback
infosineSingle soft tone — informational, non-intrusive
toggletriangleShort tactile pop — on/off switch
deletesawtoothRapid descending — destructive action
messagesineSoft high ping — incoming chat message
uploadsineAscending sweep — file sent
downloadsineDescending sweep — file received

Fun & misc

NameWaveformCharacter
eightBitsquareChiptune arpeggio — retro 8-bit 🕹️
policesawtoothAlternating wee-woo siren 🚨
coinsquareClassic pickup coin 🪙
boingsineComedy spring drop 🎪

Browser support

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.

License

MIT

Keywords

web-audio-api

FAQs

Package last updated on 20 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts