如何在 Mac OS Yosemite 上的 Docker 容器中播放声音 [英] How to play sound in a Docker container on Mac OS Yosemite
问题描述
我正在尝试将文本转语音应用程序 dockerize 以与其他开发人员共享代码,但是我现在遇到的问题是 docker 容器在我的主机上找不到声卡.
I'm trying to dockerize a text to speech application for sharing the code with other developers, however the issue I am having right now is the docker container cannot find the sound card on my host machine.
当我尝试在我的 docker 容器中播放 wav 文件时
When I try to play a wav file in my docker container
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 容器无法访问我主机上的声卡.
I guess that the main problem is docker container is unable reach the sound card on my host.
到目前为止我有
- 我安装了 alsa-utils 和大部分 alsa 依赖项码头集装箱.
- 在运行时添加了
--group-add audio
容器通过指定docker run --group-add audio -t -iself/debian/bin/bash
- I installed alsa-utils and most of the alsa dependencies within my docker container.
- Added
--group-add audio
while running the container by specifyingdocker run --group-add audio -t -i self/debian /bin/bash
我不确定 docker 是否可以实现(我不确定声卡等硬件资源如何与容器共享).我在 Mac OS Yosemite 主机上使用 debian 容器.
I am not sure if this is even possible with docker(I'm not exactly sure of how hardware resources such as sound cards are shared with containers). I'm using a debian container on a Mac OS Yosemite host.
推荐答案
肯定有可能,需要挂载/dev/snd,看Jess Frazelle如何启动Spotify容器,来自
It is definitely possible, you need to mount /dev/snd, see how Jess Frazelle launches a Spotify container, from
https://blog.jessfraz.com/post/docker-桌面容器/
你会注意到
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,最后
or for Chrome, at the end
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
这篇关于如何在 Mac OS Yosemite 上的 Docker 容器中播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!