如何在docker集装箱中播放声音

我试图dockerize文本到语音应用程序与其他开发人员共享代码,但是我现在遇到的问题是泊坞窗容器无法find我的主机上的声卡。

当我尝试在我的docker容器中播放一个wav文件时

root@3e9ef1e869ea:/# aplay Alesis-Fusion-Acoustic-Bass-C2.wav ALSA lib confmisc.c:768:(parse_card) cannot find card '0' ALSA lib conf.c:4259:(_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:4259:(_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:4259:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such file or directory ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default aplay: main:722: audio open error: No such file or directory 

我猜主要问题是docker容器无法到达我的主机上的声卡。

到目前为止,我有

  1. 我在docker容器中安装了alsa-utils和大部分alsa依赖项。
  2. 增加了--group-add audio同时通过指定docker run --group-add audio -t -i self/debian /bin/bash来运行容器docker run --group-add audio -t -i self/debian /bin/bash

我不确定这是甚至可能与docker(我不确定如何硬件资源,如声卡共享容器)。 我在Mac OS Yosemite主机上使用debian容器。

这肯定是可能的,你需要挂载/ dev / snd,看看Jess Frazelle如何启动一个Spotify容器

https://blog.jessfraz.com/post/docker-containers-on-the-desktop/

你会注意到的

docker run -it \ -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket -e DISPLAY=unix$DISPLAY \ # pass the display --device /dev/snd \ # sound --name spotify \ jess/spotify

或者是Chrome,最后

docker run -it \ --net host \ # may as well YOLO --cpuset-cpus 0 \ # control the cpu --memory 512mb \ # max memory it can use -v /tmp/.X11-unix:/tmp/.X11-unix \ # mount the X11 socket -e DISPLAY=unix$DISPLAY \ # pass the display -v $HOME/Downloads:/root/Downloads \ # optional, but nice -v $HOME/.config/google-chrome/:/data \ # if you want to save state --device /dev/snd \ # so we have sound --name chrome \ jess/chrome