mlx-audio-io
The native audio data layer for Apple MLX: fast file decode and encode directly to and from mlx.core.array, with one unified API across macOS and Linux.
- Zero-Copy MLX Pipeline: Direct decode and encode via DLPack capsules (
mx.from_dlpack) and the Python buffer protocol. - Zero Torch, Zero NumPy: MLX is the sole required runtime dependency. No heavyweight PyTorch or NumPy runtime overhead.
- Apple Silicon Optimized: Native macOS backend powered by Apple AudioToolbox loads a WAV 6.8x faster than librosa and saves one 1.5x faster than SoundFile on an M4 Max (measurements).
- Decoupled Architecture: Upgrading
mlxnever requires rebuildingmlx-audio-io. One build works with any installed MLX (0.32.0+). - Concurrent Writer Engine: Staged buffer preparation (
prepare_save/save_prepared) releases the Python GIL and avoids MLX contention across background export workers.
Installation
pip install mlx-audio-io
Prebuilt wheels are published for macOS 14 or later on Apple Silicon (Python 3.10 to 3.14), so nothing is compiled there. Other platforms build from source during install; see the Installation Guide for the compiler and Linux packages that needs.
MLX Compatibility
mlx-audio-io requires:
- macOS:
mlx>=0.32.0(Apple Silicon) - Linux:
mlx[cpu]>=0.32.0
Because decoded audio enters MLX via DLPack and save operations consume arrays through the buffer protocol, mlx-audio-io does not link against libmlx.dylib. Upgrading MLX versions in your environment does not require rebuilding mlx-audio-io.
For Linux build dependencies, source checkout, and troubleshooting, see the Installation Guide.
Quickstart
1. Load Audio
import mlx_audio_io as audio_io
# Decode native format directly into an mx.array: [frames, channels]
audio, sr = audio_io.load("speech.wav")
# Load with automatic high-quality resampling and mono fold-down
audio_16k, sr_16k = audio_io.load("speech.wav", sr=16000, mono=True)
2. Save Audio
# Save float32 or pcm16 WAV
audio_io.save("out.wav", audio, sr)
audio_io.save("out_pcm16.wav", audio, sr, encoding="pcm16")
# Save compressed formats (MP3, AAC/M4A, FLAC)
audio_io.save("out.mp3", audio, sr, bitrate="192k")
audio_io.save("out.m4a", audio, sr, bitrate="256k")
audio_io.save("out.flac", audio, sr)
3. Chunked Streaming
Stream long audio files in fixed-duration chunks without decoding the whole file into RAM:
for chunk, chunk_sr in audio_io.stream("long_recording.wav", chunk_duration=2.0):
# chunk is an mx.array of shape [frames, channels]
process(chunk)
4. Concurrent Background Export
For multi-stem export pipelines (e.g. Demucs, audio separators), stage the buffer once on the producer thread and delegate writing to background file workers:
from concurrent.futures import ThreadPoolExecutor
import mlx_audio_io as audio_io
# Producer: stage read-only view and evaluate lazy MLX graph
prepared = audio_io.prepare_save(stem, layout="channels_first")
# Worker threads: encode and write without holding the Python GIL
with ThreadPoolExecutor(max_workers=4) as workers:
workers.submit(audio_io.save_prepared, "vocals.wav", prepared, 44100, encoding="pcm16")
5. Fast Metadata Inspection
Read container metadata in microseconds without reading or decoding sample frames:
meta = audio_io.info("speech.wav")
print(meta.duration, meta.sample_rate, meta.channels, meta.subtype)
API Overview
| Function / Class | Description | Documentation |
|---|---|---|
load |
Decode audio file to mx.array with optional resampling, slicing, and mono mix |
Details |
save |
Write mx.array or buffer-compatible array to WAV, MP3, M4A, FLAC, AIFF |
Details |
prepare_save |
Stage evaluated buffer view on producer for concurrent export threads | Details |
save_prepared |
File encoder for background worker threads (releases the GIL while encoding) | Details |
PreparedAudio |
Read-only audio buffer wrapper preserving strides and memory layout | Details |
stream |
Generator yielding fixed-frame or fixed-duration mx.array chunks |
Details |
info |
Fast header inspection returning AudioInfo (frames, duration, channels) |
Details |
batch_load |
Multi-threaded multi-file audio decoding into a list of mx.array |
Details |
supports_soxr |
Check whether high-quality libsoxr resampling support is enabled |
Details |
For complete signatures and parameter contracts, see the Full API Reference.
Platform Backends
| Capability | macOS Backend | Linux Backend |
|---|---|---|
| Engine | Apple AudioToolbox | Native C++ WAV/MP3 + libav (FFmpeg) |
| Supported Formats | WAV, MP3, M4A/AAC, FLAC, AIFF, CAF | WAV, MP3, FLAC, M4A/AAC, AIFF, CAF |
| Encodings | float32, pcm16, alac (lossless M4A) |
float32, pcm16, alac (lossless M4A) |
| Resampling | AudioToolbox (best) / libsoxr (soxr_vhq) |
Native linear / libav / libsoxr |
| Streaming | Full chunked streaming across all formats | Full chunked streaming across all formats |
Performance Highlights
Measured on Apple M4 Max (macOS 27.0) on a 194.8-second stereo 44.1 kHz PCM16 WAV track (median p50 latency):
| Operation | macOS M4 Max | vs librosa / soundfile | vs torchaudio |
|---|---|---|---|
| Full WAV Load | 3.74 ms | 6.8x faster than librosa | 9.2x faster |
| WAV Partial Read (1s) | 0.05 ms | 3.4x faster than librosa | 708x faster |
| MP3 Load (native SR) | 37.88 ms | 1.1x faster than librosa | 1.9x faster |
| WAV Save (Float32) | 14.07 ms | 1.5x faster than SoundFile | 1.5x faster |
Save Prepared (save_prepared) |
13.77 ms | 1.5x faster than SoundFile | 1.6x faster |
Load + Resample (16 kHz, fastest) |
10.76 ms | 5.6x faster than librosa | 5.0x faster |
Load + Resample (16 kHz, best) |
33.17 ms | 1.8x faster than librosa | 1.6x faster |
For complete benchmarking methodology, Linux arm64/x86_64 numbers, and tail latency profiles, see Benchmarking & Performance.
Documentation
- 📖 API Reference — Comprehensive signatures, parameters, and return types for all functions.
- ⚡ Benchmarking & Performance — Detailed latency tables, methodology, and cross-framework comparisons.
- 🛠️ Installation, Builds & Troubleshooting — Linux libav dependencies, wheel repair, Docker workflows, and diagnostic tools.
License
MIT
Metadata
Release files for mlx-audio-io 1.3.24
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mlx_audio_io-1.3.24.tar.gz | 362.8 kB | Details |
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| mlx_audio_io-1.3.24-cp314-cp314-macosx_14_0_arm64.whl | CPython 3.14 | CPython 3.14 | macOS 14.0+ ARM64 | Details |
| mlx_audio_io-1.3.24-cp313-cp313-macosx_14_0_arm64.whl | CPython 3.13 | CPython 3.13 | macOS 14.0+ ARM64 | Details |
| mlx_audio_io-1.3.24-cp312-cp312-macosx_14_0_arm64.whl | CPython 3.12 | CPython 3.12 | macOS 14.0+ ARM64 | Details |
| mlx_audio_io-1.3.24-cp311-cp311-macosx_14_0_arm64.whl | CPython 3.11 | CPython 3.11 | macOS 14.0+ ARM64 | Details |
| mlx_audio_io-1.3.24-cp310-cp310-macosx_14_0_arm64.whl | CPython 3.10 | CPython 3.10 | macOS 14.0+ ARM64 | Details |
Total release size: 2.1 MB
Release files / mlx_audio_io-1.3.24.tar.gz
| Download URL | mlx_audio_io-1.3.24.tar.gz |
|---|---|
| Size | 362.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e7404707d090be8ea218b0b7de6ec90ea382e05be86f56e742c3cfd005a38ee1
|
|
BLAKE2b-256 checksum How to use checksums |
3612c338f0e83d3827650a746a211d2e7e0012789164419e0010affcf02cc128
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / mlx_audio_io-1.3.24-cp314-cp314-macosx_14_0_arm64.whl
| Download URL | mlx_audio_io-1.3.24-cp314-cp314-macosx_14_0_arm64.whl |
|---|---|
| Size | 345.0 kB |
| Tags | CPython 3.14 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e0e01c809ec3c8577cb2c109ef3b5d5dc067073dbc570b73d4a2892910971555
|
|
BLAKE2b-256 checksum How to use checksums |
4e2cb4e62457dcc6bdcc1f88bca136593a35c7b7b69952baeb0d51e137c0566a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / mlx_audio_io-1.3.24-cp313-cp313-macosx_14_0_arm64.whl
| Download URL | mlx_audio_io-1.3.24-cp313-cp313-macosx_14_0_arm64.whl |
|---|---|
| Size | 344.9 kB |
| Tags | CPython 3.13 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
754bedf1b033c0e1973df68634bec996675c189528fc35e1c4bbf9acf2ff6e95
|
|
BLAKE2b-256 checksum How to use checksums |
0dfc00b5c2de7f90d9c21356b41d5adec3b4f86dfe34725f3b090d446d0b578c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / mlx_audio_io-1.3.24-cp312-cp312-macosx_14_0_arm64.whl
| Download URL | mlx_audio_io-1.3.24-cp312-cp312-macosx_14_0_arm64.whl |
|---|---|
| Size | 344.8 kB |
| Tags | CPython 3.12 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
8009f6d70b94edc9679017a182025897eeb70eb81dd8e46bb89826cd9eba94c1
|
|
BLAKE2b-256 checksum How to use checksums |
14ba6b1f7790f403b97e6b3f52d1875b8e8fa0ac9abe2ae08cc67fd21d755b11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / mlx_audio_io-1.3.24-cp311-cp311-macosx_14_0_arm64.whl
| Download URL | mlx_audio_io-1.3.24-cp311-cp311-macosx_14_0_arm64.whl |
|---|---|
| Size | 345.7 kB |
| Tags | CPython 3.11 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e6c58d3a773aff4baf6ea6730ed23fca1268af7a4842a1e8035679474fe9852f
|
|
BLAKE2b-256 checksum How to use checksums |
0e91c2cf789bd8e60638714a8bad5bc02b842cb8ae3c11619e9c7bba57147bb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency logRelease files / mlx_audio_io-1.3.24-cp310-cp310-macosx_14_0_arm64.whl
| Download URL | mlx_audio_io-1.3.24-cp310-cp310-macosx_14_0_arm64.whl |
|---|---|
| Size | 345.9 kB |
| Tags | CPython 3.10 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
0319ff802929dabd9fc7e094b71ae7e328691953ee6fe7f554e27955bda452ee
|
|
BLAKE2b-256 checksum How to use checksums |
23ae1796987c6d3fcd512b6af51bc4d32335b576ae4173c48e09c8419a958979
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 5, 2026.
Transparency log