webrtc-rs / webrtc

A pure Rust implementation of WebRTC
https://webrtc.rs
Apache License 2.0
3.95k stars 347 forks source link

Best practices for decoding Opus audio in real time #550

Open SoftMemes opened 3 months ago

SoftMemes commented 3 months ago

First of all, I'm so glad this project exists! I initially attempted to complete my project directly in Kotlin on the JVM, but the WebRTC support, even when wrapping the Google library, is not great - and using this library has been a joy in comparison.

Now, I'm able to use this library for two way real time audio. One end runs as a service, and the other end is made up of regular WebRTC clients (browsers/apps). While this works, I want to make sure that I'm not missing any best practices, especially when it comes to audio.

I am using Opus only and have been using https://docs.rs/opus/latest/opus/ for this. This works, although the library itself (and the libopus version it's using) is quite old. I've seen the examples in this repo that save audio to disk etc, but this only saves the frames as is, it does not do any decoding. Some specific questions:

morajabi commented 3 months ago

@SoftMemes using this package works quite well. (alternative is this library). To make voice chat application you need to do:

this is a rough overview of things you need. webrtc_rs and str0m both ship with a basic packet re-orderer that might work well enough for you. although you'd need to use a jitter buffer (or write one yourself)