Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@1j01 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