Skip to main content

🎵 sound_rs

PyPI Downloads Python Platforms Typed Docs License

sound_rs is a fast, Rust-powered audio library for Python that I built and maintain — decoding with symphonia (plus minimp3 for MP3), resampling with rubato, output through cpal.

Documentation: neksand.github.io/sound_rs — guides, API reference, the soundrs command and the benchmark methodology.


🚀 Features

  • Formats: WAV, MP3, FLAC, OGG/Vorbis, M4A, AAC — any bit depth, including 24-bit
  • Streaming playback: a two-hour file costs ~4 MB of RAM, not gigabytes, and the first sound arrives in ~9 ms instead of after the whole decode
  • Player: one output stream stays open — play, pause, resume, seek, stop, volume, position, duration
  • Decode to NumPy: load(path) -> (ndarray, sample_rate), shape (frames, channels)
  • Parallel decode: load_many(paths) uses every core, with the GIL released
  • Gapless (MP3, OGG, AAC/MP4): encoder delay and padding are trimmed, so decoded audio lines up with the original
  • Fast metadata: get_audio_info reads the container header, ~1 ms regardless of file length
  • Resampling: rubato's FFT resampler with a proper anti-aliasing filter
  • Device-native output: the stream opens in whatever sample format the device wants (f32, f64, i16, i32, u8, u16)
  • Errors: everything raises sound_rs.SoundRsError (a RuntimeError subclass)
  • No ffmpeg, no system libraries: MP3, FLAC, OGG, AAC and WAV are decoded inside the wheel; pip install sound_rs needs nothing else
  • Typed: ships sound_rs.pyi and py.typed, so editors autocomplete everything

🧠 Installation

pip install sound_rs

Wheels are built for Linux (x86_64), Windows (amd64) and macOS (arm64) for Python 3.10–3.14. Other platforms build from source.


⌨️ Command line

Installing the package also installs soundrs, so you can check the setup and read the docs without opening Python:

soundrs --help       # commands and the documentation link
soundrs devices      # output devices, default marked with *
soundrs info a.flac  # rate, channels, duration from the header
soundrs play a.flac --volume 0.5
soundrs docs         # prints https://neksand.github.io/sound_rs/

Exit codes: 0 success, 1 runtime failure, 2 bad usage.

💻 Usage

One-shot playback

import sound_rs

sound_rs.play_audio("sound.wav")          # blocks, GIL released
sound_rs.play_audio("sound.mp3", device="MacBook Pro Speakers")

The player

import sound_rs

with sound_rs.Player() as player:
    player.play_file("music.flac")   # returns immediately, streams from disk
    player.volume = 0.7
    player.seek(42.0)
    player.pause()
    player.resume()
    print(player.position, player.duration)
    player.wait()                    # block until it ends

sound_rs.list_devices()              # [(0, "MacBook Pro Speakers", True), ...]

Inspect and decode

sample_rate, channels, duration = sound_rs.get_audio_info("music.mp3")  # no decode
audio, rate = sound_rs.load("music.flac")                               # (frames, channels) float32

pairs = sound_rs.load_many(["a.flac", "b.flac", "c.flac"])              # parallel

From a NumPy array

import numpy as np

rate = 44100
t = np.linspace(0, 2.0, rate * 2, endpoint=False, dtype=np.float32)
sound_rs.play_array(np.sin(2 * np.pi * 440 * t), rate)   # mono, 1D
sound_rs.play_array(np.stack([left, right]), rate)       # 2D, channels first
sound_rs.play_sine_wave(440.0, 1.0, 44100)

🧩 Benchmark

Every measurement runs in its own process: peak RSS is process-wide, so timing and memory cannot share one. Median and p95 over repeated runs, competitors run side by side on the same files.

python bench/run.py                 # sound_rs only
python bench/run.py --compare       # + soundfile / sounddevice
python bench/run.py --reps 9

Hardware I measured on: Apple M5 Pro, macOS 26.6.2, Python 3.14.7, release build (lto = "fat", opt-level = 3). Competitors: libsndfile 1.2 (soundfile 0.14), PortAudio (sounddevice). Corpus: 3 s and 10 min stereo 44.1 kHz, generated by the harness.

Scoreboard — every axis in this section, side by side:

axis sound_rs best competitor ratio
import 1.1 ms 31.8 ms (soundfile) 29×
metadata (60 s file) 1.2 ms 31.7 ms (soundfile) 26×
decode WAV 131 ms 155 ms 1.2×
decode FLAC 265 ms 465 ms 1.8×
decode MP3 247 ms 272 ms 1.1×
decode AAC 361 ms not supported —
time to first sound (10 min) 8.8 ms 492 ms 56×
peak RAM (10 min file) 43 MB 255 MB 6×
playback overhead 32 ms 148 ms 4.6×
batch decode (2 files) 272 ms 448 ms 1.6×

Import time (cold process):

time peak RSS
sound_rs 1.1 ms 25 MB
soundfile 31.8 ms 34 MB
sounddevice 75.3 ms 32 MB

Metadata (60 s file): sound_rs 1.2 ms, soundfile 31.7 ms.

