cmusphinx/pocketsphinx

Can't use audio from Docker

debasishaimonk opened this issue · 2 comments

Whenver i am trying to run LiveSpeech() in my docker enviroment. It showing me "sounddevice.PortAudioError: Error querying device -1" error.
How should i fix this?

Unfortunately audio is very difficult to get working correctly in Docker. I have never successfully been able to make it work, and there is I think a note to this effect in the documentation or on the CMUSphinx website.

You can, sort of, do this, by running with --device /dev/snd. See https://github.com/mviereck/x11docker/wiki/Container-sound:-ALSA-or-Pulseaudio and https://wiki.alpinelinux.org/wiki/ALSA for example.

You might need to find and select the appropriate recording device by running arecord -l - if it doesn't show "card 0" in the list then use the card number that it does show. For example in my case (Thinkpad X250 with HDMI port as card 0) the microphone is card 1. To run in the Docker image I do:

docker build -t pocketsphinx .
docker run --device /dev/snd -it pocketsphinx
AUDIODEV=hw:1,0 sox -qd $(pocketsphinx soxflags) | pocketsphinx live -