Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Errno -9996] #59

Open
hugoneedshelp opened this issue Dec 30, 2021 · 3 comments
Open

[Errno -9996] #59

hugoneedshelp opened this issue Dec 30, 2021 · 3 comments

Comments

@hugoneedshelp
Copy link

Hey guys! So I'm a noob at this and I need your help,

so when I do the command:
sudo python3 visualization.py scroll
This pops up, can someone help me fix this?

ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_headpho.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'cards.bcm2835_headpho.pcm.hdmi.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
ALSA lib conf.c:4745:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5233:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM hdmi
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
connect(2) call to /dev/shm/jack-0/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
connect(2) call to /dev/shm/jack-0/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib conf.c:5200:(snd_config_expand) Unknown parameters {AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2 CARD 0}
ALSA lib pcm.c:2660:(snd_pcm_open_noupdate) Unknown PCM iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2 CARD 0}
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_dmix.c:1009:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_direct.c:1846:(_snd_pcm_direct_get_slave_ipc_offset) Invalid value for card
ALSA lib pcm_direct.c:1846:(_snd_pcm_direct_get_slave_ipc_offset) Invalid value for card
ALSA lib pcm_dmix.c:1009:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_direct.c:1846:(_snd_pcm_direct_get_slave_ipc_offset) Invalid value for card
ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card
ALSA lib pcm_direct.c:1846:(_snd_pcm_direct_get_slave_ipc_offset) Invalid value for card
connect(2) call to /dev/shm/jack-0/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
Traceback (most recent call last):
File "/home/pi/dancyPi-audio-reactive-led/python/visualization.py", line 420, in
microphone.start_stream(microphone_update)
File "/home/pi/dancyPi-audio-reactive-led/python/microphone.py", line 10, in start_stream
stream = p.open(format=pyaudio.paInt16,
File "/usr/lib/python3/dist-packages/pyaudio.py", line 750, in open
stream = Stream(self, *args, **kwargs)
File "/usr/lib/python3/dist-packages/pyaudio.py", line 441, in init
self._stream = pa.open(**arguments)
OSError: [Errno -9996] Invalid input device (no default output device)

@kyle-hunady
Copy link

Haha, also having a difficult time with finding the default device. Using mic mode on RPi 3B.

Technically I don't have a USB mic plugged in (awaiting shipment), so that could be the issue. However, I do have an AUX mic plugged into the headphone jack. I did a lot of googling. Making sure a default device is set isn't easy for a beginner like myself--something to do with faulty install for dependencies of pyaudio.

However, pyaudio only throws this error because you did not specify a specific device to use, so it checks for a default. The error comes from this code:

stream = p.open(format=pyaudio.paInt16,
                    channels=1,
                    rate=config.MIC_RATE,
                    input=True,
                    frames_per_buffer=frames_per_buffer)

So here's my workaround: there's another parameter that allows you to explicitly choose your device to bypass needing a default...

stream = p.open(format=pyaudio.paInt16,
                    channels=1,
                    rate=config.MIC_RATE,
                    input=True,
                    frames_per_buffer=frames_per_buffer,
                    input_device_index=0) # choosing device 0

How do you know the index of your device? Pyaudio can tell you! Here's a little snippet I put it into microphone.py:

# some statements above...
# in microphone.py
def start_stream(callback):
    p = pyaudio.PyAudio()

    # list devices (code from https://stackoverflow.com/questions/36894315/how-to-select-a-specific-input-device-with-pyaudio)
    info = p.get_host_api_info_by_index(0)
    numdevices = info.get('deviceCount')
    print("Device count: ", numdevices) # look for this in console output
    # and the rest ...

I ran sudo python3 visualization.py scroll again, and scanned through the errors to find the device list. I only had one from my console output, here's a snippet:

Device count:  1
Input Device id  0  -  bcm2835 Headphones: - (hw:0,0)

Here's my new microphone.py that lists all devices and hardcodes the index for headphones:

# microphone.py
import time
import numpy as np
import pyaudio
import config


def start_stream(callback):
    print("In start_stream")
    p = pyaudio.PyAudio()

    print("Initialized pyaudio")
    # list devices (https://stackoverflow.com/questions/36894315/how-to-select-a-specific-input-device-with-pyaudio)
    info = p.get_host_api_info_by_index(0)
    numdevices = info.get('deviceCount')
    print("Device count: ", numdevices)

    for i in range(0, numdevices):
        # if (p.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
        print("Input Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name'))
    # end list devices
    
    # default_info = p.get_default_input_device_info()
    # print(default_info.get('name'))

    frames_per_buffer = int(config.MIC_RATE / config.FPS)
    stream = p.open(format=pyaudio.paInt16,
                    channels=1,
                    rate=config.MIC_RATE,
                    input=True,
                    frames_per_buffer=frames_per_buffer,
                    input_device_index=0)
    overflows = 0
    prev_ovf_time = time.time()
    while True:
        try:
            y = np.fromstring(stream.read(frames_per_buffer, exception_on_overflow=False), dtype=np.int16)
            y = y.astype(np.float32)
            stream.read(stream.get_read_available(), exception_on_overflow=False)
            callback(y)
        except IOError:
            overflows += 1
            if time.time() > prev_ovf_time + 1:
                prev_ovf_time = time.time()
                print('Audio buffer has overflowed {} times'.format(overflows))
    stream.stop_stream()
    stream.close()
    p.terminate()

I got past the default device error, but now it claims it has an invalid number of channels. I'll have to see what that means when I have time tomorrow.

@kyle-hunady
Copy link

Ah, well, the internet tells me that the headphone jack on RPi is actually strictly output (no mic input). So I was doomed to fail. Maybe that's causing the invalid channel number issue.

It seems USB-cams are a necessity. I'll be getting one soon.

@naztronaut
Copy link
Owner

Ah, well, the internet tells me that the headphone jack on RPi is actually strictly output (no mic input).

Sadly.

You don't need a camera, just a USB mic should do.

@hugoneedshelp if you still need help, try these commands and let me know what you see:

  • cat /proc/asound/cards
  • cat /etc/modules
  • arecord -l
  • aplay -l

You can also run the script that Kyle posted above.

Apologies to anyone who are still waiting for responses from me. I've shifted focus so so I haven't had a lot of time to work on my Raspberry Pi projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants