PulseAudio on host <> docker-container (on RPi OS Lite Buster)

Hi all,

it took me 4 hours this afternoon to figure out what is necessary to get audio out onto a bluetooth speaker which is connected to the RPi OS lite Buster operating system via PulseAudio (not BlueAlsa). I found a solution for me that works for my setup and I thought it would be maybe a good idea to share it here.

First of all, I connected my Bluetooth speaker using this manual:

First of all, I could not start the PulseAudio Service, it always failed.
After running it with verbose output, using:
/usr/bin/pulseaudio --daemonize=false -v
There I encountered the following weird problem:
E: [pulseaudio] core-util.c: Failed to create secure directory (/home/pi/.config/pulse): Permission denied
The problem was due to the installation of rhasspy (I think!); the folder belongs to root and not to pi, which is the account that must start the PulseAudio Service.
A
sudo chown pi .config
executed in the home directory solved this problem.
Finally I was able to paplay aaa.wav sound on the host.

I then changed my configuration of Audio Playing section to “aplay”, Device “pulse”, Available Devices; “PulseAudio Sound Server (pulse)”.
But no sound came out of my bluetooth speaker.

I first had to adapt my docker-compose.yml to add the container to the audio group, and forward the PulseAudio cookie. Found most of the parts here:

Finally, which this docker-compose.yml it worked:

version: "2.4"
services:
  rhasspy:
    image: "rhasspy/rhasspy"
    container_name: rhasspy
    restart: unless-stopped
    volumes:
      - "$HOME/.config/rhasspy/profiles:/profiles"
      - "/etc/localtime:/etc/localtime:ro"
      - "$HOME/.config/pulse/cookie:/root/.config/pulse/cookie"
      - "${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native"
    environment:
      - PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native
    ports:
      - "12101:12101"
      - "12183:12183"
    devices:
      - "/dev/snd:/dev/snd"
    command: --user-profiles /profiles --profile de
    group_add:
      - audio

Hopefully someone can benefit from this information :blush:.

Regards
Martin from Austria

PS: For the sake of completeness, my ReSpeaker 4-mic array still worked afterwards… :smiley:

8 Likes