Invalid audio device #2 - Raspberry Pi OS (32-bit) Lite fresh install

W
wittrup posted Jun 6, 16:53:

Hello

Have installed SamplerBox by following the procedure.

´´´
pi@raspberrypi:~/SamplerBox $ python samplerbox.py
Invalid audio device #2
´´´

Tried re-installing Raspberry Pi OS (32-bit) Lite on the memory card to remove all other faults.

How do I proceed to fix this issue?

´´´
pi@raspberrypi:~/SamplerBox $ aconnect -o
client 14: 'Midi Through' [type=kernel]
0 'Midi Through Port-0'
client 20: 'MK-249 USB MIDI keyboard' [type=kernel,card=1]
0 'MK-249 USB MIDI keyboard MIDI 1'

pi@raspberrypi:~/SamplerBox $ aplay -l output
List of PLAYBACK Hardware Devices
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 8/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1
Subdevice #2: subdevice #2
Subdevice #3: subdevice #3
Subdevice #4: subdevice #4
Subdevice #5: subdevice #5
Subdevice #6: subdevice #6
Subdevice #7: subdevice #7

´´´

W
wittrup posted Jun 6, 19:35:

After modifying samplerbox.py some:

#########################################
# OPEN AUDIO DEVICE
#
#########################################

sd = None
outputdevices = [AUDIO_DEVICE_ID]
[outputdevices.append(x) for x in range(0, 10) if x not in outputdevices]
for AUDIO_DEVICE_ID in outputdevices:
    if sd:
        break
    try:
        sd = sounddevice.OutputStream(device=AUDIO_DEVICE_ID, blocksize=512, samplerate=44100, channels=2, dtype='int16', callback=AudioCallback)
        sd.start()
        print 'Opened audio device #%i' % AUDIO_DEVICE_ID
    except Exception as e:
        print 'Error when opening audio device #%i - %s - %s' % (AUDIO_DEVICE_ID, type(e).__name__, str(e))
        sd = None
#    print 'Invalid audio device #%i' % AUDIO_DEVICE_ID
if not sd:
     print 'Unable to open audio device'
     exit(1)

By removing the sample rate specification, i.e.:

            sd = sounddevice.OutputStream(device=AUDIO_DEVICE_ID, blocksize=512, channels=2, dtype='int16', callback=AudioCallback)

I end up with this:

pi@raspberrypi:~/SamplerBox $ sudo python samplerbox.py
Error when opening audio device #2 - PortAudioError - Error querying device 2
Opened audio device #0
Opened MIDI: MK-249 USB MIDI keyboard 20:0
Preset loading: 0 (0 Saw)
Preset loaded: 0

However there is no sound when playing at the MIDI keyboard.

Audio output has been verified with OMXPlayer

wget rpf.io/lamp3 -O example.mp3 --no-check-certificate
pi@raspberrypi:~ $ omxplayer -o local example.mp3
Error: Unable to open font
Audio codec mp3float channels 1 samplerate 11025 bitspersample 16
Subtitle count: 0, state: off, index: 1, delay: 0
have a nice day ;)

Please advice.

R
Rosco posted Jun 14, 22:39:

Hello I have been having the same problem, but have a workaround involving an external audio device.

Am installing manually using a pi 4, and was getting the Invalid audio device 2 issue.

I couldnt totally figure out how the audio devices were getting numbered, but running alsamixer, and then F6: Select sound card, I could see that no 2, appeared to be bcm2835 Headphones, and I have headphones plugged into my audio jack and otherwise working.

Well, I wasnt making any headway, so on a whim I plugged in my USB Focusrite Scarlet Studio, which is an external audio device that I have for running an external mic, and guitar into computer. This showed up in alsamixer as a new entry (no 3).

Then setting AUDIO_DEVICE_ID = 3 in the python script, and Bingo, it worked.
I dont really want to use the external device however, so still looking for better solution

S
Sebizarro posted Aug 4, 14:11:

Hello,
I'm having the same issue, but don't have any external sound card, is there another way to use the internal sound card of the pi?
I've tried the audio devices from 0 to 3 and nothing-

...

  (not published)
  I want to post as guest
 

Post