Skip to content

Instantly share code, notes, and snippets.

@gabouh
Forked from kevincennis/buffertowav.js
Created May 8, 2016 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabouh/49cc852fc2f7f9c3b20b9ca411f40568 to your computer and use it in GitHub Desktop.
Save gabouh/49cc852fc2f7f9c3b20b9ca411f40568 to your computer and use it in GitHub Desktop.
Buffer to WAV
// assuming a var named `buffer` exists and is an AudioBuffer instance
// start a new worker
// we can't use Recorder directly, since it doesn't support what we're trying to do
var worker = new Worker('recorderWorker.js');
// initialize the new worker
worker.postMessage({
command: 'init',
config: {sampleRate: 44100}
});
// callback for `exportWAV`
worker.onmessage = function( e ) {
var blob = e.data;
// this is would be your WAV blob
};
// send the channel data from our buffer to the worker
worker.postMessage({
command: 'record',
buffer: [
buffer.getChannelData(0),
buffer.getChannelData(1)
]
});
// ask the worker for a WAV
worker.postMessage({
command: 'exportWAV',
type: 'audio/wav'
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment