diff --git a/README.md b/README.md index 3830a91d..5e6f55c0 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,21 @@ This will pass the recorded stereo buffer (as an array of two Float32Arrays, for } This sample code will play back the stereo buffer. +More simply: + + rec.getAudioBuffer([callback]) + +This will pass the recorded AudioBuffer to the callback. + + function getAudioBufferCallback( buffer ) { + var newSource = audioContext.createBufferSource(); + newSource.buffer = newBuffer; + newSource.connect( audioContext.destination ); + newSource.start(0); + } + +This sample code will also play back the stereo buffer. + rec.configure(config) @@ -73,4 +88,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/recorder.js b/recorder.js index 52f3d0cd..63b67005 100644 --- a/recorder.js +++ b/recorder.js @@ -54,6 +54,16 @@ currCallback = cb || config.callback; worker.postMessage({ command: 'getBuffer' }) } + + this.getAudioBuffer = function (cb, context) { + var ctx = context || this.context + this.getBuffer(function (buffers) { + var newBuffer = ctx.createBuffer(2, buffers[0].length, ctx.sampleRate); + newBuffer.getChannelData(0).set(buffers[0]); + newBuffer.getChannelData(1).set(buffers[1]); + cb(newBuffer) + }) + } this.exportWAV = function(cb, type){ currCallback = cb || config.callback;