List all audio devices with Python's pyaudio (portaudio binding)

21,906

Solution 1

I've created (a while after this question was posted) the sounddevice module for Python, which includes its own DLLs with ASIO support (and all other host APIs, too). It can be installed with:

pip install sounddevice --user

After that, you can list all your devices with:

python -m sounddevice

Of course you can also do this within Python:

import sounddevice as sd
sd.query_devices()

Solution 2

I think your expectations are reasonable. The equivalent C code to enumerate PortAudio devices would give you all available devices. There are a couple of things that could be wrong:

  • Your build of PyAudio has not been compiled with ASIO support. PortAudio will only enumerate devices for the native host APIs that have been configured/compiled in at compile time.

  • You have a 64-bit build of Python/PyAudio and your ASIO device drivers are 32-bit, or vis-versa (64-bit ASIO drivers and 32-bit Python).

As Multimedia Mike suggests, you can eliminate PyAudio from the equation by enumerating PA devices from C. The pa_devs.c program in the PortAudio distribution does this.

Share:
21,906
Basj
Author by

Basj

I work on R&D involving Python, maths, machine learning, deep learning, data science, product design, and MacGyver solutions to complex problems. I love prototyping, building proofs-of-concept. For consulting/freelancing inquiries : [email protected]

Updated on July 15, 2022

Comments

  • Basj
    Basj almost 2 years

    I tried

    import pyaudio
    p = pyaudio.PyAudio()
    for i in range(p.get_device_count()):
        print p.get_device_info_by_index(i)
    

    but I don't get the full list of all devices : for example I don't get ASIO devices in this list. This is strange, because portaudio should give ASIO devices as well, right ?

    How can I list all audio devices with pyaudio ?

  • Basj
    Basj over 10 years
    I need to study this. I don't have a C compiler/linker installed (and those libraries neither) right now, and quite no knowledge about this... Would you have such tools @MultimediaMike ?
  • Ross Bencina
    Ross Bencina over 10 years
    The fact that PortAudio can't open streams to multiple ASIO devices simultaneously has no bearing on enumerating device info.
  • Basj
    Basj over 10 years
    Thank you for your answer. I spent hours and hours to try to compile PyAudio with ASIO support (thanks to the discussion github.com/bastibe/PyAudio/pull/4) but unfortunately I cannot finish the compile... If you have time to have a look at the procedure described here github.com/bastibe/PyAudio/pull/4 @RossBencina, thanks in advance!
  • JakeD
    JakeD about 7 years
    The sounddevice module also uses PortAudio which can find the correct device.
  • Chris P
    Chris P about 4 years
    python3.6 -m sounddevice (prints nothing)
  • Matthias
    Matthias about 4 years
    @ChrisP Please create an issue as described in python-sounddevice.readthedocs.io/en/latest/CONTRIBUTING.htm‌​l.