在macbook air 64位上运行以下代码,测试
python 2.7和
python 3.4上的代码
import speech_recognition as sr
r = sr.Recognizer()
with sr.microphone() as source:
audio = r.listen(source)
try:
print("You said " + r.recognize(audio))
except LookupError:
print("Could not understand audio")
当我尝试python 2.7时,我不断收到以下错误:
Traceback (most recent call last):
File "star.py", line 3, in
with sr.microphone() as source:
AttributeError: 'module' object has no attribute 'microphone'
(star.py是我正在测试它的文件的名称)
当我尝试python 3.4时,我不断收到以下错误:
Traceback (most recent call last):
File "star.py", line 1, in
import speech_recognition as sr
ImportError: No module named 'speech_recognition'
我已经下载了speech_recognition和pyaudio库,但错误的原因仍然没有找到我.请帮忙!