python-3.xspeech-recognitionpyaudioalsa

How do I make ALSA library available to PyAudio?


I am trying to build a Python application that uses the SpeechRecognition package to record user's speech with a microphone. I am using Ubuntu 23.04 on a Lenovo X1 Carbon. I am working in a conda environment with python 3.11 (although I've tested in 3.9 and have the same problem).

I have installed libasound2-dev and pyaudio to my system:

$ sudo apt install libasound2-dev
$ sudo apt install python3-pyaudio

And installed pyaudio and speech_recognition in my conda env:

$ conda activate my_env
$ conda install pyaudio
$ conda install speech_recognition

When I try to execute the SpeechRecognition package from the shell I get the following stderr:

$ python3 -m speech_recognition
ALSA lib conf.c:4005:(snd_config_hooks_call) Cannot open shared library libasound_module_conf_pulse.so (/home/me/miniconda3/envs/py3.9/lib/alsa-lib/libasound_module_conf_pulse.so: cannot open shared object file: No such file or directory)
ALSA lib control.c:1529:(snd_ctl_open_noupdate) Invalid CTL hw:0

I checked and confirmed that /home/me/miniconda3/envs/py3.9/lib/alsa-lib/ does NOT exist. However, listing my conda env packages shows the following:

$ conda list alsa
# Name                    Version                   Build  Channel
alsa-lib                  1.2.9                hd590300_0    conda-forge
pyalsaaudio               0.10.0                   pypi_0    pypi

Is the issue that pyaudio doesn't know where to find alsa-lib?


Solution

  • Posting the solution I eventually found in case it helps others. It appears to be an issue with the SpeechRecognition conda package version or at least managing the package with conda. I tried installing with pip and the "cannot open shared library" error messages stopped occurring and I was able to record with my microphone.