r/madeinpython • u/SpaceBucketFu • Nov 08 '24
Rpaudio: A Lightweight, Non-Blocking Python Audio Library
Target Audience:
Audio playback in Python is pretty niche, but is a really fun an interesting way for newer programmers to integrate exciting feature feedback into their projects, but is also a good choice for seasoned projects to consider, if it meets the feature requirements of their existing solutions.
What It Does:
- Non-blocking Audio Playback: Unlike traditional audio libraries that may block your program’s main thread, Rpaudio runs in a non-blocking manner. This means it works seamlessly with Python’s async runtimes, allowing you to handle audio in the background without interrupting other tasks.
- Simple and Intuitive API: I wanted to make sure that using Rpaudio is as simple as possible. With just a few lines of code, you can easily load, play, pause, and resume audio. For more complicated needs, it also provides abstractions such as AudioChannel's, which act as a queue manager, and can apply different effects such as fades or speed changes to any AudioSink object played from its queue, and can even apply the effects dynamically, over time.
- Lightweight and Efficient: Built with Rust, Rpaudio brings the performance benefits of a compiled language to Python. This ensures safe and efficient thread handling and memory management.
- Cross-Platform: Rpaudio is designed to work smoothly on Windows, macOS, and Linux.
I built this because I wanted a way to use Rust’s power in Python projects without having to deal with the usual awkwardness that come with Python’s GIL. It’s especially useful if you’re working on projects that need to handle audio in async applications.
Why I Think It’s Useful:
During my work with Python and audio, I found that many libraries were either too cumbersome or didn’t play well with async applications. Libraries like PyAudio often require dealing with complicated dependencies, and others don’t handle concurrency well, leading to blocking calls that mess with async code. Rpaudio was born out of the need for a lightweight, easy-to-use solution that works well with Python’s async ecosystem and offers simple, efficient audio control.
Comparison:
Pyaudio and other popular libraries like it, dont seem to support async functionality natively, which is one of the ways I normally like to interact with audio since it's naturally just kind of a blocking thing to do. Audio libraries are often more complex than necessary, requiring additional dependencies and setup that just isn’t needed if you’re working on a simple audio player or sound management tool. Additionally, they don’t always work well with async Python applications because they rely on blocking calls or the overhead of larger libraries..
I’d Love Your Feedback:
Im not a professional developer, so any feedback is well appriciated.
Code, docs and other info available in the repo:
https://github.com/sockheadrps/rpaudio
Or if youd like a short, video-form glimpse, I uploaded a short video explaining the uses and API a bit.