This module will take sampled data and encode it as a wav file. This is based on https://github.com/mattdiamond/Recorderjs/
npm install wavencoder
This module will take sampled data and encode it as a wav file. This is based on https://github.com/mattdiamond/Recorderjs/
This module will use webworkers if they are available with no extra setup.

The following example uses wavencoder and two other modules to record 3 seconds of audio from a users mic encode the recorded data as a wav file and allow the user to download it. (It should be noted that in Chrome you must run this code on https as getUserMedia is only available on https)
``javascript
var recordmic = require('recordmic');
var browsersavefile = require( 'browsersavefile' );
var wavencoder = require('wavencoder')();
if(recordmic.isAvailable) {
var recorder = recordmic({ onSampleData: function( left, right ) {
// console.log( left );
}}, function( error ) {
console.log('we\'re good', error);
if(!error) {
console.log('start recording');
recorder.start();
setTimeout(function() {
console.log('stop recording');
recorder.stop();
wavencoder.data(recorder.getStereoData());
wavencoder.export(function(error, data) {
browsersavefile('output.wav', data);
});
}, 3000);
}
});
} else {
throw new Error( 'not avaiable' );
}
`
To construct a wavencoder just require and call a function.
You can pass optional options when insntantiating the encoder.
- sampleRate: This is the sameple rate of the recorded audio. Default: 44100channels
- : How many channels of audio the recorded audio has. Default: 2noWorker
- : If you'd like to force not using a web worker pass in true for noWorker
The data function should be passed interleaved audio data that will be exported.
The export function should be called when you'd like to encode your wav file based on the interleaved data passed to the data` function.
This function takes on parameter which is a callback function. This callback will passback an error if an error occurs and the encoded audio as the second parameter. The encoded data will be a blob.
MIT, see LICENSE.md for details.