Skip to main content

🎵 sound_rs

PyPI Downloads Python Platforms Typed 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.


🚀 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.


💻 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

⚙️ 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.1

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.1
File Size Uploaded Provenance Actions
sound_rs-0.2.1.tar.gz 46.4 kB Without provenance Details for sound_rs-0.2.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for sound-rs 0.2.1
File Actions
sound_rs-0.2.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details for sound_rs-0.2.1-cp314-cp314-win_amd64.whl
sound_rs-0.2.1-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.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.1-cp314-cp314-macosx_11_0_arm64.whl CPython 3.14 CPython 3.14 macOS 11.0+ ARM64 Details for sound_rs-0.2.1-cp314-cp314-macosx_11_0_arm64.whl
sound_rs-0.2.1-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for sound_rs-0.2.1-cp313-cp313-win_amd64.whl
sound_rs-0.2.1-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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.1-cp313-cp313-macosx_11_0_arm64.whl CPython 3.13 CPython 3.13 macOS 11.0+ ARM64 Details for sound_rs-0.2.1-cp313-cp313-macosx_11_0_arm64.whl
sound_rs-0.2.1-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for sound_rs-0.2.1-cp312-cp312-win_amd64.whl
sound_rs-0.2.1-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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.1-cp312-cp312-macosx_11_0_arm64.whl CPython 3.12 CPython 3.12 macOS 11.0+ ARM64 Details for sound_rs-0.2.1-cp312-cp312-macosx_11_0_arm64.whl
sound_rs-0.2.1-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for sound_rs-0.2.1-cp311-cp311-win_amd64.whl
sound_rs-0.2.1-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.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.1-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details for sound_rs-0.2.1-cp311-cp311-macosx_11_0_arm64.whl
sound_rs-0.2.1-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for sound_rs-0.2.1-cp310-cp310-win_amd64.whl
sound_rs-0.2.1-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.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
sound_rs-0.2.1-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details for sound_rs-0.2.1-cp310-cp310-macosx_11_0_arm64.whl

Total release size: 21.2 MB

Release files / sound_rs-0.2.1.tar.gz

Download URL sound_rs-0.2.1.tar.gz
Size 46.4 kB
Tags Source
SHA-256 checksum
How to use checksums
36856f11317bd74b306fe7a326f48265d2a262ba6172f24be5566afead7c3d86
BLAKE2b-256 checksum
How to use checksums
e01b40391f9de925d24488482ae0b08b3724e89e839d0b8c224a30f4402c80b8
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.1-cp314-cp314-win_amd64.whl

Download URL sound_rs-0.2.1-cp314-cp314-win_amd64.whl
Size 1.3 MB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
f3fb03a10c0af2e2c27c5cb5b1306fa7f2384a96796bf96c414e912e942b6ab2
BLAKE2b-256 checksum
How to use checksums
fe371aac984bb4b1e8bbec9f597c73be42701c5acb46cedb4702e1464075cdb5
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.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.1-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.8 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
06c6ac0c0b8a445fd65d4ab88b4cd5efe08363bfbee4e6a2fd26ae8781c3af37
BLAKE2b-256 checksum
How to use checksums
1ba2b540505edec2142ec094a5852f87e21b68c53ea27adb20caea4ee210c652
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.1-cp314-cp314-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.1-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
7771018eeb3e9b1eaee16f732251f4e230a3cfedc33b4a757392360a3f5ca535
BLAKE2b-256 checksum
How to use checksums
f363a419be5c8525a339bbf6c1300b726ca53847a026aeb0bb6fdac05bfcb669
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.1-cp313-cp313-win_amd64.whl

