ALSA error recording audio Raspberry Pi 3

Hi, I’m trying to run the following python’s example of PyAudio lib (https://people.csail.mit.edu/hubert/pyaudio/) using a dockerfile with the base-image for raspberry with wheezy raspbian.
FROM resin/raspberrypi3-debian:wheezy

"""PyAudio example: Record a few seconds of audio and save to a WAVE file."""

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT,
                channels=CHANNELS,
                rate=RATE,
                input=True,
                frames_per_buffer=CHUNK)

print("* recording")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    data = stream.read(CHUNK)
    frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()

The script runs with no problem in my raspberry without resin but when i try to implment it as a resin proyect comes the error messages as follow:

ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.front.0:CARD=0'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM front
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround40.0:CARD=0'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround40
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround41
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround50
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround51.0:CARD=0'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround51
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.surround71.0:CARD=0'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM surround71
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM iec958
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM spdif
01.02.18 10:33:03 (-0500) ALSA lib confmisc.c:1286:(snd_func_refer) Unable to find definition 'cards.bcm2835.pcm.iec958.0:CARD=0,AES0=4,AES1=130,AES2=0,AES3=2'
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4241:(_snd_config_evaluate) function snd_func_refer returned error: No suchfile or directory
01.02.18 10:33:03 (-0500) ALSA lib conf.c:4720:(snd_config_expand) Evaluate error: No such file or directory
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM spdif
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
01.02.18 10:33:03 (-0500) ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
01.02.18 10:33:03 (-0500) ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
01.02.18 10:33:03 (-0500)
01.02.18 10:33:03 (-0500) ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused
01.02.18 10:33:03 (-0500)
01.02.18 10:33:03 (-0500) ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
01.02.18 10:33:03 (-0500) Cannot connect to server socket err = No such file or directory
01.02.18 10:33:03 (-0500) Cannot connect to server request channel
01.02.18 10:33:03 (-0500) jack server is not running or cannot be started

I am not able to figure out the problems here. Is it something about alsa configuration or the port audio settings?
How can I check what the problem is?

Thanks

Hello,

Are you using the same dockerfile and the same basic image when you try your project locally? (i.e. not as a resin project).

Also, are there any significant changes when you try to implement it as a resin project? If you have the same dockerfile, there shouldn’t be any.

I don’t have any experience in ALSA and pulseaudio, but maybe you need to start jack server and pulseaudio manually?

pulseaudio --start
jack_control start

Hi,

I tried starting manually pulseaudio and the jack but thast’s not the problem, it still prompting the same error log.

Looking more about this error I found this thread (https://stackoverflow.com/questions/28985714/run-apps-using-audio-in-a-docker-container) on Stackoverflow. According to it ALSA needs /dev/snd and some hardware acces. For it I must start the docke like this …

docker run -ti --rm \
    -v /dev/snd:/dev/snd \
    --lxc-conf='lxc.cgroup.devices.allow = c 116:* rwm' \
    myContainer sh -c "echo run something"`

Can I do that with RESIN ? If it’s possible, how could it be done?

Thanks.

Hello,

There is some documentation here: https://docs.resin.io/runtime/runtime/#access-to-dev .
In resinOS application containers run with the --privileged option and should have access to /dev/.