cmusphinx / pocketsphinx

A small speech recognizer
Other
3.87k stars 713 forks source link

Can't use audio from Docker #347

Closed debasishaimonk closed 7 months ago

debasishaimonk commented 1 year ago

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?

dhdaines commented 1 year ago

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.

dhdaines commented 7 months ago

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 -