audio-codec
A collection of VoIP audio codecs implemented for Rust. This crate provides a unified interface for encoding and decoding various audio formats commonly used in SIP, VoIP, and WebRTC applications.
Supported Codecs
| Codec | Implementation | Feature |
|---|---|---|
| G.711 (PCMA/PCMU) | Pure Rust | Built-in |
| G.722 | Pure Rust | Built-in |
| G.729 | Pure Rust (g729-sys) |
Built-in |
| Opus | Pure Rust (opus-rs) |
opus (default) |
| Telephone Event | RFC 4733 | Built-in |
Features
- Unified API: Simple
EncoderandDecodertraits for all codecs. - Resampler: Built-in audio resampling utility.
- Lightweight: Minimal dependencies for core codecs.
Performance
Measured on Apple M2 Pro (processing 20ms audio frames):
| Codec | Encode (20ms) | Decode (20ms) | Rate |
|---|---|---|---|
| PCMU | ~50.09 ns | ~59.73 ns | 8kHz |
| PCMA | ~50.23 ns | ~59.63 ns | 8kHz |
| G.722 | ~5.02 µs | ~3.82 µs | 16kHz |
| G.729 | ~20.50 µs | ~6.16 µs | 8kHz |
| Opus | ~52.34 µs | ~23.19 µs | 48kHz |
Note: Benchmarks were run with cargo bench --bench codec_bench (Criterion). create_encoder(CodecType::Opus) currently uses the default Opus profile: 48kHz, stereo, Application::Audio, bitrate 64kbps, complexity 5.
Usage
Add this to your Cargo.toml:
[]
= "0.3"
Example: Decoding PCMA
use ;
Example: Encoding G.722
use ;
Example: Configuring Opus (Factory API)
use ;
License
This project is licensed under the MIT License.