我可以控制 pyttxs3 和 speech_recognition 将什么作为输入吗?

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

好吧,所以我尝试在嘈杂的区域使用 pyttxs3 和 speech_recognition,我的代码运行了很多时间,我假设它一直将噪音作为输入。所以我想知道是否可以提供一个计时器,例如,如果超过 2 分钟,它应该停止输入并运行代码,或者如果它听到像

okay
这样的特定单词,它应该停止输入。

这是我的代码示例: 将 speech_recognition 导入为 sr 导入 pyttsx3

r = sr.Recognizer()
with sr.Microphone() as source:
    print('Talk to me')
    audio =r.listen(source)
    text = r.recognize_google(audio)
    print('You said: ', text)

engine = pyttsx3.init()
engine.say("You said" + text)
engine.runAndWait()
python speech-recognition python-module pypi pyttsx3
© www.soinside.com 2019 - 2024. All rights reserved.