This project has moved and is read-only. For the latest updates, please go here.

Convert from OGG Data URL

Jul 31, 2014 at 1:47 AM
I am trying to use NVorbis to convert from OGG into a WAV file.

My OGG data originates from the Firefox MediaReader API, which records audio from the computer's microphone. Here is a sample data URL. I transmit this data URL to my server, and I decode it into a byte array as follows.
// `recording` is the data URL string
var base64 = recording.Substring(1 + recording.IndexOf(","));
var bytes = Convert.FromBase64String(base64);
var stream = new MemoryStream(bytes);
var vorbis = new NVorbis.VorbisReader(stream, true);
The base 64 decoding works fine. However, when the code gets to the vorbis line, it throws the following exception:
Could not determine container type!
I have two questions:
  1. What is the best way to pass a data URL to the VorbisReader such that the VorbisReader will accept it?
  2. Once the VorbisReader is formed, how do you save it as a WAV file?
Thanks in advance!
Jul 31, 2014 at 1:52 PM
The error message is a bit incorrect... The file is an Ogg container, but has Opus data instead of Vorbis. You might try Opus.NET instead... There's not (yet) a pure C# port of Opus, so I hope you're in an environment that supports full trust...
Jul 31, 2014 at 7:59 PM
Thank you for the advice. I didn't realize that the file was not in Vorbis format. I will look into Opus.NET.