Hi,
This is my first seeed project. I am using a ReSpeaker 2-Mics Pi HAT V1 on a Raspberry Pi 4
I recorded a wav file using ‘arecord’ , which I hear ok when I run : aplay -D “plughw:3,0” test.wav
But I am unable to hear the same wav file using python (see code below). The program pauses slightly which makes me think it is playing the file,. Do I need to increase the volume , or edit the asound.conf ?
I choose 3 for output_device_index to match aplay above
I installed GitHub - respeaker/seeed-voicecard: 2 Mic Hat, 4 Mic Array, 6-Mic Circular Array Kit, and 4-Mic Linear Array Kit for Raspberry Pi , and SPI is enabled .
I listed the /etc/asound.conf below.
Thanks, Peter
def play_wav(wavename):
file_path = r"/home/pi/test.wav"
print(f"Playing wav file : {file_path}")
wf = wave.open(str(file_path), 'rb')
p = pyaudio.PyAudio()
stream = p.open(format = p.get_format_from_width(wf.getsampwidth()),
channels = wf.getnchannels(),
rate = wf.getframerate(),
output = True,
output_device_index = 3)
# read data (based on the chunk size)
data = wf.readframes(chunk)
# play stream (looping from beginning of file to the end)
while data:
# writing to the stream is what *actually* plays the sound.
stream.write(data)
data = wf.readframes(chunk)
# cleanup stuff.
stream.close()
p.terminate()
=================================================================
here is the /etc/asound.conf
The IPC key of dmix or dsnoop plugin must be unique
If 555555 or 666666 is used by other processes, use another one
use samplerate to resample as speexdsp resample is bad
defaults.pcm.rate_converter “samplerate”
pcm.!default {
type asym
playback.pcm “playback”
capture.pcm “capture”
}
pcm.playback {
type plug
slave.pcm “dmixed”
}
pcm.capture {
type plug
slave.pcm “array”
}
pcm.dmixed {
type dmix
slave.pcm “hw:seeed2micvoicec”
ipc_key 555555
}
pcm.array {
type dsnoop
slave {
pcm “hw:seeed2micvoicec”
channels 2
}
ipc_key 666666
}