我在代码中玩了一圈,并抓住了其他开发人员的一些代码。我有此代码,它会不断显示错误消息:
Traceback (most recent call last):
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 108, in get_pyaudio
import pyaudio
ImportError: No module named 'pyaudio'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/pi/Documents/SHADOW/tkinter.py", line 5, in <module>
with sr.Microphone() as source:
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 79, in __init__
self.pyaudio_module = self.get_pyaudio()
File "/usr/local/lib/python3.5/dist-packages/speech_recognition/__init__.py", line 110, in get_pyaudio
raise AttributeError("Could not find PyAudio; check installation")
AttributeError: Could not find PyAudio; check installation
我尝试用麦克风插入某些耳机,但不知道问题出在哪里。我必须先卸载然后重新安装吗?
这是我正在使用的代码:
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
print("You said {}".format(text))
except:
print("sorry")