如何使ALSA库对PyAudio可用?

huangapple go评论58阅读模式
英文:

How do I make ALSA library available to PyAudio?

问题

我正在尝试构建一个使用SpeechRecognition包录制用户麦克风语音的Python应用程序。
我在联想X1 Carbon上使用Ubuntu 23.04。我在一个conda环境中使用Python 3.11进行开发(尽管我在3.9中进行了测试,问题相同)。

我已将libasound2-dev和pyaudio安装到我的系统中:

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

并在我的conda环境中安装了pyaudio和speech_recognition:

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

当我尝试从shell执行SpeechRecognition包时,我收到以下标准错误信息:

$ python3 -m speech_recognition
ALSA lib conf.c:4005:(snd_config_hooks_call) 无法打开共享库libasound_module_conf_pulse.so(/home/me/miniconda3/envs/py3.9/lib/alsa-lib/libasound_module_conf_pulse.so: 没有此文件或目录)
ALSA lib control.c:1529:(snd_ctl_open_noupdate) 无效的CTL hw:0

我检查并确认/home/me/miniconda3/envs/py3.9/lib/alsa-lib/不存在。
然而,列出我的conda环境包时显示如下:

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

问题是pyaudio不知道在哪里找到alsa-lib吗?

英文:

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?

答案1

得分: 0

不确定仅安装libasound-dev是否足够。还需要portaudio。
尝试运行以下命令:apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg,然后pip install PyAudio。如果您已经尝试过这样做,请忽略。

英文:

not sure if libasound-dev alone is sufficient. portaudio is also required.
Try this, apt install libasound2-dev portaudio19-dev libportaudio2 libportaudiocpp0 ffmpeg and then pip install PyAudio. If you have tried this, then kindly ignore.

答案2

得分: 0

以下是翻译好的部分:

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.

英文:

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.

huangapple
  • 本文由 发表于 2023年6月16日 05:05:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76485507.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定