试图用python制作语音识别程序,但该程序似乎听不到我的声音

问题描述 投票:0回答:1

每次我对着麦克风讲话时,第一个除外区都会运行,请帮助!

'''

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))

'''

python speech-recognition speech-to-text google-speech-to-text-api
1个回答
0
投票

我认为您的RequestError是Google API达到其极限的结果。 Google说:

大于1分钟的音频必须使用uri字段引用Google Cloud Storage中的音频文件。 See here for the documentation

因此您需要创建一个帐户here并使用给定的API密钥。然后将音频上传到云端,然后将该链接用作程序中的参数。

这是Google提供的唯一解决方案。希望对您有所帮助:)

© www.soinside.com 2019 - 2024. All rights reserved.