现在不建议使用duration参数。参考StackOverflow问题。
而是使用
phrase_time_limit或
timeout。
这是使用的代码块
phrase_time_limit:
import speech_recognition as srdef myCommand(): r = sr.Recognizer() with sr.Microphone() as source: audio = r.listen(source, phrase_time_limit = 5) try: command = r.recognize_google(audio).lower() print("you said: " + command) except sr.UnknownValueError: print("Sorry, Cant understand, Please say again") command = myCommand() return command这工作得很好。



