Python PyAudio IOError:没有可用的默认输入设备
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4672155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PyAudio IOError: No Default Input Device Available
提问by Gus
I'm using PyAudio under the Enthought Python Distribution (Python 2.6.6) in Ubuntu 10.10 x64.
我在 Ubuntu 10.10 x64 的 Enthought Python Distribution (Python 2.6.6) 下使用 PyAudio。
>>> import pyaudio
>>> pa = pyaudio.PyAudio()
>>> pa.get_default_input_device_info()
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
pa.get_default_input_device_info()
File "/usr/lib/python_epd/lib/python2.6/site-packages/pyaudio.py", line 936, in get_default_input_device_info
device_index = pa.get_default_input_device()
IOError: No Default Input Device Available
This is the same error I get if I try to open an input stream. There is the corresponding error "IOError: No Default Output Device Available"
如果我尝试打开输入流,这与我得到的错误相同。有对应的错误“IOError: No Default Output Device Available”
采纳答案by DrSAR
OK, here is a solution that isn't pretty but works for me. As per my comment to ulidtko's answer, pyaudio is not the problem but rather the underlying PortAudio that pyaudio is supposed to bind to.
好的,这是一个不漂亮但对我有用的解决方案。根据我对 ulidtko 回答的评论,pyaudio 不是问题,而是 pyaudio 应该绑定到的底层 PortAudio。
On ubuntu the portaudio drivers are installed with this package:
在 ubuntu 上,portaudio 驱动程序随此软件包一起安装:
sudo apt-get install python-gnuradio-audio-portaudio
You must have this already, since you said your stock ubuntu runs your code fine (albeit with some debug messages that can be ignored)
你必须已经有了这个,因为你说你的股票 ubuntu 运行你的代码很好(尽管有一些可以忽略的调试消息)
If you query the location of your portaudio module you will find the following when you are running enthought's python:
如果您查询 portaudio 模块的位置,您会在运行 enthought 的 python 时发现以下内容:
>>> import pyaudio
>>> pyaudio.pa.__file__
'/opt/epd-7.2-2-rh5-x86_64/lib/python2.7/site-packages/_portaudio.so'
and the following on stock ubuntu:
以及以下股票 ubuntu:
In [1]: import pyaudio
In [2]: pyaudio.pa.__file__
Out[2]: '/usr/lib/pymodules/python2.7/_portaudio.so'
I moved the enthought _portaudio.so out of the way and replaced it with a link to the system _portaudio.so and now everything including the lovely spectrum analyzer in the chaco demo/advanced directory works:
我将 enthought _portaudio.so 移开,并用指向系统 _portaudio.so 的链接替换它,现在包括 chaco demo/advanced 目录中可爱的频谱分析仪在内的所有内容都可以正常工作:
cd /opt/epd-7.2-2-rh5-x86_64/lib/python2.7/site-packages/
mv _portaudio.so _portaudio.so.originalEPD
ln -s /usr/lib/pymodules/python2.7/_portaudio.so
回答by ulidtko
PyAudio provides Python bindings for PortAudio, the cross-platform audio I/O library.
PyAudio 为跨平台音频 I/O 库 PortAudio 提供 Python 绑定。
http://people.csail.mit.edu/hubert/pyaudio/
http://people.csail.mit.edu/hubert/pyaudio/
Did you install the PortAudio software? It is required fot the pyaudioto work.
您是否安装了 PortAudio 软件?它是pyaudio工作所必需的。
回答by archiboldian
I would recommend PYOfor audio I/O and synthesis, I found it really easy to pick up. Here's some code to illustrate how I would get PYO to get and output an audio input after processing it to change it's pitch:
我会推荐PYO用于音频 I/O 和合成,我发现它很容易上手。下面是一些代码来说明我如何让 PYO 在处理它以改变它的音高后获取和输出音频输入:
from pyo import *
serv = Server(duplex=1).boot()
serv.start()
shiftfreq = 329.63
# 329.63 is the frequency for the E note
mic = Input(chnl=0)
shift = FreqShift(mic, shift=shiftfreq, mul=.5).out()
serv.gui(locals())
PYO also lets you change frequencies and parameters of synthesis, generators or anything on the fly, which was the biggest draw for me because I use it mostly for programming live synthesiser instruments.
PYO 还可以让您即时更改合成器、发生器或任何东西的频率和参数,这对我来说是最大的吸引力,因为我主要使用它来对现场合成器乐器进行编程。
It also has a great manual...
它还有一本很棒的手册...
回答by Parthan
Check this https://github.com/shichao-an/soundmeter/issues/7
检查这个 https://github.com/shichao-an/soundmeter/issues/7
All you have to do is
install ALSA : sudo apt-get install libasound-dev
您所要做的就是安装 ALSA : sudo apt-get install libasound-dev
then build portaudio (this version pa_stable_v190600_20161030.tgz)
http://www.portaudio.com/download.html
然后构建portaudio(这个版本pa_stable_v190600_20161030.tgz)
http://www.portaudio.com/download.html
then Get root privileges (sudo su rootunder Ubuntu where plain su rootdoes not work.)
然后获取 root 权限(sudo su root在 Ubuntu 下,plainsu root不起作用。)
Place the portaudio archive in /usr/srcand unpack it with tar xvfz pa_snapshot.tgzThis will generate the directory /usr/src/portaudio.
将 portaudio 存档放入/usr/src并解压,tar xvfz pa_snapshot.tgz这将生成目录/usr/src/portaudio。
Descend into this directory and execute these commands:
下降到这个目录并执行这些命令:
./configure
make
make install
ldconfig
The linradconfigure script has to be run after the successful installation of portaudio to make Linrad aware of the fact that portaudio is available.
该linrad配置脚本已成功安装portaudio使Linrad知道的事实,portaudio可用的后运行。
Make sure you get ALSA as yes in the ./configurefile
确保./configure文件中的ALSA 为 yes
Target ...................... x86_64-unknown-linux-gnu
C++ bindings ................ no
Debug output ................ no
ALSA ........................ yes
ASIHPI ...................... no
OSS ......................... yes
Hyman ........................ no "
Install the latest version of pyaudio(PyAudio-0.2.11.tar.gz)
安装最新版本的pyaudio( PyAudio-0.2.11.tar.gz)
回答by shantanu pathak
Installing pyaudio from following source worked for me
从以下来源安装 pyaudio 对我有用
conda install nwani::portaudio nwani::pyaudio
reference : Answer of Mamun Or Rashid for question... OSError: No Default Input Device Available
参考:Mamun 或 Rashid 的回答问题... OSError:没有可用的默认输入设备

