在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")
Run Code Online (Sandbox Code Playgroud)
当我尝试python 2.7时,我不断收到以下错误:
Traceback (most recent call last):
File "star.py", line 3, in <module>
with sr.microphone() as source:
AttributeError: 'module' object has no attribute 'microphone'
Run Code Online (Sandbox Code Playgroud)
(star.py是我正在测试它的文件的名称)当我尝试python 3.4时,我不断收到以下错误:
Traceback (most recent call last):
File "star.py", line 1, in <module>
import speech_recognition as sr
ImportError: No module named 'speech_recognition'
Run Code Online (Sandbox Code Playgroud)
我已经下载了speech_recognition和pyaudio库,但错误的原因仍然没有找到我.请帮忙!