我正在制作一个python脚本,它会监听您的声音,然后根据您所说的内容执行函数
我刚刚开始制作一个“唤醒词”,代码如下所示:
while True:
try:
with sr.Microphone() as source1:
SpeakText("one")
r.adjust_for_ambient_noise(source1)
print("Set minimum energy threshold to {}".format(r.energy_threshold))
SpeakText("two")
audio1 = r.listen(source)
SpeakText("three")
MyText = r.recognize_google(audio1)
print(MyText)
SpeakText("four")
MyText = MyText.lower()
if MyText == "oink" or "ink" or "link":
playsound("oink_boop.mp3")
detect_command()
except sr.UnknownValueError:
print("No Speech or No Internet")
现在我输入SpeakText部分(使用pyttsx3)只是为了调试目的,但它说“两个”,然后在audio1=r.listen(源代码)上听我的演讲时卡住了
它似乎没有停止听我说话,我甚至试着让麦克风静音,但也没用
您还应使用:
if 'oink' in MyText or ...
编辑: 用这个
我试过这个:
它仍然不起作用 我做错什么了吗
相关问题 更多 >
编程相关推荐