无法在 Docker 上托管语音识别和声音播放应用程序

无法在 Docker 上托管语音识别和声音播放应用程序

我有一个应用程序,它从麦克风接收语音输入,执行语音识别并根据识别出的提示词播放某些音乐文件。此应用程序使用 Python 编写,并实现了几个 Python 模块,如 PyAudio、Playsound 和 Websocket-client。我正在尝试构建此应用程序的 Docker 映像。

我创建了一个包含以下内容的 Dockerfile:

FROM ubuntu
ADD . /app

FROM python:3
ADD transcribe.py /
ADD speech.cfg /
ADD setup.cfg / 
ADD setup.py /

RUN apt-get update
RUN apt-get --assume-yes install libasound-dev portaudio19-dev     libportaudio2 libportaudiocpp0
RUN pip3 install pyaudio
RUN pip3 install websocket-client
RUN pip3 install playsound
CMD [ "python3", "./transcribe.py" ]

当尝试构建它时,我收到如下成功构建响应:

ABCDEFG:random-folder User$ docker build -t storyassist .
Sending build context to Docker daemon  3.494MB
Step 1/13 : FROM ubuntu
 ---> 4c108a37151f
Step 2/13 : ADD . /app
 ---> e520eb6d11e8
Step 3/13 : FROM python:3
 ---> 42d620af35be
Step 4/13 : ADD transcribe.py /
 ---> 6c76aee20537
Step 5/13 : ADD speech.cfg /
 ---> 74c3221f2324
Step 6/13 : ADD setup.cfg /
 ---> 2c415c19a4fb
Step 7/13 : ADD setup.py /
 ---> c6382077cdcf
Step 8/13 : RUN apt-get update
 ---> Running in ace9adab6a44
Get:1 http://deb.debian.org/debian buster InRelease [118 kB]
Get:2 http://deb.debian.org/debian buster-updates InRelease [46.8 kB]
Get:3 http://deb.debian.org/debian buster/main amd64 Packages [7897 kB]
Get:4 http://security.debian.org/debian-security buster/updates     InRelease [39.1 kB]
Get:5 http://security.debian.org/debian-security     buster/updates/main amd64 Packages [42.5 kB]
Fetched 8143 kB in 3s (2493 kB/s)
Reading package lists...
Removing intermediate container ace9adab6a44
 ---> d46db350b95f
Step 9/13 : RUN apt-get --assume-yes install libasound-dev     portaudio19-dev libportaudio2 libportaudiocpp0
 ---> Running in 8d772b088b15
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libasound2 libasound2-data libjack-dev libjack0
Suggested packages:
  libasound2-plugins alsa-utils libasound2-doc jackd1 portaudio19-doc
The following NEW packages will be installed:
  libasound2 libasound2-data libasound2-dev libjack-dev libjack0     libportaudio2
  libportaudiocpp0 portaudio19-dev
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 1094 kB of archives.
After this operation, 5886 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 libasound2-    data all 1.1.8-1 [59.6 kB]
Get:2 http://deb.debian.org/debian buster/main amd64 libasound2     amd64 1.1.8-1 [361 kB]
Get:3 http://deb.debian.org/debian buster/main amd64 libasound2-dev     amd64 1.1.8-1 [145 kB]
Get:4 http://deb.debian.org/debian buster/main amd64 libjack0 amd64     1:0.125.0-3 [109 kB]
Get:5 http://deb.debian.org/debian buster/main amd64 libjack-dev     amd64 1:0.125.0-3 [227 kB]
Get:6 http://deb.debian.org/debian buster/main amd64 libportaudio2     amd64 19.6.0-1 [66.6 kB]
Get:7 http://deb.debian.org/debian buster/main amd64     libportaudiocpp0 amd64 19.6.0-1 [18.8 kB]
Get:8 http://deb.debian.org/debian buster/main amd64 portaudio19-    dev amd64 19.6.0-1 [108 kB]
debconf: delaying package configuration, since apt-utils is not     installed
Fetched 1094 kB in 1s (1381 kB/s)
Selecting previously unselected package libasound2-data.
(Reading database ... 24544 files and directories currently     installed.)
Preparing to unpack .../0-libasound2-data_1.1.8-1_all.deb ...
Unpacking libasound2-data (1.1.8-1) ...
Selecting previously unselected package libasound2:amd64.
Preparing to unpack .../1-libasound2_1.1.8-1_amd64.deb ...
Unpacking libasound2:amd64 (1.1.8-1) ...
Selecting previously unselected package libasound2-dev:amd64.
Preparing to unpack .../2-libasound2-dev_1.1.8-1_amd64.deb ...
Unpacking libasound2-dev:amd64 (1.1.8-1) ...
Selecting previously unselected package libjack0:amd64.
Preparing to unpack .../3-libjack0_1%3a0.125.0-3_amd64.deb ...
Unpacking libjack0:amd64 (1:0.125.0-3) ...
Selecting previously unselected package libjack-dev.
Preparing to unpack .../4-libjack-dev_1%3a0.125.0-3_amd64.deb ...
Unpacking libjack-dev (1:0.125.0-3) ...
Selecting previously unselected package libportaudio2:amd64.
Preparing to unpack .../5-libportaudio2_19.6.0-1_amd64.deb ...
Unpacking libportaudio2:amd64 (19.6.0-1) ...
Selecting previously unselected package libportaudiocpp0:amd64.
Preparing to unpack .../6-libportaudiocpp0_19.6.0-1_amd64.deb ...
Unpacking libportaudiocpp0:amd64 (19.6.0-1) ...
Selecting previously unselected package portaudio19-dev:amd64.
Preparing to unpack .../7-portaudio19-dev_19.6.0-1_amd64.deb ...
Unpacking portaudio19-dev:amd64 (19.6.0-1) ...
Setting up libasound2-data (1.1.8-1) ...
Setting up libjack0:amd64 (1:0.125.0-3) ...
Setting up libasound2:amd64 (1.1.8-1) ...
Setting up libjack-dev (1:0.125.0-3) ...
Setting up libasound2-dev:amd64 (1.1.8-1) ...
Setting up libportaudio2:amd64 (19.6.0-1) ...
Setting up libportaudiocpp0:amd64 (19.6.0-1) ...
Setting up portaudio19-dev:amd64 (19.6.0-1) ...
Processing triggers for libc-bin (2.28-10) ...
Removing intermediate container 8d772b088b15
 ---> d2bc72b4654c
