Skip to main content
use-sound is a React hook that plays audio files you supply. audx’s useSound has a similar shape, so most components change by a line or two. You can then either keep your audio files or replace them with synthesized sounds that need no files at all.

Option 1: switch to synthesized sounds

Add the semantic sounds that match what your files did:
Then swap the import and the hook:
Two differences to note:
  • audx’s useSound is a named export, and it returns the play function directly rather than a tuple.
  • The sound is TypeScript in your repo, not an audio file, so there’s nothing to host, preload or cache.

Option 2: keep your audio files

If your app depends on specific recordings, play them with a sample source. Define each sound once, at module level:
sounds/boop.ts
The file is fetched and decoded on first play, then cached.
Set envelope.decay to at least the length of the file in seconds, with sustain: 1. Without an envelope, a layer fades out after about half a second. gain: 1 plays the file at its recorded level; the default is 0.5.
Use it exactly like a generated sound:

Option mapping

Mute and accessibility

With use-sound you pass soundEnabled to every hook. In audx, one <SoundProvider> near the root controls every useSound below it:
useSound also stays silent when the user has prefers-reduced-motion: reduce set, without extra code. See Use with React for a complete sound setting.

Remove use-sound

When nothing imports it any more:
Delete the audio files you replaced with synthesized sounds.