PyAudio IOError: No Default Input Device Available
Asked Answered
R

6

28

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"

Remillard answered 12/1, 2011 at 17:55 Comment(5)
What do you get if you try pa.get_device_count()?Entrammel
@Entrammel pa.get_device_count() returns 0Remillard
pyaudio installed via sudo apt-get install python-pyaudio works on Ubuntu-11.10Denominate
so it tells you don't have what you ask for, or it cannot find what you ask for, or you don't have permissions to access what you ask for. seems reasonable to me. perhaps you really don't have input devices?Scenery
DIY! FIY. Get sources - compile - ... - profit!Fredkin
W
3

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
Wallah answered 26/4, 2012 at 18:30 Comment(2)
I ran into the same problem in with EPD 7.3 (64 bit) in Ubuntu 12.04, and this solution worked. One difference: I installed python-pyaudio rather than python-gnuradio-audio-portaudio.Physiognomy
can't find the package python-gnuradio-audio-portaudio even update the apt-getMeri
S
3

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

Subscript answered 22/7, 2011 at 16:2 Comment(0)
W
3

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
Wallah answered 26/4, 2012 at 18:30 Comment(2)
I ran into the same problem in with EPD 7.3 (64 bit) in Ubuntu 12.04, and this solution worked. One difference: I installed python-pyaudio rather than python-gnuradio-audio-portaudio.Physiognomy
can't find the package python-gnuradio-audio-portaudio even update the apt-getMeri
K
2

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

Kassandra answered 12/1, 2021 at 10:30 Comment(0)
M
1

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.

Mayor answered 20/1, 2011 at 14:1 Comment(2)
yes, PortAudio is installed. This is an oddity to do with the Enthought Python Distribution, I think. Under the standard distribution, PyAudio works fine.Remillard
The problem lies with Enthoughts portaudio since the pyaudio modules are identical.Wallah
T
1

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)

Toggery answered 24/9, 2018 at 16:49 Comment(0)
R
0

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

Rigger answered 9/3, 2020 at 11:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.