I have an application that takes voice input from microphone, performs speech recognition and plays certain music files based on the cue words recognized. This application is in Python and implements a couple of python modules like PyAudio, Playsound and Websocket-client. I am trying to build a Docker image of this application.
I have created a Dockerfile with below contents:
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" ]When trying to build it, I get a successful build response as below:
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 buster InRelease [118 kB]
Get:2 buster-updates InRelease [46.8 kB]
Get:3 buster/main amd64 Packages [7897 kB]
Get:4 buster/updates InRelease [39.1 kB]
Get:5 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 buster/main amd64 libasound2- data all 1.1.8-1 [59.6 kB]
Get:2 buster/main amd64 libasound2 amd64 1.1.8-1 [361 kB]
Get:3 buster/main amd64 libasound2-dev amd64 1.1.8-1 [145 kB]
Get:4 buster/main amd64 libjack0 amd64 1:0.125.0-3 [109 kB]
Get:5 buster/main amd64 libjack-dev amd64 1:0.125.0-3 [227 kB]
Get:6 buster/main amd64 libportaudio2 amd64 19.6.0-1 [66.6 kB]
Get:7 buster/main amd64 libportaudiocpp0 amd64 19.6.0-1 [18.8 kB]
Get:8 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 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 27e8859468f3c0fd7dc5a76dd9c4dbd7906/websocket_client-0.56.0-py2.py3- none-any.whl (200kB)
Collecting six (from websocket-client) Downloading 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 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:latestBut when I try to runt his image, I get a bunch of errors where I my docker image cannot find the drivers specified. While its is possible to resolve similar issues in Virtual Machines, I am not sure if there is a simple way to resolve the same in docker containers.
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 1 Reset to default