0

I made this thread in Raspberry PI Stack Exchange and my problem was solved. Until last week I tried to run my Python application again (both in Raspbian and Ubuntu 16.04) this error appeared again.

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

What I have done so far.

  • pyaudio.PyAudio().get_device_count() returns 0.
  • arecord --device=hw:1,0 --format S16_LE --rate 44100 -c1 test.wav returns this error.

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

  • I have properly installed PortAudio version 19 stable.
  • I can still use my microphone for other activities like video call, ....
  • I am using Python 3.
notalentgeek
  • 4,939
  • 11
  • 34
  • 53

2 Answers2

2

Well the problem is definitely in the PyAudio part. However, some threads mention that the main culprit is miss-connection between PyAudio and PortAudio (although, I have already compiled proper PortAudio version 19 stable).

At this point my solution is to use pyalsaaudio from https://github.com/larsimmisch/pyalsaaudio. For Python 2.x you can just install it with pip install pyalsaaudio, however for Python 3.x you need to compile it from the source codes (see instruction in its GitHub page). Note to mention is that pyalsaaudio only works for Linux. With pyalsaaudio my Python application is working like usual.

notalentgeek
  • 4,939
  • 11
  • 34
  • 53
0

This is not really intended to be an answer but it might be helpful to print a list of all the devices available to pyaudio and see if your USB soundcard is even being recognized.

(Some code from a previous project):

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']))

You may also want to look into alsa and some techniques to list available devices and possibly alsamixer as well.

Logic1
  • 1,806
  • 3
  • 26
  • 43
  • `p.get_device_count()` is `0` I miss typed my post. – notalentgeek May 13 '17 at 08:32
  • Have you verified that the USB port is still functional (tried other ports)? Have you verified the sound card is functional on other PCs? Maybe sound card's cable is damaged. Also could be related to a power issue where a higher amperage PS might help? Or use a powered USB Hub. – Logic1 May 13 '17 at 20:47
  • 1
    I am using laptop and as mentioned "I can still use my microphone for other activities like video call, ....". I will try fresh installing my Ubuntu. – notalentgeek May 13 '17 at 22:02