我使用了下面的代码段,但是当通过麦克风进行输入时,它似乎没有监听。
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
r.adjust_for_ambient_noise(source, duration=10)
print("Say something ")
audio = r.listen(source)
try:
test = r.recognize_google(audio)
#print("you said :" + test)
print("you said: {}".format(test))
except:
print("sorry could not hear you")