【发布时间】:2022-02-14 20:09:26
【问题描述】:
我正在研究 RPi 4 并且代码可以正常工作,但是从我的麦克风听我的语音识别对象的时间真的很长,几乎像 10 秒。我想减少这个时间。我查看了speech recognition library documentation,但它没有在任何地方提及该功能。
Python 编辑器给了我listen() 函数的以下提示;
self:识别器,来源,超时 = 无,phrase_time_limit = 无 snowboy_configuration =无
所以我尝试像这样调用函数:
audio = r.listen(source,None,3)
或者
audio = r.listen(source,3,3)
希望它会听 3 秒钟,但它不是那样工作的。
以下是我的代码:
import speech_recognition as sr
r = sr.Recognizer()
speech = sr.Microphone(2)
#print(sr.Microphone.list_microphone_names())
while 1:
with speech as source:
print("say something!…")
audio = r.adjust_for_ambient_noise(source)
audio = r.listen(source,None,3)
print("the audio has been recorded")
# Speech recognition using Google Speech Recognition
try:
print("api is enabled")
recog = r.recognize_google(audio, language = 'en-US')
# for testing purposes, we're just using the default API key
# to use another API key, use r.recognize_google(audio)
# instead of r.recognize_google(audio)
print("You said: " + recog)
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))
如何缩短收听时间?
【问题讨论】:
标签: python speech-recognition google-speech-api