我正在尝试使用
speech_recognition
模块制作一个 python AI,
我想在人工智能中添加一个热词检测功能,所以我尝试使用 speech_recognition
模块来实现它,但它不起作用。它在 4 - 5 秒后听了一次,并开始识别所说的内容。因此,如果我在 4-5 秒的时间范围后说出 hotword
,它不会识别 hotword
。
像
一样使用
pause_threshold
import speech_recognition as sr
hot_word='Hi'
r=sr.Recognizer()
r.pause_threshold=5#This waits for 5 sec after voice ends
with sr.Microphone() as source:
text=r.listen(source)
text=r.recognize_google(text)
if hot_word in text:
#do anything like calling a function or reply to it
谢谢你
祝你有美好的一天