Audio library for the Web Audio API.
(TypeScripted version of Three.js@r126's Audio without Object3D)
npm install @yandeu/audiohttps://unpkg.com/@yandeu/audio/umd/audio.min.js// import AudioManager
import { AudioManager } from '@yandeu/audio'
// print the current version
console.log('AudioManager VERSION: ', AudioManager.VERSION)
// instantiate
const audio = new AudioManager()
// load your sound: Promise<void>
// (Loads either dance-hits-2011.mp3 or dance-hits-2011.ogg depnding on browser support.)
await audio.load('hits', '../sound/dance-hits-2011', 'mp3', 'ogg')
// create your sound: Promise<Sound>
const sound = await audio.add('hits')
// play your sound
sound.play()
// check if your sound is playing
sound.isPlaying
// pause your sound (resume with .play())
sound.pause()
// stop your sound
sound.stop()
// and many many more...You probably need something like babel to make this library work on older devices.
On a newly-created AudioContext will always begin in the suspended state. Resume the state on a user event.
const audioManager = new AudioManager()
window.addEventListener(
  'click',
  async () => {
    await audioManager.listener.context.resume()
    // now you can play your audio
  },
  { once: true }
)You will find the full API on https://yandeu.github.io/audio.
The most important classes are AudioManager and Audio.
| Package | Description | 
|---|---|
audio | 
🎵 Audio library for the Web Audio API. | 
keyboard | 
⌨️ Handling of keyboard events. | 
tap | 
🖱️ Handling of user interactions such as mouse, touch and pointer events. | 
Join the enable3d discussions!