audio-io
A simple library to read and write audio files on your disk.
The library can read many formats and can write only to wav files.
Quick Start
Read Audio
You can read most common audio formats, if you specify them in the feature flags.
use *;
let data: = audio_read.unwrap;
let sample_rate = data.sample_rate;
let block = data.audio_block; // convert into AudioBlock, which makes it easier to access channels or frames (does not allocate).
Write Audio
You can only write wav files.
use *;
let sample_rate = 48000
let block = from_slice;
audio_write.unwrap;
By leveraging audio-blocks you can write any audio layout, e.g.:
let block = from_slice;
audio_write.unwrap;
let block = from_slice;
audio_write.unwrap;
Supported Input Codecs
Only royalty free codecs are enabled by default.
| Format | Feature Flag | Enabled by Default |
|---|---|---|
| AAC | aac |
No |
| ADPCM | adpcm |
Yes |
| ALAC | alac |
No |
| FLAC | flac |
Yes |
| CAF | caf |
No |
| ISO MP4 | isomp4 |
No |
| Matroska (MKV) | mkv |
Yes |
| MP1 | mp1 |
No |
| MP2 | mp2 |
No |
| MP3 | mp3 |
No |
| Ogg | ogg |
Yes |
| PCM | pcm |
Yes |
| AIFF | aiff |
No |
| Vorbis | vorbis |
Yes |
| WAV | wav |
Yes |
To enable all formats, use the all feature flag.
Read and Write Options
Reading
When reading a file you can specify the following things:
- Start and stop in frames or time
- First channel and number of channels
The crate will try to decode and store only the parts that you selected.
Writing
For writing audio you can only select to store the audio in Int16 or Float32.
By default Int16 is selected, for broader compatibility.
Some example configs:
- read from frame 300 to 400
let audio = .unwrap;
- read the first 0.5 seconds
use Duration;
let audio = .unwrap;
- read only the first two channels
let audio = .unwrap;
- skip the first channel, reading channel 2 and 3
let audio = .unwrap;
- write audio samples in
Float32
audio_write
.unwrap;