Hi there,
After overcoming some troubles I’ve finally got the mic tests working and arecord works fine (although there’s background noise). However I couldn’t figure out how to get PyAudio to work properly.
My record devices:
pi@raspberrypi:~ $ python3 -m sounddevice
0 bcm2835 ALSA: - (hw:0,0), ALSA (0 in, 2 out)
1 bcm2835 ALSA: IEC958/HDMI (hw:0,1), ALSA (0 in, 2 out)
2 Dummy: PCM (hw:1,0), ALSA (2 in, 2 out)
3 sysdefault, ALSA (128 in, 128 out)
4 pulse, ALSA (32 in, 32 out)
5 sc, ALSA (2 in, 2 out)
6 mic_channel0, ALSA (2 in, 2 out)
7 mic_channel1, ALSA (2 in, 2 out)
8 mic_channel2, ALSA (2 in, 2 out)
9 mic_channel3, ALSA (2 in, 2 out)
10 mic_channel4, ALSA (2 in, 2 out)
11 mic_channel5, ALSA (2 in, 2 out)
12 mic_channel6, ALSA (2 in, 2 out)
13 mic_channel7, ALSA (2 in, 2 out)
14 mic_channel8, ALSA (2 in, 2 out)
15 dmix, ALSA (0 in, 2 out)
- 16 default, ALSA (32 in, 32 out)
My python code:
import pyaudio
CHUNK = 1024
p = pyaudio.PyAudio()
stream = p.open(format = pyaudio.paInt16,
channels = 1,
rate = 16000,
input = True,
input_device_index = 6,
frames_per_buffer=CHUNK)
while True:
data = stream.read(CHUNK)
print(len(data))
It always crashes after reading a few frames. Output’s like:
pi@raspberrypi:~ $ python3 pyaudiotest.py
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
2048
2048
ALSA lib pcm_file.c:358:(snd_pcm_file_write_bytes) write failed: Bad file descriptor
ALSA lib pcm_file.c:358:(snd_pcm_file_write_bytes) write failed: Bad file descriptor
2048
ALSA lib pcm_file.c:358:(snd_pcm_file_write_bytes) write failed: Bad file descriptor
ALSA lib pcm_file.c:358:(snd_pcm_file_write_bytes) write failed: Bad file descriptor
python3: pcm_file.c:397: snd_pcm_file_add_frames: Assertion `file->wbuf_used_bytes < file->wbuf_size_bytes’ failed.
Aborted
Any help would be greatly appreciated. Thanks!