Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

README.md

speech-dispatcher

CONTAINERS IMAGES RUN BUILD

speech-dispatcher in container and PulseAudio Docker setting.

This document outlines the steps to modify the PulseAudio configuration on Docker host (Jetson) so to run an audio enabled application in continer. It can be referenced when one tries to enable similar PulseAudio based application inside a container.

Step 1. PulseAudio Configuration on Host

  • Share PulseAudio socket file (/run/user/1000/pulse/native)
  • Set PULSE_SERVER env variable in the container
  • Allow root access to the socket file

To output sound from your Docker container while using the host's sound device, you can map the appropriate sound devices and audio services from the host to the container.

We use PulseAudio from within the container. To do this, we need share the PulseAudio socket between the host and the container.

jetson-containers run.sh modification

Expand the docker run options for sound like this.

   --device /dev/snd \
   -e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
   -v ${XDG_RUNTIME_DIR}/pulse:${XDG_RUNTIME_DIR}/pulse \

Option: If not working, further expand like following and try.

   --device /dev/snd \
   -e XDG_RUNTIME_DIR=/run/user/1000 \
   -e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
   -v ${XDG_RUNTIME_DIR}/pulse:${XDG_RUNTIME_DIR}/pulse \
   -v /etc/machine-id:/etc/machine-id \
   --group-add audio \

Edit /etc/pulse/default.pa

We operate as root in container, so we need to mofidy PusleAudio configuraiton file so that it allows the root user access to the socket file.

sudo vi /etc/pulse/default.pa

Find the section loading module-native-protomocl-unix and add auth-anonymous=1

### Load several protocols
.ifexists module-esound-protocol-unix.so
load-module module-esound-protocol-unix auth-anonymous=1
.endif
load-module module-native-protocol-unix auth-anonymous=1

Restart Pulse Audio service.

pulseaudio --kill
pulseaudio --start

Step 2. Container setup

Inside the container, install speech-dispatcher and run its server inside the container (as opposed to running the speech-dispatcher server on the host).

Here is the Dockefile snippet.

RUN apt-get update && \
    apt install -y speech-dispatcher alsa-utils && \
    rm -rf /var/lib/apt/lists/* && \
    apt-get clean

CMD speech-dispatcher --spawn  && /bin/bash

Notice it's starting the speech-dispatcher server as a background process within the container with speech-dispatcher --spawn.

Step 3. Check the default audio sink device

Reboot the host system to make sure PulseAudio starts with the modified config file.

Then, on the host, check the default audio sink.

pactl info

If need to be set, set-default-sink.

pactl list short sinks
pactl set-default-sink [SINK_NAME_OR_INDEX]

Step 4. Run the container

jetson-containers run $(autotag speech-dispatcher)

Once inside the container;

spd-say "Hello world"

You should here TTS audio coming out from your host audio device.

Troubleshooting

Restart PulseAudio with debug output

pulseaudio -k
pulseaudio -vvv

Alsa layer test

ALSA should work in your container just with /dev/snd mapped.

Test with speaker-test -t wav -c 2 (alsa-utils).

CONTAINERS
speech-dispatcher
   Requires L4T ['>=34.1.0']
   Dependencies
   Dockerfile Dockerfile
RUN CONTAINER

To start the container, you can use jetson-containers run and autotag, or manually put together a docker run command:

# automatically pull or build a compatible container image
jetson-containers run $(autotag speech-dispatcher)

# or if using 'docker run' (specify image and mounts/ect)
sudo docker run --runtime nvidia -it --rm --network=host speech-dispatcher:36.4.0

jetson-containers run forwards arguments to docker run with some defaults added (like --runtime nvidia, mounts a /data cache, and detects devices)
autotag finds a container image that's compatible with your version of JetPack/L4T - either locally, pulled from a registry, or by building it.

To mount your own directories into the container, use the -v or --volume flags:

jetson-containers run -v /path/on/host:/path/in/container $(autotag speech-dispatcher)

To launch the container running a command, as opposed to an interactive shell:

jetson-containers run $(autotag speech-dispatcher) my_app --abc xyz

You can pass any options to it that you would to docker run, and it'll print out the full command that it constructs before executing it.

BUILD CONTAINER

If you use autotag as shown above, it'll ask to build the container for you if needed. To manually build it, first do the system setup, then run:

jetson-containers build speech-dispatcher

The dependencies from above will be built into the container, and it'll be tested during. Run it with --help for build options.