首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何给出聆听python语音识别库的时间?

如何给出聆听python语音识别库的时间?
EN

Stack Overflow用户
提问于 2021-01-09 10:13:55
回答 2查看 3.3K关注 0票数 0

我正在编写RPi 4并使代码正常工作,但是从麦克风上听我的语音识别对象的时间真的很长,几乎是10秒。这一次我想减少。我查看了语音识别库文档,但它没有提到任何地方的函数。

Python编辑器提供了以下listen()函数的提示符;

self:识别器,源,超时=无,phrase_time_limit =无snowboy_configuration =无

所以我试着调用这个函数,比如:

代码语言:javascript
复制
audio = r.listen(source,None,3)

代码语言:javascript
复制
 audio = r.listen(source,3,3)

希望它能听3秒,但它不是那样工作的。

以下是我的代码:

代码语言:javascript
复制
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))

如何缩短听力时间?

EN

回答 2

Stack Overflow用户

发布于 2021-05-05 15:14:38

试试这个audio = r.listen(source, 10, 3)

票数 1
EN

Stack Overflow用户

发布于 2022-02-14 12:09:26

代码语言:javascript
复制
audio = r.listen(source, phrase_time_limit=3)

您可以在设置phrase_time_limit的同时忽略其他可选参数。

文件上说:

phrase_time_limit参数是允许短语在停止之前继续并返回在到达时限之前处理的部分的最大秒数。产生的音频将是短语切断在时间限制。如果phrase_timeout为“无”,则不存在短语限制。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65641455

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档