recognize_google 失败,出现 WinError 10060
我在用Python写程序的时候,遇到了一个TimeoutError: [WinError 10060]的错误。这种错误发生在连接的另一方没有在规定的时间内做出回应,或者已经建立的连接因为对方没有反应而失败。我觉得这个问题可能和recognize_google有关,因为程序在这行代码处停住了:
text = recognizer.recognize_google(audio)
代码示例:
import speech_recognition as sr
# Initialize the recognizer
recognizer = sr.Recognizer()
# Capture audio from the microphone
with sr.Microphone() as source:
print("Speak something...")
audio = recognizer.listen(source)
try:
# Use the recognizer to convert speech to text
text = recognizer.recognize_google(audio)
print("You said:", text)
except sr.UnknownValueError:
print("Sorry, could not understand audio.")
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
错误信息:
TimeoutError: [WinError 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
其他信息:
Python版本:3.7
PyAudio:0.2.11
playsound:1.2.2
0 个回答
暂无回答