Skip to main content

Interface sounds

Added in 6.5.0

soundhub/ui is a separate entry point with twelve interface sounds. They are rendered into buffers in the browser when you add them, so nothing is fetched and there are no files to host or licences to check. The entry point is 1.5 KB gzipped, and it only ends up in your bundle when you import it.

import { SoundHub } from 'soundhub';
import { addUiSounds, uiSounds } from 'soundhub/ui';

const soundHub = new SoundHub();
addUiSounds(soundHub);

saveButton.onclick = () => soundHub.play(uiSounds.success);

After addUiSounds they are ordinary sounds in the hub, with ids such as 'ui.click' and 'ui.success'. Volume, mute, groups, ducking and the event bus all work on them.

Try it​

Try it

Twelve sounds, no files

Idle

Every button plays one of the interface sounds. They are rendered in your browser when the page opens.

0.60
Last soundnone yet
Files loaded0

Click a button several times quickly: the sounds overlap instead of cutting each other off.

Code
Your clicks show up here as soundhub calls

The sounds​

NameId with the default prefixWhat it sounds likeLength
clickui.clickA short, bright tick23 ms
tapui.tapA soft, falling blip55 ms
toggleOnui.toggleOnTwo notes going up145 ms
toggleOffui.toggleOffThe same two notes going down145 ms
successui.successA rising major chord, one note after the other515 ms
errorui.errorTwo low, buzzy notes going down345 ms
warningui.warningThe same note twice265 ms
notifyui.notifyA two note chime615 ms
popui.popA quick upward pop65 ms
swipeui.swipeA soft whoosh of noise165 ms
deleteui.deleteA falling sweep185 ms
typeui.typeA key press, for typing13 ms

What the entry point exports​

import {
addUiSounds, // render the sounds and add them to a hub
uiSounds, // the ids with the default prefix: uiSounds.click is 'ui.click'
UI_SOUND_NAMES, // every name, in the order of the table above
renderUiSound, // the raw samples of one sound
type UiSoundName, // 'click' | 'tap' | ... | 'type'
type UiSoundsOptions, // the options for addUiSounds
} from 'soundhub/ui';
ExportTypeDescription
addUiSoundsfunctionRender the sounds and add them to a hub.
uiSoundsReadonly<Record<UiSoundName, string>>The ids addUiSounds gives the sounds with the default prefix. With a prefix of your own, use the ids addUiSounds returns.
UI_SOUND_NAMESreadonly UiSoundName[]All twelve names.
renderUiSoundfunctionThe samples of one sound, for your own use.
UiSoundNametypeThe union of the twelve names.
UiSoundsOptionstypeThe options of addUiSounds.

Muting them all​

Put them in a group, and one call reaches all of them:

import { addUiSounds, uiSounds } from 'soundhub/ui';

addUiSounds(soundHub, { groupId: 'interface', volume: 0.4 });

soundHub.play(uiSounds.click);

// A "sounds off" switch in the settings
soundHub.getGroup('interface')!.sounds.forEach((id) => soundHub.mute(id));

Good to know​

  • The sounds are the same on every load and in every browser. The noise in click, swipe and type comes from a fixed seed.
  • They overlap by default, so a fast typist or a double click does not cut the previous sound off.
  • Rendering takes a moment of CPU on the main thread and no network. Adding them before the first user gesture is fine, the context only has to run when they play.
  • Your own synthesised audio takes the same route through addBuffer.
  • The entry point uses the soundhub package you already have, it does not carry a copy of it.