Linux, musical road-dogging, and daily life by Paul W. Frields
 
SWIG, Python, and PulseAudio.

SWIG, Python, and PulseAudio.

OK, we seriously need someone who knows SWIG to put together PulseAudio bindings for Python. I’ve worked on some ctypes style wrappers, and they are not only not fun, but I suspect that I am Doing It Wrong, or in a non-Pythonic way. And I know that Lennart Poettering, the chief PulseAudio author, writes his code in a very consistent manner, which if I understand correctly makes a potential SWIG wielder’s job much easier.

It’s about time we exposed the power of PulseAudio to a new generation of Python folks (and got them to quit using python-alsaaudio when it’s really unnecessary and sometimes non-optimal).

6 Comments

  1. Dave Malcolm

    //cython.org/ has some details; it’s in Fedora. It’s the successor to Pyrex, which I’ve had success with in the past. One nice thing about Cython is that the binding C code that it generates will work with both Python 2 and Python 3 (with a recompile). Swig tries to generate bindings for all languages at once IIRC, whereas Cython is relatively simple.

    1. @Dave: Wow, “simple” is relative I guess. For the SWIG stuff I did already, I was lucky to have someone’s previous work to use as a template and learning aid. Apparently there’s automated generators out there for doing this stuff but it depends on GCC-XML which doesn’t appear to be available in Fedora (and possibly not timely maintained).

  2. Mads

    Why create python bindings for PulseAudio? What should it be used for?

    I like PulseAudio and love Python, but PulseAudio is low-level and with real-time constraints, and Python is high-level and sufficiently fast for most purposes, but definitely not suitable for real-time operations.

    Quoting //0pointer.de/blog/projects/guide-to-sound-apis.html:

    Q: I want to write a media-player-like application!

    A: Use GStreamer!

    Q: I want to add event sounds to my application!

    A: Use libcanberra, install your sound files according to the XDG Sound Theming/Naming Specifications!

    1. @Mads: The specific case use here is to get human names for sound devices that PulseAudio knows about, and also to be able to show a level meter for a specific device to which signal is routed. GStreamer, as far as I know, doesn’t provide either of those functions, and I’m pretty sure libcanberra has nothing to do with them either. I absolutely agree that Python isn’t really suitable for real-time, but that’s not required here — what is required is access to some of the information that PulseAudio is capable of producing.

      In the case above, I’m working on a multi-function *cast recorder, and for better usability it would be good to show users the level at which a specific device is operating, so it’s easy for a user to select (or even have the app auto-select) the sink and source monitor devices she and her interviewee are using. I need to do at least two things: 1. Get a list of currently available devices, with human readable names. 2. Implement a GtkProgressBar “VU meter” that helps the user select the right inputs while testing a microphone, VoIP link, or other sound source.

Comments are closed.