JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q33291F
  • License MIT

A simple, neat promise wrapper for the web Audio Context API. Get and play sounds from urls with ease.

Package Exports

  • neat-audio

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (neat-audio) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

neatAudio

A simple, neat promise wrapper for the web Audio Context API, designed for use with browserify. Get and play sounds from urls with ease.

Usage

You'll need to use a Promise pattern with neatAudio, since it returns promises.

Fetch a Sound

var neatAudio = require('neat-audio');

// Init neatAudio
neatAudio.init(window);

// Load the sound buffers into variable
neatAudio.fetchSound('willhelm_scream.wav').then(function(soundBuffer){
  var scream = soundBuffer;

  // Play the sound
  neatAudio.playSound(scream);
});

Fetch Multiple Sounds

var neatAudio = require('neat-audio');
var Promise = require('es6-promise'); // or some other promise lib/polyfill

// Init neatAudio
neatAudio.init(window);

// Declare some variables to look after your sound buffers
var sounds = {
  click: null,
  shick: null,
  boom: null
};

// Load the sound buffers into local variables
Promise.all([
  neatAudio.fetchSound('click.wav'),
  neatAudio.fetchSound('shick.wav'),
  neatAudio.fetchSound('boom.wav')
]).then(function(values) {
  sounds.click = values[0];
  sounds.shick = values[1];
  sounds.boom = values[2];
  
  // Playing any of them
  neatAudio.playSound(sounds.boom);
});

Todo

[ ] Add tests for getting and playing sounds