Skip to main content

🎵 sound_rs

sound_rs is a fast, Rust-powered audio playback library for Python that I built and maintain — decoding with symphonia, output through cpal, so the same code runs on macOS, Windows and Linux.


🚀 Features

  • Formats: WAV, MP3, FLAC, OGG/Vorbis, M4A, AAC — any bit depth, including 24-bit
  • NumPy arrays: play 1D mono (samples,) or 2D (channels, samples) float32 arrays
  • Resampling: linear interpolation to the device rate, channel folding to the device layout
  • Device-native output: the stream is opened in whatever sample format the device wants (f32, i16, u16, ...)
  • Non-blocking for others: playback blocks the calling thread but releases the GIL, so other Python threads keep running
  • Tone generator: play_sine_wave(440, 2.0, 44100)

🧠 Installation

pip install sound_rs

💻 Usage

Playback

import sound_rs

sound_rs.play_audio("sound.wav")
sound_rs.play_audio("sound.mp3")
sound_rs.play_audio("sound.flac")
sound_rs.play_audio("sound.m4a")

Inspect a file

sample_rate, channels, duration = sound_rs.get_audio_info("sound.mp3")
sound_rs.is_supported_format("sound.mp3")  # probes the header, does not decode

From a NumPy array

import numpy as np
import sound_rs

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

Background playback

import threading

threading.Thread(target=sound_rs.play_audio, args=("long.mp3",)).start()

Tone generator

sound_rs.play_sine_wave(440.0, 1.0, 44100)  # frequency, duration, sample rate

🧩 Benchmark

play_audio is synchronous, so its wall-clock time is dominated by the track's own duration. The interesting numbers are decode throughput and overhead (wall clock − audio duration).

python examples/benchmark.py                        # generated 3s tone: decode + playback
python examples/benchmark.py --compare              # + sounddevice / soundfile
python examples/benchmark.py --files a.mp3 b.flac   # decode table for real files

Hardware and setup I measured on: Apple M5 Pro, macOS 26.6.2, Python 3.14.7, release build (lto = "fat", opt-level = 3), 60 s of 44.1 kHz stereo, best of 5 runs, competitor is libsndfile (soundfile 0.14).

format size sound_rs soundfile result
WAV (PCM 16) 10.6 MB 5.6 ms 7.1 ms 1.3× faster
FLAC 0.7 MB 10.2 ms 26.1 ms 2.6× faster
MP3 1.0 MB 19.6 ms 16.1 ms 1.2× slower
M4A (AAC) 1.0 MB 22.1 ms unsupported sound_rs only

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

wall clock overhead
sound_rs 3.240 s +0.239 s
sounddevice 3.234 s +0.234 s

Both pay the same cost: opening and closing the audio stream on every call. I want to be straight about the weak spots too: my MP3 decoding is ~20% behind libmpg123, and on uncompressed WAV there is no real race to win — both sides are a memcpy. The playback overhead is the number I intend to fix with a persistent stream, which should bring it down to single-digit milliseconds.


🛠️ Roadmap

Step Feature Description
✅ 1 WAV playback Core playback
✅ 2 MP3, FLAC, M4A, AAC, 24-bit Full symphonia decode path
✅ 3 NumPy integration 1D/2D float32 arrays
🔜 4 Player object Persistent stream: pause, resume, seek, volume, position
🔜 5 Device selection list_devices(), choose input/output
🔜 6 Recording Microphone → array or WAV
🔜 7 Decode to array load(path) -> (ndarray, sample_rate) without playing

🧪 Development

cargo test                      # resampler and channel conversion
maturin develop --release       # build the extension into your venv
python tests/smoke.py           # end-to-end decode checks
SOUND_RS_PLAY=1 python tests/smoke.py   # also plays (needs an audio device)
python examples/benchmark.py

⚙️ Built With

  • 🦀 Rust — performance and safety
  • 🔗 PyO3 — Python bridge
  • 🧰 Maturin — building and publishing
  • 🔊 cpal + symphonia — audio backend and decoders

👨‍💻 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.1.7

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.1.7
File Size Uploaded Provenance Actions
sound_rs-0.1.7.tar.gz 22.7 kB Without provenance Details for sound_rs-0.1.7.tar.gz

Built distributions (wheels)

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

Total release size: 13.7 MB

Release files / sound_rs-0.1.7.tar.gz

Download URL sound_rs-0.1.7.tar.gz
Size 22.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4d4d6a36fb86efab2163baf5e1532e03686544f66c2f58f953429fb60f445187
BLAKE2b-256 checksum
How to use checksums
490359aabc104473ff8c4d8f710918177fe0801e74793dea6c5ea269a087511e
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.1.7-cp314-cp314-win_amd64.whl

Download URL sound_rs-0.1.7-cp314-cp314-win_amd64.whl
Size 741.1 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
81d080f2067f02919966d8c5c386a691e8ab8fc32355a1c18a5173d6f745f952
BLAKE2b-256 checksum
How to use checksums
b1aa84aceec8dc25a8d7dfa39e91cc4561a2698223d39544f4703bb7d5cabc41
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.1.7-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.1.7-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.14 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
b524627cf2a0f84aa92cef761a9aecc8f838e3f490d71af611f27f4dc3637e98
BLAKE2b-256 checksum
How to use checksums
a8e30e922a9fd041b51c1d04964f27725e658fb3c6baaf829524e11545370782
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.1.7-cp314-cp314-macosx_11_0_arm64.whl

