如何解决Python语音助手唤醒单词检测
我在python中有一个正在运行的语音助手,但是目前它一直在监听,我理想地希望它开始听类似于“嘿Google”的唤醒字。
有人可以帮忙吗?
下面的代码段
voices = engine.getProperty('voices')
engine.setProperty('voice',voice_id)
keyword = "jarvis"
r = sr.Recognizer()
def speak(text):
engine.say(text)
engine.runAndWait()
def wishMe():
hour = datetime.datetime.now().hour
if 0 <= hour < 12:
speak("Hello chris,Good Morning")
print("Hello,Good Morning")
elif 12 <= hour < 18:
speak("Hello chris,Good Afternoon")
print("Hello,Good Afternoon")
else:
speak("Hello chris,Good Evening")
print("Hello,Good Evening")
def takeCommand():
with sr.Microphone() as source:
speak("yes chris...")
r.adjust_for_ambient_noise(source)
audio = r.listen(source,phrase_time_limit=5)
try:
statement = r.recognize_google(audio,language='en-uk')
print(f"user said:{statement}\n")
except Exception as e:
speak("sorry i couldn't understand")
return "None"
return statement
speak("Loading jarvis")
wishMe()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。