2.0.2 • Published 5 years ago

audiosprite-pkg v2.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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.

ParamTypeDescription
optionsObjectOptions
options.ffmpegstringPath to FFMpeg installation - defaults to ffmpeg in PATH environment variable
options.bitRatenumberBit rate. Works for: ac3, mp3, mp4, m4a, ogg
options.sampleRatenumberSample rate. Defaults to 44100
options.channelCountnumberNumber of channels (1=mono, 2=stereo). Defaults to 1
options.trackGapnumberSilence gap between tracks (in seconds). Defaults to 1
options.minTrackLengthnumberMinimum track duration (in seconds). Defaults to 0
options.VBRnumberoptions.VBR 0-9. Works for: mp3. -1 disables VBR
options.bufferInitialSizenumberInitial size of storage buffer in bytes. Defaults to 300kb
options.bufferIncrementSizenumberIncremental 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

ParamTypeDescription
durationnumberLength in seconds
optionsObjectOptions object
options.namestringName to use in the output JSON for the track
options.autoplaybooleanWhether this should be marked to autoplay in the output JSON
callbackfunctionComplete callback

audioSprite.input(stream, options, callback)

Input a track from a stream into the sprite.

Kind: instance method of AudioSprite

ParamTypeDescription
streamObjectInput stream
optionsObjectOptions object
options.namestringName to use in the output JSON for the track
options.autoplaybooleanWhether this should be marked to autoplay in the output JSON
options.loopbooleanWhether this should be marked to loop in the output JSON
callbackfunctionComplete callback

audioSprite.inputFile(file, options, callback)

Input a track from a file into the sprite.

Kind: instance method of AudioSprite

ParamTypeDescription
filestringArrayInput file or array of input files
optionsObjectOptions object
options.namestringName to use in the output JSON for the track
options.autoplaybooleanWhether this should be marked to autoplay in the output JSON
options.loopbooleanWhether this should be marked to loop in the output JSON
callbackfunctionComplete callback

audioSprite.outputFile(file, options, callback)

Outputs the sprite to a file.

Kind: instance method of AudioSprite

ParamTypeDescription
filestringArrayOutput file or array of output files
optionsObjectOptions object
options.namestringName to use in the output JSON for the sprite
options.formatstringWhat format the file should be outputted as, supports: aiff,caf,wav,ac3,mp3,mp4,m4a,ogg. Defaults to 'ogg'
callbackfunctionComplete callback

audioSprite.outputJson(format) ? Object

Outputs the JSON mainfest in the given format

Kind: instance method of AudioSprite
Returns: Object - JSON manifest

ParamTypeDescription
formatstringFormat of the output JSON file (jukebox, howler, howler2, createjs). Defaults to jukebox

audioSprite.outputJsonFile(file, format, callback) ? Object

Outputs the JSON manifest to file

Kind: instance method of AudioSprite
Returns: Object - JSON manifest

ParamTypeDescription
fileObjectOutput file
formatstringFormat of the output JSON file (jukebox, howler, howler2, createjs). Defaults to jukebox
callbackfunctionComplete callback
2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.1.1

7 years ago

1.1.0

8 years ago

1.0.0

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago