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

徘徊边缘 提交于 2019-12-04 20:40:53

问题


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 ?


回答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()



回答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.




回答3:


I'm thinking that the problem could be in the underlying PortAudio library. Do you have (or can you write, in C) a simple utility that accesses the PortAudio library and tries to perform this same listing?

Also, googling for 'portaudio asio' reveals this tidbit from the official PortAudio docs:

There are cases where PortAudio is limited by the capabilities of the underlying native audio API... the ASIO SDK only allows one device to be open at a time, so PortAudio/ASIO doesn't currently support opening multiple ASIO devices simultaneously.



来源:https://stackoverflow.com/questions/20760589/list-all-audio-devices-with-pythons-pyaudio-portaudio-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!