cpal
Low-level, cross-platform audio I/O library for Rust with a unified API over ALSA, WASAPI, CoreAudio, JACK, and more.
Repository Health
Technical Analysis
cpal is a low-level cross-platform audio input/output library for Rust, providing a single Host/Device/Stream API that abstracts over each platform’s native audio backend: ALSA, PulseAudio, PipeWire, and JACK on Linux; WASAPI and ASIO on Windows; CoreAudio on macOS/iOS; AAudio on Android; and the Web Audio API/AudioWorklet in WebAssembly. Applications enumerate available devices and their supported stream configurations, then open an input or output stream with a callback invoked on each buffer of audio samples.
As part of the RustAudio organization, cpal is the foundational audio I/O layer underneath much of the Rust audio ecosystem — used directly by synthesizers, DAWs, voice-processing tools, and games, and as the device-access layer beneath higher-level crates like rodio. With 16+ million cumulative downloads and a very active maintenance cadence, it is the standard choice whenever a Rust project needs to capture or play raw audio samples without depending on a single OS’s native API.
What You Get
- A
Host/Device/Streamtrait hierarchy that abstracts over platform-specific audio backends behind one API - Device enumeration and supported stream configuration querying (sample rate, channel count, sample format)
- Callback-based input and output streams that deliver/consume buffers of audio samples in real time
- Optional backends behind Cargo features: ASIO (low-latency Windows), JACK, PipeWire, and an AudioWorklet backend for WebAssembly
- A
realtimefeature for platform-specific real-time thread scheduling to reduce audio glitches/underruns - A
customfeature for plugging in user-defined hosts, devices, and streams for testing or non-standard backends
Common Use Cases
- Capturing microphone input for a voice-processing, transcription, or voice-chat application
- Building a software synthesizer, DAW, or audio effect processor that needs low-latency playback
- Recording audio to disk (e.g. WAV) from the system’s default or a specifically selected input device
- Cross-compiling one audio codebase to Linux, Windows, macOS, Android, iOS, and WebAssembly targets
Under The Hood
Architecture — cpal’s public API (src/traits.rs, src/lib.rs) defines Host, Device, and Stream traits, with src/host/ containing one backend implementation per platform (alsa, pulseaudio, pipewire, jack, wasapi, asio, coreaudio, aaudio, webaudio, audioworklet, plus a null backend for headless/CI use), and src/platform/mod.rs selecting the appropriate backend set at compile time via cfg attributes. This lets application code write against the trait interface once while the correct OS-specific implementation is compiled in per target. Tech Stack — Rust 2021 edition (rust-version 1.85+); most backends bind to system libraries directly (ALSA via alsa-sys, ASIO via the companion asio-sys workspace crate, WASAPI/CoreAudio via OS-provided COM/Core Foundation bindings), with an audioworklet feature adding wasm-bindgen/web-sys for WebAssembly targets and a realtime feature adding audio_thread_priority for real-time thread scheduling. Code Quality — The crate maintains an examples/ directory covering desktop, Android, iOS, and WASM builds (beep.rs, record_wav.rs, feedback.rs, synth_tones.rs), a documented UPGRADING.md for breaking changes, and a maintenance = actively-developed badge backed by a very active commit and release cadence (health-score development-activity and maintenance-consistency both near maximum). API Design — The Host/Device/Stream/callback model is intentionally minimal and close to the underlying OS APIs it wraps, so switching between backends (e.g. ALSA to JACK) requires no application code changes beyond host selection, though understanding platform-specific audio concepts (buffer sizes, sample formats, real-time scheduling) is still necessary to use it effectively.
Used by 5 apps in this directory
Epicenter
Knowledge Management · Note Taking · Developer Tools
A local-first monorepo led by Whispering, an open-source speech-to-text app, built on an MIT toolkit that turns your data into plain Markdown and SQLite files you own instead of a database you rent.
Handy
Productivity
Free, offline, open-source speech-to-text that pastes directly into any app on Windows, macOS, and Linux.
Lokus
Note Taking · Knowledge Management
Local-first note-taking with graph view, canvas & AI plugins—your Markdown files, zero telemetry, blazing-fast Rust performance.
Meetily
Productivity · AI Assistants
Privacy-first AI meeting assistant that transcribes and summarizes your meetings entirely on your local machine — no cloud, no data leakage.
Voicebox
AI Development · Productivity
Clone voices, dictate anywhere, and give AI agents your voice — all locally.