OK, I am lost.
I tried for last 2 days to get working alsa config to allow me to dmix and softvol two sources - one from host an second from Docker. And I can’t get it to work. Here is what I have:
-
Respeaker USB MIc Array v2 card (with 48kHz + 1 channel input fw), which can only play audi when recoded into 48kHz, S24_3LE, 2channel stream.
-
Snapcast client on host, which is unable to recode (include server) into S24_3LE, and therefore I do receive 48kHz, S16_LE, 2 channel stream.
-
Rhasspy in Docker, using aplay.
I want both application to output simultaneously, playing to Respeaker card. Also I want to be able to set volume independently for each application. I tried almost any combination I can think of, but I failed.
It seems that problem is Docker, which is not able to share alsa dmix device, so even if dmix is working locally (i.e. on the host I can play from both apps in the same time) this doesn’t work in Docker.
So my snapcast client started on system boot will start playing music, but from rhasspy Docker when I try to play any file I get:
root@b4a24c1da87d:/# aplay -D rhasspy /usr/share/rhasspy/etc/wav/beep_hi.wav -v
ALSA lib pcm_dmix.c:1108:(snd_pcm_dmix_open) unable to open slave
aplay: main:828: audio open error: Device or resource busy
Using same command on host:
pi@speakerliving:~/rhasspy $ aplay -D rhasspy beep_error.wav
Playing WAVE ‘beep_error.wav’ : Signed 16 bit Little Endian, Rate 44100 Hz, Stereo
works like a charm. So the only problem is dmix alsa plugin shared via Docker. From this source:
For ALSA sound just share sound devices with --device /dev/snd
. You would not need the more advanced Pulseaudio setup, but will have trouble if more than one application tries to access the sound hardware. x11docker provides this setup with option --alsa
.
And no, I don’t want to try Pulse Audio on RPi.
I would be glad for any help/hint/idea. Only one in my mind now is to install snapcast client into Rhasspy docker. But hat meant starting maintain my own Docker forks.
FYI: my current asound.conf:
pcm.mix {
type dmix
ipc_key 1024
ipc_perm 0666
slave {
pcm "hw:0,0"
period_time 0
period_size 1024
buffer_size 4096
rate 48000
format S24_3LE
}
bindings {
0 0
1 1
}
}
pcm.snapcast {
type plug
slave.pcm "snapcast_vol"
}
pcm.snapcast_vol {
type softvol
slave.pcm "mix"
control {
name "Snapcast"
card 0
}
}
pcm.rhasspy {
type plug
slave.pcm "rhasspy_vol"
}
pcm.rhasspy_vol {
type softvol
slave.pcm "mix"
control {
name "Rhasspy"
card 0
}
}