audiosprite-pkg
This project is no longer maintained
Based on the audiosprite module (https://github.com/tonistiigi/audiosprite), takes the same functionality but exposes it as a node module instead of command line.
This allows better integration with grunt / gulp and other build systems.
Uses buffer streams to prevent creation of temporary files like the original.
v2.0.0 of audiosprite-pkg now returns promises for each API call, making the callbacks entirely optional.
npm install audiosprite-pkg
Example
var AudioSprite = require('audiosprite-pkg');
var as = new AudioSprite();
// .inputFile can be called as many times as necessary
as.inputFile( 'inputFile.ogg', function( err ) {
// .outputFile can also be called many times with different formats
as.outputFile( 'output.mp3', { format: 'mp3' }, function( err ) {
// output the final JSON file - this should be called once all other operations have completed
as.outputJsonFile( 'output.json', function( err ) {
// all done!
} );
} );
} );
Example using Promise API introduced in v2.0.0
const as = new AudioSprite();
return as.inputFile( 'input1.wav' )
.then( function() {
return as.inputFile( 'input2.wav' );
} )
.then( function() {
return as.inputFile( [ 'input3.wav', 'input4.wav' ] );
} )
.then( function() {
return as.outputFile( 'output.wav' );
} )
.then( function() {
return as.outputJsonFile( 'output.json' );
} );
Comprehensive example using async.js
var AudioSprite = require('audiosprite-pkg');
var as = new AudioSprite( { ffmpeg: '/my/path/to/ffmpeg', sampleRate: 96000, channelCount: 2, trackGap: 3 } );
async.waterfall( [
function( cb ) {
as.inputFile( 'sound.mp3', cb );
},
function( cb ) {
as.inputFile( 'sound2.ogg', { name: 'json tag', loop: true }, cb );
},
function( cb ) {
// input method can accept input directly from a stream
// accepts the same options as inputFile() does
var stream = fs.createReadStream( 'sound3.wav' );
as.input( stream, cb );
},
function( cb ) {
// Output final sprite
as.outputFile( 'mysprite.mp3', { format: 'mp3' }, cb );
},
function( cb ) {
// Output can be called as many times as necessary to generate different formats,
as.outputFile( 'mySprite.ac3', { format: 'ac3' }, cb );
},
function( cb ) {
// Output JSON manifest file
as.outputJsonFile( 'mysprite.json', cb );
}
function( cb ) {
// You can also call outputJson() to just get the manifest object without writing it to file.
var myManifest = as.outputJson();
console.log( myManifest );
cb();
}
],
function( err ) {
if ( err ) {
console.log( "An error occurred!", err );
}
}
);
AudioSprite
Kind: global class
new AudioSprite([options])
Constructor for AudioSprite object. Accepts an optional options object.
Param | Type | Description |
---|---|---|
[options] | Object |
Options |
options.ffmpeg | string |
Path to FFMpeg installation - defaults to ffmpeg in PATH environment variable |
options.bitRate | number |
Bit rate. Works for: ac3, mp3, mp4, m4a, ogg |
options.sampleRate | number |
Sample rate. Defaults to 44100 |
options.channelCount | number |
Number of channels (1=mono, 2=stereo). Defaults to 1 |
options.trackGap | number |
Silence gap between tracks (in seconds). Defaults to 1 |
options.minTrackLength | number |
Minimum track duration (in seconds). Defaults to 0 |
options.VBR | number |
options.VBR [0-9]. Works for: mp3. -1 disables VBR |
options.bufferInitialSize | number |
Initial size of storage buffer in bytes. Defaults to 300kb |
options.bufferIncrementSize | number |
Incremental growth of storage buffer in bytes. Defaults to 100kb |
audioSprite.inputSilence(duration, [options], [callback])
Input a silent track into the sprite.
Kind: instance method of AudioSprite
Param | Type | Description |
---|---|---|
duration | number |
Length in seconds |
[options] | Object |
Options object |
options.name | string |
Name to use in the output JSON for the track |
options.autoplay | boolean |
Whether this should be marked to autoplay in the output JSON |
[callback] | function |
Complete callback |
audioSprite.input(stream, [options], [callback])
Input a track from a stream into the sprite.
Kind: instance method of AudioSprite
Param | Type | Description |
---|---|---|
stream | Object |
Input stream |
[options] | Object |
Options object |
options.name | string |
Name to use in the output JSON for the track |
options.autoplay | boolean |
Whether this should be marked to autoplay in the output JSON |
options.loop | boolean |
Whether this should be marked to loop in the output JSON |
[callback] | function |
Complete callback |
audioSprite.inputFile(file, [options], [callback])
Input a track from a file into the sprite.
Kind: instance method of AudioSprite
Param | Type | Description |
---|---|---|
file | string |
Array |
[options] | Object |
Options object |
options.name | string |
Name to use in the output JSON for the track |
options.autoplay | boolean |
Whether this should be marked to autoplay in the output JSON |
options.loop | boolean |
Whether this should be marked to loop in the output JSON |
[callback] | function |
Complete callback |
audioSprite.outputFile(file, [options], [callback])
Outputs the sprite to a file.
Kind: instance method of AudioSprite
Param | Type | Description |
---|---|---|
file | string |
Array |
[options] | Object |
Options object |
options.name | string |
Name to use in the output JSON for the sprite |
options.format | string |
What format the file should be outputted as, supports: aiff,caf,wav,ac3,mp3,mp4,m4a,ogg. Defaults to 'ogg' |
[callback] | function |
Complete callback |
Object
audioSprite.outputJson(format) ? Outputs the JSON mainfest in the given format
Kind: instance method of AudioSprite
Returns: Object
- JSON manifest
Param | Type | Description |
---|---|---|
format | string |
Format of the output JSON file (jukebox, howler, howler2, createjs). Defaults to jukebox |
Object
audioSprite.outputJsonFile(file, format, [callback]) ? Outputs the JSON manifest to file
Kind: instance method of AudioSprite
Returns: Object
- JSON manifest
Param | Type | Description |
---|---|---|
file | Object |
Output file |
format | string |
Format of the output JSON file (jukebox, howler, howler2, createjs). Defaults to jukebox |
[callback] | function |
Complete callback |