![找不到 PyAudio,请检查安装](https://linux22.com/image/893734/%E6%89%BE%E4%B8%8D%E5%88%B0%20PyAudio%EF%BC%8C%E8%AF%B7%E6%A3%80%E6%9F%A5%E5%AE%89%E8%A3%85.png)
我是语音识别新手,正在尝试使用 Google Speech API 构建语音转文本程序。我使用以下链接中提供的教程和其中的命令来安装依赖项。教程:https://pythonspot.com/en/speech-recognition-using-google-speech-api/
命令:
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
cd pyaudio
sudo python setup.py install
sudo apt-get installl libportaudio-dev
sudo apt-get install python-dev
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
sudo pip3 install SpeechRecognition
然后我尝试在 spyder 中运行这个虚拟脚本,看看它是否正常工作,
import speech_recognition as sr
# Record Audio
r = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = r.listen(source)
# Speech recognition using Google Speech Recognition
try:
# for testing purposes, we're just using the default API key
# to use another API key, use `r.recognize_google(audio,
#key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
# instead of `r.recognize_google(audio)`
print("You said: " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
`
现在,当我运行该脚本时,我不断收到此错误:
Could not import the PyAudio C module '_portaudio'.
Traceback (most recent call last):
File "<ipython-input-1-2b39d94ceb5b>", line 1, in <module>
runfile('/home/sanwal092/Desktop/Python/SR/dummy.py', wdir='/home/sanwal092/Desktop/Python/SR')
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 866, in runfile
execfile(filename, namespace)
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/spyder/utils/site/sitecustomize.py", line 102, in execfile
exec(compile(f.read(), filename, 'exec'), namespace)
File "/home/sanwal092/Desktop/Python/SR/dummy.py", line 14, in <module>
with sr.Microphone() as source:
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/speech_recognition/__init__.py", line 78, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/home/sanwal092/anaconda3/lib/python3.6/site-packages/speech_recognition/__init__.py", line 109, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
我已经在互联网上搜索过是否可以解决这个问题,但似乎没有找到任何可行的方法,这是我第一次使用任何类型的语音识别。
如果您能对此问题提供任何帮助,或者对如何学习和提高语音识别能力提出任何建议,我们将不胜感激。
答案1
这条消息告诉你找不到 PyAudio;检查安装
您的“教程”中的这个命令列表是错误的,您首先安装库,然后编译 python 模块:
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git cd pyaudio sudo python setup.py install sudo apt-get installl libportaudio-dev sudo apt-get install python-dev sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev sudo pip3 install SpeechRecognition
正确的顺序是:
sudo apt-get install libportaudio-dev
sudo apt-get install python-dev
sudo apt-get install libportaudio0 libportaudio2 libportaudiocpp0 portaudio19-dev
git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
cd pyaudio
sudo python setup.py install
sudo pip3 install SpeechRecognition
该错误主要是由于安装 pyaudio 的步骤中的错误引起的sudo python setup.py install
。您需要重复此步骤。您需要先分析并报告此步骤中发生的错误,然后再继续下一步。