# 初始化识别器 recognizer = sr.Recognizer() with sr.Microphone() as source: audio = recognizer.listen(source) try: # 使用Google的语音识别 text = recognizer.recognize_google(audio) print("你今天完成了:" + text) except sr.UnknownValueError: print("Google Speech Recognition could not understand audio") except sr.RequestError as e: print("Could not request results from Google Speech Recognition service; {0}".format(e))