rustaudioaudio-streamingrust-tokiosymphonia

How to decode an asynchronous encoded audio stream into PCM?


I need to decode an asynchronous audio stream from a websocket in real time (preferably vorbis/opus encoded ogg) and I'm failing to find a proper crate to help me with this job.

Almost every crate has synchronous API that relies on std::io::Read which doesn't fit in this case. The only crate I could find is ogg, but it doesn't decode ogg packets into PCM samples delegating this to "some other crate, e.g. lewton". As it turns out the packet data it emits isn't compatible neither with lewton nor with symphonia's VorbisDecoder.

Could you please point me to any asynchronous solution?


Solution

  • It turns out the ogg's asynchronous PacketReader can be successfully combined with symphonia's VorbisDecoder. To do that we need to use contents of a first (id) and a third (setup) stream packets as CodecParameters::extra_data while the second one (comment) is skipped. The rest of the packets can be fed to VorbisDecoder. Thanks to est31 (the ogg's author) for the given assistance.