如何在Docker容器中播放声音

编程入门 行业动态 更新时间:2024-10-18 18:24:51
本文介绍了如何在Docker容器中播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将文本语音转换应用程序与其他开发人员共享,但是我现在遇到的问题是Docker容器在主机上找不到声卡。

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

root @ 3e9ef1e869ea:/#播放Alesis-Fusion-Acoustic-Bass-C2.wav ALSA lib confmisc.c:768:(parse_card)找不到卡'0' ALSA lib conf.c: 4259:(_ snd_config_evaluate)函数snd_func_card_driver返回错误:没有这样的文件或目录 ALSA lib confmisc.c:392:(snd_func_concat)错误评估字符串 ALSA lib conf.c:4259:(_ snd_config_evaluate)函数snd_func_concat返回错误:没有这样的文件或目录 ALSA lib confmisc.c:1251:(snd_func_refer)错误评估名称 ALSA lib conf.c:4259:(_ snd_config_evaluate)函数snd_func_refer返回错误:没有这样的文件或目录目录 ALSA lib conf.c:4738:(snd_config_expand)评估错误:没有这样的文件或目录 ALSA lib pcm.c:2239:(snd_pcm_open_noupdate)未知的PCM默认播放:主要: 722:音频打开错误:没有这样的文件或目录

我想主要是提示docker容器无法到达主机上的声卡。

到目前为止,我已经

  • 我安装了alsa-utils,并且大多数 docker容器中的alsa依赖项。
  • 通过指定 docker run在运行容器时添加了-group-add音频- -group-add audio -t -i self / debian / bin / bash
  • 我不确定docker是否可以做到这一点(我不确定如何将声卡之类的硬件资源与容器共享)。我在Mac OS Yosemite主机上使用的是Debian容器。

    解决方案

    绝对有可能,您需要挂载/ dev / snd,看看Jess Frazelle如何从以下位置启动Spotify容器: / p>

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

    您会注意到

    docker run -it \ -v /tmp/.X11-unix:/tmp/.X11-unix \#安装X11套接字 -e DISPLAY = unix $ DISPLAY \#通过显示 --device / dev / snd \#声音 --name spotify \ jess / spotify

    或Chrome浏览器,最后

    docker run -it \ --net host \#也可以YOLO --cpuset-cpus 0 \#控制cpu --memory 512mb \#可以使用的最大内存 -v /tmp/.X11-unix:/tmp/.X11-unix \#安装X11插槽 -e DISPLAY = unix $显示\#通过显示 -v $ HOME / Downloads:/ root / Downloads \#可选,但是不错 -v $ HOME / .config / google-chrome /:/ data \#如果要保存状态 --device / dev / snd \#这样我们就可以听到的声音了--name chrome \ jess / chrome

    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.

    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

    I guess that the main problem is docker container is unable reach the sound card on my host.

    So far I have

  • I installed alsa-utils and most of the alsa dependencies within my docker container.
  • Added --group-add audio while running the container by specifying docker run --group-add audio -t -i self/debian /bin/bash
  • 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.

    解决方案

    It is definitely possible, you need to mount /dev/snd, see how Jess Frazelle launches a Spotify container, from

    blog.jessfraz/post/docker-containers-on-the-desktop/

    you will notice

    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

    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

    更多推荐

    如何在Docker容器中播放声音

    本文发布于:2023-11-14 15:16:55,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1587770.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:容器   声音   如何在   Docker

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!