【发布时间】:2018-03-11 10:33:18
【问题描述】:
我正在使用 Speech_recognition 和 google gTTS 库创建一个基于 python 的命令行个人助理。我当前对启动词“Hey Siri”的实现是不断运行一个while循环并在每个循环中监听。
但它很慢而且不是真正连续的。所以很多时候都错过了演讲,有没有更好的选择?
while True:
listen()
def listen():
with sr.Microphone() as source:
audio = Listen.r.listen(source)
try:
recog_speech = str(Listen.r.recognize_google(audio))
if 'Hey Siri' in recog_speech:
print('I am listening')
#listen and do stuff
except Exception as e:
print('Something bad happened')
解决该问题的一个可能解决方案是不说话时不运行循环。
【问题讨论】:
-
您看过文档的Troubleshooting 部分吗?也许它试图识别太多,通过互联网,这显然会减慢速度并导致失误。你确定它只开始识别语音吗?
-
它总是运行,不管它是否检测到语音,返回一个异常。
标签: python terminal console-application speech-recognition