我已经开始开发我自己的虚拟助手了。这在几天前工作得很好,但我相信我搞砸了。它应该找出我输入的命令,然后响应,但它总是显示'greeting'-response。
from time import ctime
import time
import os
import requests, json
import random
import pyttsx3
engine = pyttsx3.init()
startup = ["Starting Ares...", "Booting up Ares..."]
selected_startup = random.choice(startup)
print(selected_startup)
engine.say(selected_startup)
engine.runAndWait()
command = input("Enter Command:")
def main():
commands()
def commands():
if command == "Hey" or "Hello" or "Hi" or "Ares":
greetings = ["Hello, sir. What can I help you with?", "How can I be of assistance today, sir?", "Yes?"]
selected_greeting = random.choice(greetings)
print(selected_greeting)
engine.say(selected_greeting)
engine.runAndWait()
elif command == "how are you":
print("I am well, thank you. What can I do for you?")
elif command == "What's the time?" or "What time is it?" or "What's the time, Ares?" or "What time is it, Ares" or "Time":
dates = ["Todays date is ", "Today is "]
selected_date = random.choice(dates)
print(ctime())
engine.say(selected_date + ctime)
engine.runAndWait
elif command == "Stop":
print("Shutting down...")
else:
print("I'm sorry, I didn't quite catch that.")
if __name__ == '__main__':
commands()例如,如果我说“嘿”,它应该以一个问候语响应,但无论我输入什么,它总是以问候语响应。
我不知道它出了什么问题。这可能真的很简单。谢谢你们:)
发布于 2021-04-17 00:30:02
噢!谢谢。问题是我用了
command == "something"不是使用
command in {"something"}再次感谢你
https://stackoverflow.com/questions/67120751
复制相似问题