每次我对着麦克风讲话时,第一个除外区都会运行,请帮助!
'''
import speech_recognition as sr
# get audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak:")
audio = r.listen(source)
try:
print("You said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
'''
我认为您的RequestError
是Google API达到其极限的结果。 Google说:
大于1分钟的音频必须使用uri字段引用Google Cloud Storage中的音频文件。 See here for the documentation
因此您需要创建一个帐户here并使用给定的API密钥。然后将音频上传到云端,然后将该链接用作程序中的参数。
这是Google提供的唯一解决方案。希望对您有所帮助:)