Project Website • Minimal demo
flac.js encodes or decodes whole files to FLAC, the Free Lossless Audio Codec. Supported input formats are wav
, rf64
, w64
, aif
, flac
(flac in its native container as well as in oga/ogg). It is supposed to do the same as the flac executable that can be built from the FLAC sources.
This version of flac.js was built with Emscripten 1.37.20; flac 1.3.2; libogg 1.3.3
If you just want to use flac.js, you don't have to build it. In this case, see using instead.
- A recent linux build system
- Emscripten installed and activated
git clone --recursive git://github.com/Rillke/flac.js.git flac.js
cd flac.js
./make.sh
A pre-compiled script together with some auxiliary scripts making use from JavaScript easier is in the /worker
directory.
iframe.html is a minimal usage example. Test it live. It starts the encoding process posting command: 'encode'
to the worker:
var worker = new Worker( 'worker/EmsWorkerProxy.js' );
// Input data
var fileName = 'pcmData.raw';
var inData = {
// File name
fileName: {
// Must be Uint8
fileData
}
}
// Files to be read and posted back
// after encoding completed
var outData = {
// File name
'encoded.flac': {
// MIME type
'MIME': 'audio/flac'
}
};
worker.onmessage = function( e ) {
// Handle incoming data
};
worker.onerror = function( e ) {
// Handle error
};
// Arguments
var args = [
"--endian=little", // endianness of samples
"--sign=unsigned", // representation of numbers
"--channels=1", // channel count
"--bps=8", // bits per second
"--sample-rate=16000", // sample rate in Hz
fileName
];
// Post all data and the encode command
// to the web worker
worker.postMessage( {
command: 'encode',
args: args,
outData: outData,
fileData: inData
} );
command
:'encode'|'prefetch'
DOMString that either starts encoding (or decoding) or prefetching the worker script. Posting a prefetch command in advance is optional, depends on the user experience you'd like to create and does not require further arguments. If the script is not prefetched, it will be downloaded when'encode'
is invoked.args
: Array holding the command line arguments (DOMString)outData
: Object literal of information about the files that should be read out of the worker's file system after encoding completedfileData
: Object literal of input file data mapping file names toUint8Array
s
A more extensive example is available on the project's website.
Submit patches to this GitHub repository or file issues.
See LICENSE.md