如何在 Mac OS Yosemite 上的 Docker 容器中播放声音
How to play sound in a Docker container on Mac OS Yosemite
我正在尝试 docker 化文本到语音应用程序以便与其他开发人员共享代码,但是我现在遇到的问题是 docker 容器找不到声卡在我的主机上。
当我尝试在 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 容器无法访问我主机上的声卡。
到目前为止我有
- 我安装了 alsa-utils 和我的大部分 alsa 依赖项
docker 容器。
- 添加了
--group-add audio
而 运行
通过指定 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
我正在尝试 docker 化文本到语音应用程序以便与其他开发人员共享代码,但是我现在遇到的问题是 docker 容器找不到声卡在我的主机上。
当我尝试在 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 容器无法访问我主机上的声卡。
到目前为止我有
- 我安装了 alsa-utils 和我的大部分 alsa 依赖项 docker 容器。
- 添加了
--group-add audio
而 运行 通过指定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