Vin*_*mar 0 python speech-recognition
代码停留在监听(audio=r.listen(source)行)并且不会超出它。没有错误消息或其他任何内容。
我的代码:
import speech_recognition as sr
def takeCommand():
'''
It takes user's voice as input
'''
r=sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio=r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language="en-in")
print(f"Recognized Command: {query}")
except Exception as e:
print(e)
print("I didn't recognize what you said please repeat")
return "None"
return query
takeCommand()
Run Code Online (Sandbox Code Playgroud)
我刚刚检查了您在评论中发布的链接。
有这样的代码:
with mic as source:
audio = r.listen(source)
Run Code Online (Sandbox Code Playgroud)
如果此代码不起作用,原因之一可能是麦克风拾取了过多的环境噪音。
解决方案可能是
with mic as source:
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
Run Code Online (Sandbox Code Playgroud)