/sound-board

🎧 A simple abstraction around web audio apis to make interactions easier for loading files and playing them.

Primary LanguageJavaScript

Sound board

Build Status

A simple abstraction around web audio apis to make interactions easier for loading files and playing them.

Install

npm i sound-board --save

Usage

Loading sound

import soundBoard from 'sound-board'

soundBoard.downloadSound('waterbowl', 'http://example.com/waterbowl.mp3')
  .then(() => soundBoard.play('waterbowl'))
  .catch(err => console.error(err)) // if something happens on download

// or
soundBoard.loadSounds({
  waterbowl: 'http://example.com/waterbowl.mp3',
  gong: 'http://example.com/gong.mp3'
})
  .then(() => /* do stuff with sounds */)
  .catch(err => console.error(err)) // if something happens on a download

// or a local buffer
soundBoard.loadBuffer('chime', arrbuffer)
  .then(() => /* do stuff with sounds */)
  .catch(err => console.error(err)) // if something happens on a download

Playing sound

// to play a sound at a certain time
soundBoard.play('waterbowl', 1.337) // starts at 1.337 seconds

// to pause the sound
soundBoard.pause('waterbowl')

// to stop the sound
soundBoard.stop('waterbowl')

Events

soundBoard.on('play', (soundName) => {}) // when starting to play the sound
soundBoard.on('pause', (soundName) => {}) // when pausing the sound
soundBoard.on('end', (soundName) => {}) // when the sound ends
soundBoard.on('frequencyData', (soundName, bufferLength, dataArray) => {}) // some data when song is playing