Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 ?

like image 344
Basj Avatar asked Dec 24 '13 12:12

Basj


People also ask

Do you need PortAudio with PyAudio?

Install PortAudio. This is required by the PyAudio library to stream audio from your computer's microphone.

Which blocks until all the given frames have been played in PyAudio?

Stream. read() blocks until all the given/requested frames have been played/recorded.

What is PyAudio module in Python?

PyAudio is a python module that allows you to use python to play, record, and create audio data from inputs and outputs.


2 Answers

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()
like image 102
Matthias Avatar answered Sep 20 '22 11:09

Matthias


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.

like image 24
Ross Bencina Avatar answered Sep 19 '22 11:09

Ross Bencina