running Rhasspy3 (tutorial) in a docker container
kha84 opened this issue · 5 comments
It's not an issue, it's a side note!
Just in case, if anyone is interested to play with Rhasspy3 in a docker container (whatever your motivation is) - onnxruntime doesn't work quite well with Alpine-based containers, because of musl. So build your containers out of something different. In my case I'm running this on a top of my Ubuntu 22.10 with Pipewire as a sound server executed under my own user - thus the fd mount.
# create a docker container
docker run -it -v /run/user/$(id -u)/pipewire-0:/tmp/pipewire-0 -e XDG_RUNTIME_DIR=/tmp --publish 13331:13331 --name rhasspy3 ubuntu /bin/bash
# inside of the docker container
apt update && apt install pipewire-audio-client-libraries alsa-utils vim python3.10-venv git -y
# in UBUNTU 22.04 you'll need to make that PCM device a default one
cat << EOF > ~/.asoundrc
pcm.!default {
type plug
slave.pcm "pipewire"
}
EOF
# make sure sound playback works with now-default ALSA device (press ^C to stop)
# if it doesn't - check/change your default Pipewire sink, like in Gnome that will be in Sound Settings -> Output
# (or write a lua script for wireplumber)
speaker-test -c2
# Now let's test microphone. Say something after running the arecord
arecord -d5 test.wav
# And play it back:
aplay test.wav
# If you don't hear anything back - check / change your default Pipewire input device
# in Gnome that will be in Sound Settings -> Input
# install dependencies and clone the project
apt install git -y
cd /root
git clone https://github.com/rhasspy/rhasspy3
cd rhasspy3
# check configuration
script/run bin/config_print.py
# check microphone
script/run bin/mic_test_energy.py
# config VAD
apt install python3.10-venv -y
mkdir -p config/programs/vad/
cp -R programs/vad/silero config/programs/vad/
python3 -m venv config/programs/vad/silero/.venv
. config/programs/vad/silero/.venv/bin/activate
config/programs/vad/silero/script/setup
# install and test VAD
script/run bin/mic_record_sample.py sample.wav
# make a pause, say something, then after a pause it will be captured to a file
# play the resulted file
aplay sample.wav
...
.... or just follow the rest guide - https://github.com/rhasspy/rhasspy3/blob/master/docs/tutorial.md
I'd like to thank @synesthesiam Michael once again, I followed his guide and everything works just perfectly.
Need to mention, if you're planning to run this on a headless system without being logged in to X all the time, Pipewire in the most of the popular distributions is configured to run under a user account and reconfiguring it to run as root is highly discouraged. So on most recent linuxes it works like this: before you log in, pipewire is executed under "gdm" user, if you're running Gnome with GDM. And then, after you login, the gdm's Pipewire is stopped and your own one is started instead.
I think, for such cases (headless system with some occasional interactive use), the ideal scenario here would be to reconfigure pipewire systemwide e.g. in /etc to accept local network connections and use them instead. So it doesn't matter if the gdm user will be running Pipewire, or your own user, docker container will be able to connect to it over TCP.
I spent quite a lot time, figuring out where the tail or head is in such "sound in docker using pure alsa" / "sound in docker when the host is running pipewire" / "sound in docker when the host running pulseaudio" configurations :)
The onnxruntime package exists for Alpine in the repo (https://pkgs.alpinelinux.org/package/edge/testing/x86_64/onnxruntime), but it's in edge, i.e. not stable branch. It means that it will require few dependent packages (including musl itself) to be switched to edge. Not sure we want that in terms of stability, but I can give it a try.
I've also seen few traces of ppl building onnxruntime successfully from source - I even tried that myself following one of such guides, but it didn't work quite well in my case. But again, if we need it namely on alpine, I can put some better efforts into that.
Is there an official docker yet?
@NonaSuomy if you're interested I've made a simple sh script to create your own local docker image - it's just a one-click-thing and in a couple of minutes you have it. It's still WIP though, there're few missing parts (they're mentioned in TODO), but you can give it a try - https://github.com/kha84/R3Docker
I run portainer with watchtower for updates so was hoping for a simple docker-compose linked to a GitHub to point it at so it can keep updating itself weekly as it gets better.