Skip to main content

Getting Started

soundhub is a TypeScript library that wraps the Web Audio API in a single SoundHub class. It handles loading, playback, volume, fading, panning, spatial positioning, sprites, groups and events โ€” without you having to wire up audio nodes by hand.

Every method on the interface has its own page in this documentation. Use the sidebar to browse by topic, or the search box in the header to jump straight to a method.

Installationโ€‹

npm install soundhub
yarn add soundhub

Your first soundโ€‹

import { SoundHub, SoundEventsEnum, type SoundEvent } from 'soundhub';

const soundHub = new SoundHub();

soundHub.addEventListener(SoundEventsEnum.LOADED, (event: SoundEvent) => {
console.log('Sound loaded', event);
});

await soundHub.loadSounds([{ id: 'music', url: '/sounds/music.mp3' }]);
soundHub.play('music');
Browsers block audio until the user interacts

Most browsers suspend the audio context until the visitor clicks, taps or presses a key. Trigger your first play() from a real user action, or call resumeContext once the visitor interacts with the page.

Where to go nextโ€‹

TopicStart here
โฏ๏ธ Playbackplay ยท pause ยท stop ยท seek
๐ŸŽ›๏ธ All sounds at oncestopAllSounds ยท pauseAllSounds
๐Ÿ”Š Volume & mutesetSoundVolume ยท setGlobalVolume ยท toggleMute
๐ŸŒ— FadingfadeIn ยท fadeOut
๐Ÿ” Looping & playback ratesetLoop ยท setPlaybackRate
๐Ÿ“ฅ Loading soundsloadSounds ยท loadSound
๐Ÿ“Š State & progressisPlaying ยท getProgress ยท startProgressTracking
๐ŸŽš๏ธ Pan & balancesetPan ยท setGlobalPan
๐ŸŽฏ Spatial audiosetSpatialPosition ยท isSpatialAudioSupported
๐ŸŽถ Sound spritesSound sprites ยท setSoundSprite
๐Ÿ‘ฅ Sound groupscreateSoundGroup ยท addToSoundGroup
๐ŸŽง Audio context & nodesresumeContext ยท getMasterOutput
๐Ÿ›ก๏ธ Master limiterMaster limiter ยท setMasterLimiter
๐Ÿ“ก EventsaddEventListener ยท SoundEvent
๐Ÿ”„ Reset & cleanupreset ยท destroy
๐Ÿ”ง UtilitiesgetConfig ยท setDebugMode
๐Ÿ“˜ Types & InterfacesPlayOptions ยท SoundHubConfig

Try it liveโ€‹

Want to hear it before you install anything? The live demo lets you play with volume, panning, fading, sprites and spatial audio in the browser.

Many pages in this documentation also carry a Try it section with a working player, so you can hear what a method does while you read about it โ€” start with play or fadeIn.