Decode 60 s stereo, median / p95:

format sound_rs libsndfile result PCM check
WAV 131 / 160 ms 155 ms 1.2× faster identical
FLAC 265 / 267 ms 465 ms 1.8× faster identical
MP3 247 / 249 ms 272 ms 1.1× faster 1.6e-05, 47-sample offset
M4A (AAC) 361 / 365 ms unsupported sound_rs only matches ffmpeg to 8e-08

Streaming a 10-minute FLAC — time to the first sound and peak memory:

first sound peak RSS
sound_rs Player 8.8 ms 43 MB
soundfile + sounddevice 492 ms 255 MB

Playback of a 3 s tone — overhead over the track duration:

overhead
sound_rs Player (stream kept open) +32 ms
sounddevice.play (opens a stream per call) +148 ms
sound_rs.play_array (one-shot, opens a stream) +182 ms

Batch decode two FLAC files: load_many 272 ms vs a soundfile loop 448 ms.

What the numbers do not hide:

  • MP3 output is offset by 47 samples (~1 ms) versus libsndfile and ffmpeg. Sample values agree to 1.6e-05 once aligned; the offset comes from how the decoder delay is trimmed, and the length matches exactly.
  • WAV decode is a memcpy race with libsndfile; the gap there is small by nature, the real wins are FLAC, metadata, memory and latency.
  • AAC decoding is slower than everything else — it is a newer, less tuned decoder — but libsndfile cannot read AAC at all.

🛠️ Roadmap

Step Feature Description
✅ 1 Playback + formats WAV, MP3, FLAC, OGG, M4A, 24-bit
✅ 2 NumPy integration 1D/2D arrays, load, load_many
✅ 3 Player Persistent stream: pause, seek, volume, position
✅ 4 Streaming decode Constant memory, ~9 ms to first sound
🔜 5 Device selection UI Input devices, hot-swap on disconnect
🔜 6 Recording Microphone to array or WAV
🔜 7 Effects Basic gain/fade/mix utilities

🧪 Development

cargo test                      # resampler, channel conversion, gapless, seek
maturin develop --release       # build into your venv
python tests/smoke.py           # end-to-end decode + API checks
SOUND_RS_PLAY=1 python tests/smoke.py   # also plays (needs an audio device)
python bench/run.py --compare   # full benchmark
python3 docs/_build.py          # rebuild the documentation site

⚙️ Built With

  • 🦀 Rust — performance and safety
  • 🔗 PyO3 — Python bridge
  • 🧰 Maturin — building and publishing
  • 🔊 cpal, symphonia, minimp3, rubato — output, decoding, resampling

👨‍💻 Author

Nurassyl Mussainov Kazakhstan 🇰🇿 Python / Rust Developer

🔗 GitHub: Neksand 📦 PyPI: sound_rs


📜 License

Licensed under the MIT License — free for personal and commercial use.

Metadata

Release files for sound-rs 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sound-rs 0.2.2
File Size Uploaded Provenance Actions
sound_rs-0.2.2.tar.gz 102.9 kB Without provenance Details for sound_rs-0.2.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for sound-rs 0.2.2
File Actions
sound_rs-0.2.2-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for sound_rs-0.2.2-cp314-cp314-win_amd64.whl
sound_rs-0.2.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.14 CPython 3.14 Linux glibc 2.17+ x86-64 Details for sound_rs-0.2.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.2-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for sound_rs-0.2.2-cp314-cp314-macosx_11_0_arm64.whl
sound_rs-0.2.2-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for sound_rs-0.2.2-cp313-cp313-win_amd64.whl
sound_rs-0.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.17+ x86-64 Details for sound_rs-0.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.2-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for sound_rs-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
sound_rs-0.2.2-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for sound_rs-0.2.2-cp312-cp312-win_amd64.whl
sound_rs-0.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.17+ x86-64 Details for sound_rs-0.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.2-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for sound_rs-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
sound_rs-0.2.2-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for sound_rs-0.2.2-cp311-cp311-win_amd64.whl
sound_rs-0.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.17+ x86-64 Details for sound_rs-0.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.2-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for sound_rs-0.2.2-cp311-cp311-macosx_11_0_arm64.whl
sound_rs-0.2.2-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for sound_rs-0.2.2-cp310-cp310-win_amd64.whl
sound_rs-0.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.17+ x86-64 Details for sound_rs-0.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.2-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details for sound_rs-0.2.2-cp310-cp310-macosx_11_0_arm64.whl

Total release size: 21.8 MB

Release files / sound_rs-0.2.2.tar.gz

Download URL sound_rs-0.2.2.tar.gz
Size 102.9 kB
Tags Source
SHA-256 checksum
How to use checksums
a7f065bc322d973ee92038eae90d873b2aa41c3aff887e6302718682cc0ee44c
BLAKE2b-256 checksum
How to use checksums
87dece1e466116bc795948e33fac6b4e3389a0e7f1e37119ab7048c6193f3121
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp314-cp314-win_amd64.whl

