musquito, A Web Audio API Library


musquito is an audio engine created using Web Audio API for HTML5 games and interactive websites. It provides a simple abstraction to create and play sounds easier.

Below are some of the core features supported by the library.

  • Simple API to create and play sounds
  • Supports variety of codecs
  • Supports audio sprites
  • Fading
  • Caching

Browser Support

  • Google Chrome
  • Firefox
  • Safari
  • Opera
  • Microsoft Edge


At this time musquito is available only in npm and you can install it using the below command.

npm install musquito --save

You can also directly reference files available from the distribution folder.

<script src="musquito/dist/musquito-1.0.0.min.js"></script>

"Hello World" example

A simple example of how to create and play a gun fire sound.

ES6 and above

import $buzz from 'musquito';

const buzz = $buzz('gunfire.mp3');;

Classic JavaScript

var buzz = $buzz('gunfire.mp3');;

Advanced example

The below example shows how you can pass additional parameters like volume, rate and event handlers.

const buzz = $buzz({
  src: ['gunfire.mp3', 'gunfire.wav'],
  volume: 0.5,
  rate: 2,
  onplaystart: () => console.log('Playback started'),
  onplayend: () => console.log('Playback ended')

Using Sprites

Audio Sprites are like image sprites concatenates multiple small sounds in a single file. You can create audio sprite using this tool.

Below is an example of how to use sprites.

const buzz = $buzz({
  src: 'gamesprite.mp3',
    'gun': [0, 0.48],
    'bomb': [2, 2.42],
    'greenade': [4, 4.67]

Fading Sounds

You can fade the volume of a playing sound linearly or exponentially as shown below.

const buzz = $buzz({
  src: 'bg.mp3'

buzz.fade(0, 3);


To know all the API methods please visit here.

Source Code



blog comments powered by Disqus