我正在编写RPi 4并使代码正常工作,但是从麦克风上听我的语音识别对象的时间真的很长,几乎是10秒。这一次我想减少。我查看了语音识别库文档,但它没有提到任何地方的函数。
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))如何缩短听力时间?
发布于 2021-05-05 15:14:38
试试这个audio = r.listen(source, 10, 3)
发布于 2022-02-14 12:09:26
audio = r.listen(source, phrase_time_limit=3)您可以在设置phrase_time_limit的同时忽略其他可选参数。
文件上说:
phrase_time_limit参数是允许短语在停止之前继续并返回在到达时限之前处理的部分的最大秒数。产生的音频将是短语切断在时间限制。如果phrase_timeout为“无”,则不存在短语限制。
https://stackoverflow.com/questions/65641455
复制相似问题