我遇到 PyAudio 未检测到输入设备的问题

I have trouble with PyAudio does not detect input device

made 这个线程在 Raspberry PI Stack Exchange 中,我的问题已经解决了。直到上周我再次尝试 运行 我的 Python 应用程序(在 Raspbian 和 Ubuntu 16.04 中)这个错误再次出现。

OSError: [Errrno -9996] Invalid input device (no default output device)

到目前为止我做了什么。

ALSA lib pcm_hw.c:1700:(_snd_pcm_hw_open) Invalid value for card arecord: main:722: audio open error: No such file or directory

这并不是真正的答案,但打印 pyaudio 可用的所有设备列表并查看您的 USB 声卡是否被识别可能会有所帮助。

(之前项目的一些代码):

p = pyaudio.PyAudio()
for i in range(p.get_device_count()):#list all available audio devices
  dev = p.get_device_info_by_index(i)
  print((i,dev['name'],dev['maxInputChannels']))

您可能还想查看 alsa and some techniques to list available devices and possibly alsamixer

嗯,问题肯定出在 PyAudio 部分。然而,一些线程提到主要的罪魁祸首是 PyAudio 和 PortAudio 之间的连接错误(尽管我已经编译了正确的 PortAudio 版本 19 稳定)。

此时我的解决方案是使用https://github.com/larsimmisch/pyalsaaudio中的pyalsaaudio。对于 Python 2.x 你可以用 pip install pyalsaaudio 安装它,但是对于 Python 3.x 你需要从源代码编译它(参见它的说明 GitHub 页)。需要注意的是 pyalsaaudio 仅适用于 Linux。 pyalsaaudio 我的 Python 应用程序正常工作。