Download URL sound_rs-0.2.2-cp314-cp314-win_amd64.whl
Size 1.4 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
288c6c3932bcb1262d4455db6050fa7c24a9c9d1500237cef85c759f5adb7fc8
BLAKE2b-256 checksum
How to use checksums
fb2a0d7c804d87074220fb28056d43b7e0bb3e352ce28ae4e881a99069b3cb06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.9 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
35f02fa3f4311f170993e893cbc3bf8f14c738fd174007ed72fa8029dd0a3397
BLAKE2b-256 checksum
How to use checksums
8736638ffa2799b09972a908d3f4948a3f5c352d96320129626f1df9aed4ba75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp314-cp314-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.2-cp314-cp314-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
198d5a302957248d48416b378a6d74fd095e06db5921f78bab7ae4d1ef321bc1
BLAKE2b-256 checksum
How to use checksums
b6ed27613313baea35ab6130b8334cf1dc62b3205d1b2b9481374638daa0b51d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp313-cp313-win_amd64.whl

Download URL sound_rs-0.2.2-cp313-cp313-win_amd64.whl
Size 1.4 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
519eba37693848af7b46ae73f43b0fa4f6743ad6c4ded2d4b564d32dd0932655
BLAKE2b-256 checksum
How to use checksums
8782f51e190f6b600ea583086599a33ace1348e7811b98e7ccc837e8b35fc0e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.9 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
077f4d146951b555759ade4af4f3fcc2c23334174008b1acf4082c53fd0b48e5
BLAKE2b-256 checksum
How to use checksums
ef841389de3164ee9a6f0c32670c8c06435a0e56e6febc74b71fb2d2bb4d673e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp313-cp313-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.2-cp313-cp313-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0ca16f5a532adbfe02ebd51ebb1e402c1ee6fbdcec4524f08ac7a9134cedbfcd
BLAKE2b-256 checksum
How to use checksums
ded9257add4baafd7158e538c3c5651b76090a2294bba9fce26962349bc02bcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp312-cp312-win_amd64.whl

Download URL sound_rs-0.2.2-cp312-cp312-win_amd64.whl
Size 1.4 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
599c4e1ea013af4d127374e17a8af8a3bc89a7f9ce4535effcdbd8eb2fde08bb
BLAKE2b-256 checksum
How to use checksums
7707fee4b4dbc40fe33bda7378bb18e4d6490cc9f16aea2dd439fd3037ffab50
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.9 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
4ff8fd2c029cf76b4f606906fa9f647a6198821ffb454a40b84e5452906bd000
BLAKE2b-256 checksum
How to use checksums
f42d3d1284e318d27ac007074d27f1c77bcea21d6243b31c6a4cf4624f5f87ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp312-cp312-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ebc1c9f5ec1d4a4b7fbe93f8696045ceb0ed8d2b2723c1070e74ecedea5f5e51
BLAKE2b-256 checksum
How to use checksums
deba5bb441722a03e0e58ebb77750c359d70fc045a4b233de5b02edd66d4b679
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp311-cp311-win_amd64.whl

Download URL sound_rs-0.2.2-cp311-cp311-win_amd64.whl
Size 1.4 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
a1fdcd46ff1ec80b0bbb9c2298824841676897bff37a418f5bf7cf05690a9fc5
BLAKE2b-256 checksum
How to use checksums
2a959d6849fd189209b9deec42530dc99ae4ee6c27a798a16d0a2bc54d85876a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.9 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
89eae23629f62ef9abc09b6bfdb924070f0224ff42d94271e1b5e07929717565
BLAKE2b-256 checksum
How to use checksums
88a7c72a8ee28bb55c3fae5c07b61fc4114eaae652583664184dd5394aa912f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp311-cp311-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.2-cp311-cp311-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
43e4d77004bc6f41da0b4763b1fc6c392bdc78d851c668f72f90169af6310861
BLAKE2b-256 checksum
How to use checksums
1fa68b142701ffa5c6f1f2dfc7ca1f982c1440bc2f1b191034029a4699773462
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp310-cp310-win_amd64.whl

Download URL sound_rs-0.2.2-cp310-cp310-win_amd64.whl
Size 1.4 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
02ca5d83983ed470aa013071cc3f30775524b19bf98e23cb32d3be43feb78e59
BLAKE2b-256 checksum
How to use checksums
63ca4dbed1ee67b6b47cec646247cbc035d03cec8a64371c9697db0ab3cff2a2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.2-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
ef9e88a077f9cd7d299f2dfe4b620198a530c4e8119f2db882b651ce04570073
BLAKE2b-256 checksum
How to use checksums
f95d9d4ed7dd064d46ef880a30e37879a04cc4fa1b94cfd4948a4b5a6f84c07f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / sound_rs-0.2.2-cp310-cp310-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.2-cp310-cp310-macosx_11_0_arm64.whl
Size 1.1 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ca940620e4adab40bee130d02adb8fd3b351720ac5fe2ff388dd038b2d66ff31
BLAKE2b-256 checksum
How to use checksums
127517d9b9284fc12466e25e8bc84f55c54cb49514e50c08047e26fffd88bcde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for sound-rs 0.2.2

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page