Run rhasspy-speakers-cli-hermes in docker

Hey,

I’ve started to use rhasspy-speakers-cli-hermes again for my setup. Sadly I can’t get it running in a docker container.
I’ve tried it with: docker run -it -d --name speaker rhasspy/rhasspy-speakers-cli-hermes --host 192.168.0.2 --port 12183 --debug --play-command "aplay -D plug:dmix"

Inside the docker container the dmix device isn’t available so it fails.

Is anyone running it successfully? For me it’s not an option to just run it using the command line. My remote ssh session ends as soon as my computer goes to sleep and at this point I won’t here anything anymore.

Any help is much appreciated.

Thanks

I haven’t tried this with rhasspy-speakers-cli-hermes, but you need to mount the audio device inside the Docker container to be able to use it. Try adding the --device /dev/snd option before the name of the image.

1 Like

I’ve tried it at first with this:
docker run -it --name speaker --device /dev/snd:/dev/snd --rm rhasspy/rhasspy-speakers-cli-hermes --host 192.168.0.2 --port 12183 --debug --play-command "aplay -D plug:dmix"

Afterwards I thought maybe the asound.conf isn’t correctly propagated from the host system so I’ve tried this command:
docker run -it --name speaker --device /dev/snd:/dev/snd --mount type=bind,source=/home/pi/Documents/asound_mix.txt,target=/etc/asound.conf --rm rhasspy/rhasspy-speakers-cli-hermes --host 192.168.0.2 --port 12183 --debug --play-command "aplay -D plug:dmix"

Both commands end up with this error message:

Using virtual environment at /usr/lib/rhasspy-speakers-cli-hermes/.venv
[DEBUG:2021-07-10 09:33:41,896] rhasspyspeakers_cli_hermes: Namespace(debug=True, host='192.168.0.2', list_command=None, log_format='[%(levelname)s:%(asctime)s] %(name)s: %(message)s', password=None, play_command='aplay -D plug:dmix', port=12183, site_id=None, tls=False, tls_ca_certs=None, tls_cert_reqs='CERT_REQUIRED', tls_certfile=None, tls_ciphers=None, tls_keyfile=None, tls_version=None, username=None)
[DEBUG:2021-07-10 09:33:41,898] asyncio: Using selector: EpollSelector
[DEBUG:2021-07-10 09:33:41,899] rhasspyspeakers_cli_hermes: Connecting to 192.168.0.2:12183
[DEBUG:2021-07-10 09:33:41,905] asyncio: Using selector: EpollSelector
[DEBUG:2021-07-10 09:33:41,907] rhasspyspeakers_cli_hermes: Connected to MQTT broker
[DEBUG:2021-07-10 09:33:41,908] rhasspyspeakers_cli_hermes: Subscribed to hermes/audioServer/+/playBytes/#
[DEBUG:2021-07-10 09:33:41,908] rhasspyspeakers_cli_hermes: Subscribed to hermes/audioServer/toggleOff
[DEBUG:2021-07-10 09:33:41,909] rhasspyspeakers_cli_hermes: Subscribed to rhasspy/audioServer/getDevices
[DEBUG:2021-07-10 09:33:41,909] rhasspyspeakers_cli_hermes: Subscribed to hermes/audioServer/toggleOn
[DEBUG:2021-07-10 09:33:48,584] rhasspyspeakers_cli_hermes: <- AudioPlayBytes(28044 byte(s))
[DEBUG:2021-07-10 09:33:48,585] rhasspyspeakers_cli_hermes: ['aplay', '-D', 'plug:dmix']
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_card_driver returned error: No such file or directory
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2564:(snd_pcm_open_noupdate) Unknown PCM dmix
aplay: main:828: audio open error: No such file or directory
[ERROR:2021-07-10 09:33:48,601] rhasspyspeakers_cli_hermes: handle_play
Traceback (most recent call last):
  File "/usr/lib/rhasspy-speakers-cli-hermes/rhasspyspeakers_cli_hermes/__init__.py", line 60, in handle_play
    subprocess.run(self.play_command, input=wav_bytes, check=True)
  File "/usr/lib/python3.7/subprocess.py", line 512, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['aplay', '-D', 'plug:dmix']' returned non-zero exit status 1.
[DEBUG:2021-07-10 09:33:48,607] rhasspyspeakers_cli_hermes: -> AudioPlayError(error="Command '['aplay', '-D', 'plug:dmix']' returned non-zero exit status 1.", site_id='default', context='8d5bf63d-29af-4cc0-8302-44f47f59b667', session_id='')
[DEBUG:2021-07-10 09:33:48,608] rhasspyspeakers_cli_hermes: Publishing 173 bytes(s) to hermes/error/audioServer/play
[DEBUG:2021-07-10 09:33:48,609] rhasspyspeakers_cli_hermes: -> AudioPlayFinished(id='8d5bf63d-29af-4cc0-8302-44f47f59b667', session_id='')
[DEBUG:2021-07-10 09:33:48,610] rhasspyspeakers_cli_hermes: Publishing 63 bytes(s) to hermes/audioServer/default/playFinished

If I run aplay -l inside the container I’m getting the sound device correctly listed:

root@b3bdebdedf55:/# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 1: USB [Jabra SPEAK 510 USB], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

That’s my asound.conf on the host:

pcm.ossmix {
    type dmix
    ipc_key 1024 # must be unique!
#   ipc_key_add_uid false   # let multiple users share
#   ipc_perm 0666           # IPC permissions for multi-user sharing (octal, default 0600)
    slave {
        pcm "hw:1,0"      # you cannot use a "plug" device here, darn.
        period_time 0
        period_size 1024 # must be power of 2
        buffer_size 8192  # dito. It
       #format "S32_LE"
       #periods 128 # dito.
       #rate 8000 # with rate 8000 you *will* hear,
       # if ossmix is used :)
    }
    # bindings are cool. This says, that only the first
    # two channels are to be used by dmix, which is
    # enough for (most) oss apps and also lets
    # multichannel chios work much faster:
    bindings {
        0 0 # from 0 => to 0
        1 1 # from 1 => to 1
    }
}
pcm.dsp0 {
    type plug
    slave.pcm "ossmix" # use our new PCM here
}
# mixer1 like above
ctl.mixer1 {
    type hw
    card 1
}

Currently I still need to run aplay with the -D flag. Haven’t managed so far to define the ossmix as the default device for aplay. Without the flag there isn’t any sound coming from aplay test.wav.

This command has almost been the solution… except for the wrong plug…

Final command:

docker run -it --name speaker --device /dev/snd:/dev/snd --mount type=bind,source=/home/pi/Documents/asound_mix.txt,target=/etc/asound.conf --rm rhasspy/rhasspy-speakers-cli-hermes --host 192.168.0.2 --port 12183 --debug --play-command "aplay -D plug:ossmix"