【发布时间】:2020-03-28 23:53:08
【问题描述】:
如果有人知道这里发生了什么,我将不胜感激。所以我试图识别通过麦克风输入的语音(设备索引为 1),而我的程序正在挂断聆听。我已经针对环境噪音进行了调整,但我仍然没有取得任何进展。
这是我的代码:
import pyaudio
import speech_recognition as sr
r = sr.Recognizer()
mic = sr.Microphone(1)
with mic as source:
r.adjust_for_ambient_noise(source)
print("Please Speak :")
audio = r.listen(source)
print("Stop Talking")
try:
text = r.recognize_google(audio)
print("You said : " + r. recognize_google(text))
except:
print("Sorry, I could not recognize what you said")
这就是程序运行时我得到的全部内容:
Please Speak :
然后没有别的了。我在 python 控制台中运行了它,但从未得到控制台提示。
r = sr.Recognizer()
with mic as source:
r.adjust_for_ambient_noise(source)
print("Please Speak :")
audio = r.listen(source)
Please Speak :
我不确定我可以在这里做什么或出了什么问题。 我在跑步:
Mac OS Mojave 10.14.6
Python 3.8
Pycharm IDLE
现在我做了一些改变:
import speech_recognition as sr
r = sr.Recognizer()
print(sr.Microphone.list_microphone_names())
mic = sr.Microphone(device_index=1)
with mic as source:
r.adjust_for_ambient_noise(source, duration=5)
print("Please Speak :")
audio = r.listen(source, timeout=5)
print("Stop Talking")
try:
text = r.recognize_google(audio)
print("You said : " + text)
except:
print("Sorry, I could not recognize what you said.")
这是我的错误:
eTraceback (most recent call last):
File "/Users/cameronclarke/PycharmProjects/SpeechRecog/Speech
Recog.py", line 13, in <module>
audio = r.listen(source, timeout=5)
File
Users/cameronclarke/opt/anaconda3/envs/SpeechRecog/lib/python3.7/site-
packages/speech_recognition/__init__.py", line 544, in listen
raise WaitTimeoutError("listening timed out while waiting for phrase
to start")
speech_recognition.WaitTimeoutError: listening timed out while waiting
for phrase to start.
为什么会这样? 干杯!感谢所有帮助:)
【问题讨论】:
-
我在这里stackoverflow.com/questions/32005310/…发现了一个类似的问题,这里列出的解决方案是否有帮助?
-
嘿,我已经编辑了我的原始帖子! @DeepakPatankar 感谢您的帮助
标签: speech-recognition microphone python-3.8 hung