RepositoryRustSESweden
udoprog

udoprog/audio

A crate for working with audio in Rust

92stars
11forks
15issues
1views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: wasapi

#1 Repository of the month

2
TINIX TRENDING·Topic: alsa

#2 Repository of the month

audio

github crates.io docs.rs build status

A crate for working with audio in Rust.

This is made up of several parts, each can be used independently of each other:

  • audio-core - The core crate, which defines traits that allows for interacting with audio buffers independent of their layout in memory.
  • audio - This crate, which provides a collection of high-quality audio buffers which implements the traits provided in audio-core.
  • audio-device - A crate for interacting with audio devices in idiomatic Rust.
  • audio-generator - A crate for generating audio.

Audio buffers provided by this crate have zero or more channels that can be iterated over. A channel is simply a sequence of samples. The samples within each channel at one moment in time are a frame. A buffer can store channels in various ways in memory, as detailed in the next section.


Buffers

This crate provides several structs for storing buffers of multichannel audio. The examples represent how the two channels [1, 2, 3, 4] and [5, 6, 7, 8] are stored in memory:

  • Dynamic: each channel is stored in its own heap allocation. So [1, 2, 3, 4] and [5, 6, 7, 8]. This may be more performant when resizing freqently. Generally prefer one of the other buffer types for better CPU cache locality.
  • Interleaved: samples of each channel are interleaved in one heap allocation. So [1, 5, 2, 6, 3, 7, 4, 8].
  • Sequential: each channel is stored one after the other in one heap allocation. So [1, 2, 3, 4, 5, 6, 7, 8].

These all implement the Buf and BufMut traits, allowing library authors to abstract over any one specific format. The exact channel and frame count of a buffer is known as its topology. The following example allocates buffers with 4 frames and 2 channels. The buffers are arranged in memory differently, but data is copied into them using the same API.

use audio::{BufMut, ChannelMut};

let mut dynamic = audio::dynamic![[0i16; 4]; 2];
let mut interleaved = audio::interleaved![[0i16; 4]; 2];
let mut sequential = audio::sequential![[0i16; 4]; 2];

audio::channel::copy_iter(0i16.., dynamic.get_mut(0).unwrap());
audio::channel::copy_iter(0i16.., interleaved.get_mut(0).unwrap());
audio::channel::copy_iter(0i16.., sequential.get_mut(0).unwrap());

We also support wrapping external buffers so that they can interoperate like other audio buffers.


Example: play-mp3

Play an mp3 file with minimp3-rs, cpal, and rubato for resampling.

This example can handle with any channel and sample rate configuration.

cargo run --release --package audio-examples --bin play-mp3 -- path/to/file.mp3

Examples

use rand::Rng;

let mut buf = audio::buf::Dynamic::<f32>::new();

buf.resize_channels(2);
buf.resize_frames(2048);

/// Fill both channels with random noise.
let mut rng = rand::thread_rng();
rng.fill(&mut buf[0]);
rng.fill(&mut buf[1]);

For convenience we also provide several macros for constructing various forms of dynamic audio buffers. These should mostly be used for testing.

let mut buf = audio::buf::Dynamic::<f32>::with_topology(4, 8);

for mut channel in &mut buf {
    for f in channel.iter_mut() {
        *f = 2.0;
    }
}

assert_eq! {
    buf,
    audio::dynamic![[2.0; 8]; 4],
};

assert_eq! {
    buf,
    audio::dynamic![[2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0]; 4],
};

Similar Projects

Discover other similar projects and AI models.

RepositoryRust
HEnquist/camilladsp

A flexible cross-platform IIR and FIR engine for crossovers, room correction etc.

1.1k
Nov 29, 2026
Modelsentence-similarity
sentence-transformers/all-MiniLM-L6-v2

all-MiniLM-L6-v2 This is a sentence-transformers(https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. Usage (Sentence-Transformers) Using t...

♥0
157.6M
Jun 1, 2026
RepositoryRust
farion1231/cc-switch

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode,DeepSeek Harness and more. Only official website: ccswitch.io

158.7k
Dec 2, 2026
RepositoryC
FFmpeg/FFmpeg

Mirror of https://git.ffmpeg.org/ffmpeg.git

68.4k
Nov 29, 2026
RepositoryPython
OpenBMB/VoxCPM

VoxCPM2: Tokenizer-Free TTS for Multilingual Speech Generation, Creative Voice Design, and True-to-Life Cloning

43.1k
Nov 9, 2026
RepositoryC
mpv-player/mpv

🎥 Command line media player

38.4k
Nov 29, 2026
Modelautomatic-speech-recognition
openai/whisper-large-v3

Whisper Whisper is a state-of-the-art model for automatic speech recognition (ASR) and speech translation, proposed in the paper Robust Speech Recognition via Large-Scale Weak Supervision(https://huggingface.co/papers/2212.04356) by Alec Radford et...

♥0
3.0M
Aug 12, 2024
Modelautomatic-speech-recognition
pyannote/speaker-diarization-3.1

Using this open-source model in production? Consider switching to pyannoteAI(https://www.pyannote.ai) for better and faster options. 🎹 Speaker diarization 3.1 This pipeline is the same as pyannote/speaker-diarization-3.0(https://hf.co/pyannote/speak...

♥0
5.7M
May 10, 2024
Modelautomatic-speech-recognition
pyannote/speaker-diarization-community-1

community-1 speaker diarization This pipeline ingests mono audio sampled at 16kHz and outputs speaker diarization. - stereo or multi-channel audio files are automatically downmixed to mono by averaging the channels. - audio files sampled at a differ...

♥0
4.8M
Sep 29, 2025