I am having issues with playing sound trhough headphones connected to a jack port, on an raspberry Pi expansion board. I'm using the "ReSpeaker 2-Mics Pi HAT", dual-microphone expansion board. I've installed the voice card source code.
My main point is to have a python script play a sound file with the use of pyaudio. I wanted to specify the output_device_index for pyaudio stream. To get the index I tried this code:
import pyaudio
p = pyaudio.PyAudio()
info = p.get_host_api_info_by_index(0)
numdevices = info.get('deviceCount')
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'))
else:
print("Output Device id ", i, " - ", p.get_device_info_by_host_api_device_index(0, i).get('name'))
but it gives me a bunch of ALSA warnings and only those devices:
Output Device id 0 - sysdefault
Output Device id 1 - lavrate
Output Device id 2 - samplerate
Output Device id 3 - speexrate
Input Device id 4 - pulse
Output Device id 5 - upmix
Output Device id 6 - vdownmix
Output Device id 7 - playback
Input Device id 8 - capture
Output Device id 9 - dmixed
Input Device id 10 - array
Output Device id 11 - dmix
Input Device id 12 - default
When I run aplay -l and arecord -l the [seeed-2mic-voicecard] is listed correctly
pi@raspberrypi:~ $ aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: Headphones [bcm2835 Headphones], device 0: bcm2835 Headphones [bcm2835 Headphones]
Subdevices: 7/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
card 1: vc4hdmi0 [vc4-hdmi-0], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 2: vc4hdmi1 [vc4-hdmi-1], device 0: MAI PCM i2s-hifi-0 [MAI PCM i2s-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
card 3: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0 [bcm2835-i2s-wm8960-hifi wm8960-hifi-0]
Subdevices: 1/1
Subdevice #0: subdevice #0
pi@raspberrypi:~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 3: seeed2micvoicec [seeed-2mic-voicecard], device 0: bcm2835-i2s-wm8960-hifi wm8960-hifi-0 [bcm2835-i2s-wm8960-hifi wm8960-hifi-0]
Subdevices: 0/1
Subdevice #0: subdevice #0
After running a test audio file:
arecord -D "plughw:3,0" -f S16_LE -r 16000 -d 5 -t wav test.wav
aplay -D "plughw:3,0" test.wav
the sound records and plays without issues.
I just don't know how to access the audio devices without the use of aplay. PulseAudio Volume control and Audacity don't pick up my output device.