filedom/sound
Sound effects and playback backends.
Hooks
Schemes
import { KENNEY_SCHEME, AMBIENT_SCHEME, useSound } from 'filedom/sound';
const sfx = useSound(AMBIENT_SCHEME);
KENNEY_SCHEME, the default, maps events to bundled Kenney arcade samples.
AMBIENT_SCHEME maps them to the built-in macOS alert sounds.
A scheme maps each event to a SoundSource, or null for silence:
const scheme: SoundScheme = {
...KENNEY_SCHEME,
merge: 'Glass', // a macOS system sound
win: { sample: { bundled: 'clear' } }, // a bundled sample
lose: { sample: { file: '/abs/path/lose.wav' } }, // your own file
tick: null,
};
A file path must be absolute.
SYSTEM_SOUNDS and systemSoundPath name and locate the macOS system sounds.
BUNDLED_SOUNDS and bundledSoundPath do the same for the sounds packaged with
filedom.
Playback
import { createSoundboard, setMuted, isMuted } from 'filedom/sound';
const sfx = createSoundboard();
sfx.play('merge');
setMuted(true);
createSoundboard(scheme?, backend?) plays sounds outside React. setMuted
and isMuted control mute on the shared default backend, which every soundboard
uses unless you pass another one. Playback goes through the native
AudioController; on a machine without audio it does nothing.