Prerequisites
- Rust 1.53 or later
- An audio file to decode (MP3, FLAC, OGG, WAV, etc.)
Add Symphonia to your project
Add Symphonia to your
Cargo.toml. By default, only royalty-free formats are enabled (OGG, FLAC, Vorbis, PCM, Wave, WebM).For MP3 support, enable the mp3 feature:Cargo.toml
Other format support
Other format support
- MP4/M4A container: Enable
isomp4 - AAC codec: Enable
aac - ALAC codec: Enable
alac - All formats: Enable
all
Create a media source stream
Symphonia reads from a
MediaSourceStream, which wraps any source implementing Read and Seek.For unseekable sources (like stdin), use
ReadOnlySource:Probe the format and create a decoder
Use Symphonia’s probe to automatically detect the audio format and create a decoder for the track.
Decode packets in a loop
The decode loop retrieves packets from the format reader and decodes them into audio samples.
Complete Example
Here’s a complete, working program that decodes an audio file and counts the samples:Common Errors
unsupported format
unsupported format
The audio format isn’t enabled. Check your
Cargo.toml features and add the required format support.no supported audio tracks
no supported audio tracks
The file may be corrupted, or it might be a video file. If decoding video files, search specifically for audio tracks instead of using the default track.
unsupported codec
unsupported codec
The codec isn’t enabled. Enable the appropriate codec feature in
Cargo.toml (e.g., mp3, aac, alac).Next Steps
Core Concepts
Learn about demuxing, decoding, and Symphonia’s architecture
API Reference
Explore the complete API documentation
Working with Audio Data
Learn how to access and process decoded audio samples
Metadata
Extract and handle audio metadata and tags