Step 10/13 : RUN pip3 install pyaudio
 ---> Running in 654227a7b259
Collecting pyaudio
  Downloading         https://files.pythonhosted.org/packages/ab/42/b4f04721c5c5bfc196ce156b3    c768998ef8c0ae3654ed29ea5020c749a6b/PyAudio-0.2.11.tar.gz
Building wheels for collected packages: pyaudio
  Building wheel for pyaudio (setup.py): started
  Building wheel for pyaudio (setup.py): finished with status     'done'
  Stored in directory:     /root/.cache/pip/wheels/f4/a8/a4/292214166c2917890f85b2f72a8e5f13e1ffa5    27c4200dcede
Successfully built pyaudio
Installing collected packages: pyaudio
Successfully installed pyaudio-0.2.11
Removing intermediate container 654227a7b259
 ---> 1336a7cbfb0f
Step 11/13 : RUN pip3 install websocket-client
 ---> Running in dfa7c4d9f195
Collecting websocket-client
  Downloading         https://files.pythonhosted.org/packages/29/19/44753eab1fdb50770ac696055    27e8859468f3c0fd7dc5a76dd9c4dbd7906/websocket_client-0.56.0-py2.py3-    none-any.whl (200kB)
Collecting six (from websocket-client)
  Downloading     https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238    ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Installing collected packages: six, websocket-client
Successfully installed six-1.12.0 websocket-client-0.56.0
Removing intermediate container dfa7c4d9f195
 ---> e82fd88cd21a
Step 12/13 : RUN pip3 install playsound
 ---> Running in 2f2af7ce7bdc
Collecting playsound
  Downloading         https://files.pythonhosted.org/packages/f5/16/10d897b0a83fb4b05b03a63d7    a2667ab75f857f67f7062fd447dd3f49bf7/playsound-1.2.2-py2.py3-none-any.whl
Installing collected packages: playsound
Successfully installed playsound-1.2.2
Removing intermediate container 2f2af7ce7bdc
 ---> ac6c2e571e3b
Step 13/13 : CMD [ "python3", "./transcribe.py" ]
 ---> Running in 11291eaff8f4
Removing intermediate container 11291eaff8f4
 ---> 2d8cd222b2bb
Successfully built 2d8cd222b2bb
Successfully tagged storyassist:latest

但是当我尝试运行该镜像时,我收到一堆错误,我的 docker 镜像找不到指定的驱动程序。虽然可以在虚拟机中解决类似的问题,但我不确定是否有一种简单的方法可以在 docker 容器中解决同样的问题。

ABCDEFG:random-folder User$ docker run storyassist
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_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:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM sysdefault
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_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:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM sysdefault
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_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:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_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:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib confmisc.c:767:(parse_card) cannot find card '0'
ALSA lib conf.c:4568:(_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:4568:(_snd_config_evaluate) function snd_func_concat returned error: No such file or directory
ALSA lib confmisc.c:1246:(snd_func_refer) error evaluating name
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5047:(snd_config_expand) Evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM dmix
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/threading.py", line 926, in     _bootstrap_inner
    self.run()
  File "/usr/local/lib/python3.7/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "./transcribe.py", line 83, in read_audio
    RATE = int(p.get_default_input_device_info()    ['defaultSampleRate'])
  File "/usr/local/lib/python3.7/site-packages/pyaudio.py", line     949, in get_default_input_device_info
    device_index = pa.get_default_input_device()
OSError: No Default Input Device Available

相关内容