Recorderjs icon indicating copy to clipboard operation
Recorderjs copied to clipboard

Allow WAV export of complete AudioBuffer

Open kevincennis opened this issue 12 years ago • 6 comments
trafficstars

Was thinking of writing this and submitting a PR, but I wanted to see if anyone else thought it might be useful first.

Here's one use case that comes to mind:

I've created an OfflineAudioContext, rendered my mix (or whatever it is), and now I have a full AudioBuffer that I just want to export to WAV, so there's no need to attach a ScriptProcessorNode and "record" it in chunks. Obviously I can sort of do this myself by creating my own Web Worker and just passing it a sampleRate and two Float32Arrays - but it might be nice to have a static method on Recorder that will do it for me.

What do you think? Should I write it?

Oh, and thanks so much for writing this library. It served as a fantastic learning resource when I needed to do WAV export in my own app.

kevincennis avatar Jun 08 '13 14:06 kevincennis

Hey, sorry for not replying to this... feel free to submit a PR. And you're welcome, glad to hear the library helped you out.

mattdiamond avatar Jul 02 '13 18:07 mattdiamond

@kevincennis Write it! Write it! :)

I need to do this too, but my coding skills aren't up to it. I've used OfflineAudioContext to create the mix buffer, but I want it to be converted to a WAV file people can download.

Was hoping Recorder.js could perform this "faster-than-realtime" export to WAV using OfflineAudioContext.

Is there any library that exists now that can take an audio buffer and export it to a WAV file for download?

sotoole avatar Jul 13 '13 01:07 sotoole

Hey @sotoole,

Still gotta spend a little time figuring out the cleanest way to integrate this. Don't want to muddy up the Recorder constructor, but I also don't want to end up with a static method that duplicates a bunch of code.

In the meantime, here's a gist that should do more or less what you want (or at least get you pointed in the right direction): https://gist.github.com/kevincennis/5989134

Disclaimer: I wrote this in about 3 minutes and didn't test it.

kevincennis avatar Jul 13 '13 02:07 kevincennis

@kevincennis Took a quick look and it looks like exactly what I need. Thanks so much! I'll test it out tomorrow.

sotoole avatar Jul 13 '13 02:07 sotoole

@kevincennis Works perfectly. Thanks again to you and @mattdiamond

sotoole avatar Jul 13 '13 16:07 sotoole

Hey @mattdiamond,

Two years later, I found this in my list of open issues and realized I never did submit a PR. Gonna try to knock this out over the weekend.

Any preference for what this gets called? I was thinking just a static method like:

Recorder.toWAV( audioBuffer, function( blob ) {
  // do what you will
});

kevincennis avatar Jun 12 '15 17:06 kevincennis