PyAudio IOError:没有可用的默认输入设备

发布于 2024-10-11 12:51:38 字数 617 浏览 8 评论 0原文

我在 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

如果我尝试打开输入流,这与我得到的错误相同。有相应的错误“IOError:没有可用的默认输出设备”

I'm using PyAudio under the Enthought Python Distribution (Python 2.6.6) in Ubuntu 10.10 x64.

>>> 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"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

笙痞 2024-10-18 12:51:38

好的,这是一个不太漂亮但对我有用的解决方案。
根据我对 ulidtko 的回答的评论, pyaudio 不是问题,而是 pyaudio 应该绑定到的底层 PortAudio 。

在 ubuntu 上,portaudio 驱动程序是用这个包安装的:

sudo apt-get install python-gnuradio-audio-portaudio

你必须已经有了这个,因为你说你的 ubuntu 可以很好地运行你的代码(尽管有一些可以忽略的调试消息)

如果你查询 portaudio 模块的位置,你会发现当您运行 enthought 的 python 时,会出现以下情况:

>>> import pyaudio
>>> pyaudio.pa.__file__
'/opt/epd-7.2-2-rh5-x86_64/lib/python2.7/site-packages/_portaudio.so'

以及在 ubuntu 上运行以下情况:

In [1]: import pyaudio
In [2]: pyaudio.pa.__file__
Out[2]: '/usr/lib/pymodules/python2.7/_portaudio.so'

我将 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

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.

On ubuntu the portaudio drivers are installed with this package:

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)

If you query the location of your portaudio module you will find the following when you are running enthought's 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:

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:

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
失去的东西太少 2024-10-18 12:51:38

我会推荐 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 还可以让您动态更改合成、生成器或任何其他内容的频率和参数,这对我来说是最大的吸引力因为我主要用它来编程现场合成器乐器。

它还有一个很棒的手册...

I would recommend PYO for 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:

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.

It also has a great manual...

双手揣兜 2024-10-18 12:51:38

最后这对我有用:

Build and install portaudio from soure code and install the latest version of pyaudio.

Then renamed libportaudio.so.2.0.0 to oldlibportaudio.so.2.0.0 in /usr/local/lib
and created a new soft link to the one in /usr/lib/x86_64-linux-gnu

sudo mv libportaudio.so.2.0.0 oldlibportaudio.so.2.0.0
sudo ln -s /usr/lib/x86_64-linux-gnu/libportaudio.so.2.0.0 libportaudio.so.2.0.0

在 Ubuntu 20.04 x64 上测试

Finally this work for me:

Build and install portaudio from soure code and install the latest version of pyaudio.

Then renamed libportaudio.so.2.0.0 to oldlibportaudio.so.2.0.0 in /usr/local/lib
and created a new soft link to the one in /usr/lib/x86_64-linux-gnu

sudo mv libportaudio.so.2.0.0 oldlibportaudio.so.2.0.0
sudo ln -s /usr/lib/x86_64-linux-gnu/libportaudio.so.2.0.0 libportaudio.so.2.0.0

tested on Ubuntu 20.04 x64

为人所爱 2024-10-18 12:51:38

PyAudio 为跨平台音频 I/O 库 PortAudio 提供 Python 绑定。

http://people.csail.mit.edu/hubert/pyaudio/

你有吗安装PortAudio软件? pyaudio 需要它才能工作。

PyAudio provides Python bindings for PortAudio, the cross-platform audio I/O library.

http://people.csail.mit.edu/hubert/pyaudio/

Did you install the PortAudio software? It is required fot the pyaudio to work.

江挽川 2024-10-18 12:51:38

检查这个
https://github.com/shichao-an/soundmeter/issues/7

你所要做的就是
安装 ALSA :sudo apt-get install libasound-dev

然后构建 portaudio(此版本pa_stable_v190600_20161030.tgz
http://www.portaudio.com/download.html

然后获取 root 权限 (sudo su root 在 Ubuntu 下,普通 su root 不起作用。)

将 portaudio 存档放在 /usr/src 中并使用 tar 解压xvfz pa_snapshot.tgz 这将生成目录 /usr/src/portaudio

进入该目录并执行以下命令:

./configure

make

make install

ldconfig

成功安装 portaudio 后,必须运行 linrad 配置脚本,以使 Linrad 知道 portaudio 可用。

确保您在 ./configure 文件中将 ALSA 设置为 yes

 Target ...................... x86_64-unknown-linux-gnu
  C++ bindings ................ no
  Debug output ................ no

  ALSA ........................ yes
  ASIHPI ...................... no

  OSS ......................... yes
  JACK ........................ no       "

安装最新版本的 pyaudio
PyAudio-0.2.11.tar.gz

Check this
https://github.com/shichao-an/soundmeter/issues/7

All you have to do is
install ALSA : sudo apt-get install libasound-dev

then build portaudio (this version pa_stable_v190600_20161030.tgz)
http://www.portaudio.com/download.html

then Get root privileges (sudo su root under Ubuntu where plain su root does not work.)

Place the portaudio archive in /usr/src and unpack it with tar xvfz pa_snapshot.tgz This will generate the directory /usr/src/portaudio.

Descend into this directory and execute these commands:

./configure

make

make install

ldconfig

The linrad configure script has to be run after the successful installation of portaudio to make Linrad aware of the fact that portaudio is available.

Make sure you get ALSA as yes in the ./configure file

 Target ...................... x86_64-unknown-linux-gnu
  C++ bindings ................ no
  Debug output ................ no

  ALSA ........................ yes
  ASIHPI ...................... no

  OSS ......................... yes
  JACK ........................ no       "

Install the latest version of pyaudio
(PyAudio-0.2.11.tar.gz)

ヅ她的身影、若隐若现 2024-10-18 12:51:38

从以下来源安装 pyaudio 对我有用

conda install nwani::portaudio nwani::pyaudio

:Answer of Mamun Or Rashid for Question...
操作系统错误:没有可用的默认输入设备

Installing pyaudio from following source worked for me

conda install nwani::portaudio nwani::pyaudio

reference : Answer of Mamun Or Rashid for question...
OSError: No Default Input Device Available

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文