Skip to content

Concatenate WAV files and pads with silence to whole seconds, for use in audio sprites.

Notifications You must be signed in to change notification settings

kribblo/wav-audio-sprite

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wav-audio-sprite

Concatenate WAV files and pads with silence to whole seconds, for use in audio sprites.

Meant to be instantly useful during development and later part of a larger tool-chain.

This process is really fast, compared to also encoding to a compressed format, which makes it extra suitable for local development.

Notes on usage

Only concatenates and pads + records information for use by a suitable player later. Does not convert to MP3, OGG, or other format. As such, there are no external dependencies such as FFMEPG or SOX that can sometimes trip up people. It is also very fast, so during development, you can do this on the fly for every request.

Use the WAVs during development and do final conversion for release builds in a separate part of the tool-chain - or even manually by the sound guy to get the most out of desktop/mobile and different formats.

Padding is by default at minimum one second silence between each sample, but if options.padding is set in milliseconds, that gap will be used instead, without aligning to each whole second.

API usage

npm install --save-dev wav-audio-sprite
const wavAudioSprite = require('wav-audio-sprite');

const files = ['sound-a.wav', 'sound-b.wav'];
const options = {
    padding: 200
};
wavAudioSprite(files, options)
    .then(result => {
        const {buffer, timings} = result;
        saveAudioSprite(buffer);
        postProcessTimings(timings);
    })
    .catch(e => console.error(e));

timings contains each filename, with start, end and durations - different tools wants different data and this is meant to be further processed if needs be:

{
  "sound-a.wav": {
    "start": 0,
    "end": 29538.73015873016,
    "duration": 29538.73015873016
  },
  "sound-b.wav": {
    "start": 31000,
    "end": 88600.23,
    "duration": 57600.23
  }
}

CLI usage

npm install -g wav-audio-sprite

howler-sprite

Barely more than an example, but outputs audiosprite and json in Howler.js format:

howler-sprite *.wav

howler-sprite --name mysprite *.wav

howler-sprite --path build *.wav

howler-sprite --path build --name mysprite *.wav

Add -q or --quiet to silence the output.

audio-sprite.json:

{
  "src": [
    "audio-sprite.wav"
  ],
  "sprite": {
    "sound-a": [0, 29538],
    "sound-b": [31000, 88600]
  }
}

See also

Uses node-wav for decoding/encoding.

About

Concatenate WAV files and pads with silence to whole seconds, for use in audio sprites.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published