Download URL sound_rs-0.1.7-cp314-cp314-macosx_11_0_arm64.whl
Size 744.1 kB
Tags CPython 3.14 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
cc3928955b3886821bcfecbe26a2fb893dc01118eecb6690ccbca9260977cc31
BLAKE2b-256 checksum
How to use checksums
68be0582ee0c78dc8df32b4a9e895bec3acf2bfe2e5cd78eaa3320e560382d10
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.1.7-cp313-cp313-win_amd64.whl

Download URL sound_rs-0.1.7-cp313-cp313-win_amd64.whl
Size 741.1 kB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
bc90d0ea63da5a264d5374227bb24b6e334b0d1988960e6a37cf1da40da42ee2
BLAKE2b-256 checksum
How to use checksums
8dc770f36839e3aeacf2d40b6728bdf1d9cbe6b715d8d02d494408138d6f0b7b
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.1.7-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.1.7-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.13 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
feaed7f954d5d4d784670575c8937f5297126fb27c20ba8b7c8247d7a8fe6014
BLAKE2b-256 checksum
How to use checksums
5a9050e4d5fa3dc6c6217c3f3c60a10568b33f5f444a2682d2f1d6d0e42f09d6
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.1.7-cp313-cp313-macosx_11_0_arm64.whl

Download URL sound_rs-0.1.7-cp313-cp313-macosx_11_0_arm64.whl
Size 744.2 kB
Tags CPython 3.13 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3fc34ca9aa3a83e24b6508310223d4ceca9348fc5e2fc8def43a6fc5a11929fc
BLAKE2b-256 checksum
How to use checksums
ea448c4ab0e5875350828eb5fdc5b8898c3dca4ad3588660de96cee9b04d3811
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.1.7-cp312-cp312-win_amd64.whl

Download URL sound_rs-0.1.7-cp312-cp312-win_amd64.whl
Size 741.3 kB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
98c15dbf9b05e24c6e51112ee316de48fcebb8f945a9e6e47c0edcdaf5243314
BLAKE2b-256 checksum
How to use checksums
09e170ce970a1b16ec19363257588182962b73de2164d69ff48b957c5c6772a8
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.1.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.1.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.12 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
9d2183b3354a4a9f8dc40d8c993d842a3201cde7af2ac6168fc951e65e4ab5fb
BLAKE2b-256 checksum
How to use checksums
a5ab9d906de03fc93ac94056a29f2e4aa5c4ec4843da706cf6e7c12be799eede
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.1.7-cp312-cp312-macosx_11_0_arm64.whl

Download URL sound_rs-0.1.7-cp312-cp312-macosx_11_0_arm64.whl
Size 744.2 kB
Tags CPython 3.12 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
783a413b41e7a0afe812c52b0296264f89e9b8227984fd60b730aedb7654d475
BLAKE2b-256 checksum
How to use checksums
e830e43ffa1d969dd29192a49207d9815b254836a9a99347d0de9e171046dc9b
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.1.7-cp311-cp311-win_amd64.whl

Download URL sound_rs-0.1.7-cp311-cp311-win_amd64.whl
Size 740.8 kB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
2634ca615016ecb8e6e79ed59e0d2b92326c36360de0c47ac890019def4797c8
BLAKE2b-256 checksum
How to use checksums
274f16902fc50c9104aa234ed5554a8e0e53a657242ed3c79531e855eeb73e26
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.1.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.1.7-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
c387dd481f07f29a748d7e242a819084d6028fd63fd44770f52962136d4ea448
BLAKE2b-256 checksum
How to use checksums
515873ce88ae4d671ca68d505de3bdb8d72fd084c1caf4bb2cf98a66cab5d0b0
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.1.7-cp311-cp311-macosx_11_0_arm64.whl

Download URL sound_rs-0.1.7-cp311-cp311-macosx_11_0_arm64.whl
Size 744.4 kB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
e442d6a8a882386dd9355443a86334c8a2212f36ccb82252cb08288dafb03874
BLAKE2b-256 checksum
How to use checksums
fb58be9e6ec550516cbcfa4f893afc1424431b588f3331c86e00423c310b56a9
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.1.7-cp310-cp310-win_amd64.whl

Download URL sound_rs-0.1.7-cp310-cp310-win_amd64.whl
Size 740.9 kB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
89cf30d74b17abddcfd825f8d54d0ef92bfc99475175cf963247874f77d9c227
BLAKE2b-256 checksum
How to use checksums
f13ab83947f608dd46a540d695c577b1a841f720048fc376dc34bf45d40ced76
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.1.7-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL sound_rs-0.1.7-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 1.3 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64
SHA-256 checksum
How to use checksums
5a006ab32eda3f935696f07565b1083f45adbed9adfed82c6e28bbb2378be393
BLAKE2b-256 checksum
How to use checksums
06170312c70db793bc55d60a39ddf93b3b1da9a02fc4c8d2d1b04d6077e3fae4
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.1.7-cp310-cp310-macosx_11_0_arm64.whl

Download URL sound_rs-0.1.7-cp310-cp310-macosx_11_0_arm64.whl
Size 744.5 kB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
ed4da84b9d5a669e52fc4456f4211fb893fb7e53a424a493bad53affdfa02687
BLAKE2b-256 checksum
How to use checksums
eaf1c3b835097436fd65f19e176157b320cda59a7e304e0587310035fc4cf485
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.1.7

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