我在下面有一个 python 程序。我想获取麦克风输入并从输入中获取文本。当我运行程序时,它总是停在第 9 行,“audio_text = r.listen(source)”并且不再继续。即使我已经停止说话,它似乎仍在等待麦克风输入停止。我知道我的麦克风可以工作,因为我录制了一个文件并使用 aplay 播放了它。有谁知道为什么我的程序卡在那条线上?
import speech_recognition as sr
print("Program has started!")
r = sr.Recognizer()
with sr.Microphone() as source:
print("Talk")
audio_text = r.listen(source)
print("Time over, thanks")
try:
# using google speech recognition
print("Text: "+r.recognize_google(audio_text))
except:
print("Sorry, I did not get that")
我在 Raspberry pi os 上运行它并使用 python3。