Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: ability to decode back to buffers #12

Closed
paullewis opened this issue Apr 30, 2015 · 9 comments
Closed

Request: ability to decode back to buffers #12

paullewis opened this issue Apr 30, 2015 · 9 comments

Comments

@paullewis
Copy link

I'm working on at a bit of code which stores generated audio files in IndexedDB, but also uses the Web Audio API as well.

As it stands your version of Recorderjs is epic and works amazingly well, but because Chrome's implementation doesn't support Opus in decodeAudioData, when I pass an ogg file in it fails to decode. I can see from the emscriptened libopus that the decode functionality is there, but that Recorderjs doesn't have a corresponding decode call. Is there any chance you can add it? I'd do a PR, but I'm not quite sure how to work with the emscriptened code, I'm afraid :-/

@chris-rudmin
Copy link
Owner

I had the decode audio logic in the lib, but decided to remove it, because:

  • Decoding and playback is outside the scope of a recording lib.
  • Up to date browsers can usually play ogg audio with the audio tag.

You can reference the decoder code here

Alternatively, perhaps there is a way to get the PCM out of an audio tag?

@paullewis
Copy link
Author

Makes perfect sense that you removed it :) In my case I can't use the <audio> element or new Audio because I require an offlineAudioContext, which is a bit of a bummer as they don't support MediaElementAudioSourceNodes!

One question from me: the decode function takes packets. How does that map to the ogg file blob? Do I convert over to an arraybuffer and fire it into that function, or do I need to break it up in some way first? Sorry for the noob questions, and thank you again for all your hard work on this.

@chris-rudmin
Copy link
Owner

To get the packets out of an ogg file, you will need to parse each page, and then parse the segment table to get the packet boundaries. I've seen some libs around which can do this. I think speex.js has something and perhaps aurora.js as well.

https://github.com/jpemartins/speex.js/blob/master/src/ogg.js
https://github.com/audiocogs/ogg.js/releases

@chris-rudmin
Copy link
Owner

If you can follow the logic after encode(), you need to do the same, but backwards.

@chris-rudmin
Copy link
Owner

I have created a new branch for opus only operation. I have included a decoder for completeness. It has not been documented or thoroughly tested, but the happy path is working. Check it out if you are still in need.

@chris-rudmin
Copy link
Owner

Merged decoder which allows decoding back to buffers.

@paullewis
Copy link
Author

Oh boy, I'm only just catching up on this. It's super that you broke them out to two separate scripts - thank you!

@jlev
Copy link

jlev commented Jun 30, 2015

@chris-rudmin Any chance you could write a little documentation on how to use the decoding script? I'm trying to use your excellent library to record audio for Twilio, which only accepts mp3, wav, aiff or ulaw, but unfortunately not ogg/opus. So I can either store the files as ogg on the server and transcode with ffmpeg before sending to Twilio, or get access to the buffers after downsampling and save them as wav.

@chris-rudmin
Copy link
Owner

You create a worker with the decoder and then pass it a typed array with your encoded data along with the decode command. Sounds like it might be easier to use the original recorder is and record wav.
I will add some documentation when I get some time.

chris-rudmin added a commit that referenced this issue Jul 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants