在 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 <module>
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 <module>
import speech_recognition as sr
ImportError: No module named 'speech_recognition'
我已经下载了speech_recognition和pyaudio库,但错误的原因仍然让我困惑。请帮忙!
最佳答案
已找到修复 -
pip install SpeechRecognition
pip install pyaudio
如果您发现错误 -
sudo apt-get install python-pyaudio
sudo apt-get install libjack-jackd2-dev portaudio19-dev
然后再说一遍 -
pip install pyaudio
关于Python语音识别: 'module' object has no attribute 'microphone' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28004954/