Download URL sound_rs-0.2.1-cp313-cp313-win_amd64.whl
Size 1.3 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
e69af0a514305b679ff19e9ec18080ea6aa91a51a2aae2f0a60e5b7b6127f1ea
BLAKE2b-256 checksum
How to use checksums
d03713c071079c29e53c917b59a5c585821c37a20415639b9e3eadf667f2dd78
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.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.1-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.8 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
0a998c4beef489b6559f7f5fc55c1fddfcf813eaccfe44e5decaeda701d19b69
BLAKE2b-256 checksum
How to use checksums
88e3a261bff694d97d07cba03664e7c17710aac6a9eeb9b8f07c184ff7afe199
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.1-cp313-cp313-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.1-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
560cd3d639824812832fdd40bfe67908d464a237214f0fd0b7eec091f2496064
BLAKE2b-256 checksum
How to use checksums
9511da8220bc20307127a994f600f8a9b212dc1f85e7e6d18ac7640b8e07a34d
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.1-cp312-cp312-win_amd64.whl

Download URL sound_rs-0.2.1-cp312-cp312-win_amd64.whl
Size 1.3 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
b08dc04ab8bead7892f5289a9d627acc9dbf3ab66dffa7d1ef8da4bd12e3731a
BLAKE2b-256 checksum
How to use checksums
849d0bf85f4bebc5cacb71feb9498a03e2d99806e7794528176092ce86efd51b
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.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.1-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.8 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
47b314b3d5365f044f9db29c0479729972a8023e55d827168ff8a7805aeed02c
BLAKE2b-256 checksum
How to use checksums
64f391fd16fb971502f23f7d166a9f4b87232ee8cee8f63881742c12a4b48a77
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.1-cp312-cp312-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.1-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
5cc8fd574a5936980913557e7a5e6720bc878b4845d1541096c07e8723b56a61
BLAKE2b-256 checksum
How to use checksums
c61b5a040ae587c951563f7a9d9f3de7e57961ff7ca49d82d2997ff96c75bcf7
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.1-cp311-cp311-win_amd64.whl

Download URL sound_rs-0.2.1-cp311-cp311-win_amd64.whl
Size 1.3 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
4932165cc686825925e3074db610b7a834990283a6e99ebc6544b3c155dafa3e
BLAKE2b-256 checksum
How to use checksums
ebb39900ea459ba183b0e4abbf35915dc20e86dd3fadbadbe7862282073c0d49
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.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.1-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.8 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9813de0b80ffaab75647fec74697a1fa41f3aeabe141b64cbeb296a07b44773f
BLAKE2b-256 checksum
How to use checksums
82d8429ac6f32638291878f09d9d9576656d1ac4837638b72a04f0d0cb908302
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.1-cp311-cp311-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.1-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
b765b8b97261a39f427cbdf2da500d82b441b203ad74ae607fd8de2f3d4290ac
BLAKE2b-256 checksum
How to use checksums
84c785d26276ca0dd1c228f62bf9b6b8c07a23b448898f5bb503d51cc1da77c3
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.1-cp310-cp310-win_amd64.whl

Download URL sound_rs-0.2.1-cp310-cp310-win_amd64.whl
Size 1.3 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
6275a661d67994d8c6241a3068e4e88be54277bfdc995516d925177437de7846
BLAKE2b-256 checksum
How to use checksums
b664f61c31d6ee39f73a5106519952a1fb83d5f030285f0a065881b9445dc0a8
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.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.2.1-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
cf950b0d7e7c44ac8e1eda0c498497ab893e6aa35acf299fb7efe64eaa61e1ce
BLAKE2b-256 checksum
How to use checksums
fdcc03c65bfdd89e0d7e194bdd3e4661393c2f28c084ddfa2bd42674b5f6da2c
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.1-cp310-cp310-macosx_11_0_arm64.whl

Download URL sound_rs-0.2.1-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
dcc052e8e75796abf9d4e6f7d3e9552b1b234db593c98c93351410c70348cbdd
BLAKE2b-256 checksum
How to use checksums
9f442916bee78587fae38b3eda54eb8a14474532b64594f5dcee7f1c17ac37ca
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.1

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