Skip to content

Instantly share code, notes, and snippets.

@kevincennis
Created July 13, 2013 02:17
Show Gist options
  • Save kevincennis/5989134 to your computer and use it in GitHub Desktop.
Save kevincennis/5989134 to your computer and use it in GitHub Desktop.
Bounce an AudioBuffer to WAV with RecorderWorker.js
// assuming you have an AudioBuffer instance called `buffer`,
// and an AudioContext (or OfflineAudioContext) called `ctx`...
// create a new Worker...
var worker = new Worker('recorderWorker.js');
// get it started and send some config data...
worker.postMessage({
command: 'init',
config: {
sampleRate: ctx.sampleRate
}
});
// pass it your full buffer...
worker.postMessage({
command: 'record',
buffer: [
buffer.getChannelData(0),
buffer.getChannelData(1)
]
});
// ask it to export your WAV...
worker.postMessage({
command: 'exportWAV',
type: 'audio/wav'
});
// force a download when it's done
worker.onmessage = function(e){
Recorder.forceDownload(e.data, 'SomeFileName.wav');
};
@1j01
Copy link

1j01 commented Nov 16, 2015

Configuring numChannels was necessary to get this to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment