Created
July 13, 2013 02:17
-
-
Save kevincennis/5989134 to your computer and use it in GitHub Desktop.
Bounce an AudioBuffer to WAV with RecorderWorker.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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'); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Configuring
numChannels
was necessary to get this to work.