Skip to content

add audio support in docker container for gazebo simulationΒ #7

@jacknlliu

Description

@jacknlliu

audio and contact force are very import signals for physical interaction for human.

Human process the audio signal faster than image.

ALSA lib can't work in container even though PulseAudio(server) has been installed in the host.

AL lib: (WW) alc_initconfig: Failed to initialize backend "pulse"
ALSA lib confmisc.c:768:(parse_card) cannot find card '0'
ALSA lib conf.c:4292:(_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:4292:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4292:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:4771:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM default
AL lib: (EE) ALCplaybackAlsa_open: Could not open playback device 'default': No such file or directory
[Err] [OpenAL.cc:84] Unable to open audio device[default]
 Audio will be disabled.

Solution:

docker run --device /dev/snd \
	          -e PULSE_SERVER=unix:${XDG_RUNTIME_DIR}/pulse/native \
	          -v ${XDG_RUNTIME_DIR}/pulse/native:${XDG_RUNTIME_DIR}/pulse/native \
	          --group-add $(getent group audio | cut -d: -f3) 

In container, we also need the following command to make sure the access to /dev/snd/*, if your user in container is not created by docker run option --user or USER in Dockerfile

sudo usermod -aG audio <your_user>

# or directly change the permission of /dev/snd/*
# sudo chmod a+rwx /dev/snd/*
# this will take effect directly, without restarting your container.

And then restart your container.

Reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions