I am trying to create a voice assistant with Python. For many commands I use trigger words like "exit", "time", "quit" etc.
But since it keeps track of the voice, sometimes it picks up voice it shouldn't, like for the word "sentimental" it tells me the time. I have used word barriers (\\b), but I want singular words to work as well.
So "I acquitted him" wouldn't close the program. But "quit" or "please quit" would.
This is my current json setup:
{
"BasicOperations": {
"goodbye": ["'bye", "exit", "quit", "see you"],
"time": ["time ", "getting late"],
"calculations": ["+", "-", "*", "/", "^"]
}
}
And this is the code for checking:
# Tell the time
if any(string in query for string in commands["time"]):
engine.say('The time is ' + time)
engine.runAndWait()
# Quit the program
elif any(string in query for string in commands["goodbye"]):
engine.say("Good night sir! Have a nice sleep." if is_night else "Bye sir, have a great day!" )
engine.runAndWait()
exit()
elif any(string in query for string in commands["calculations"]):
#op1, op2 = int(op1), int(op2)
for op in commands["calculations"]:
if (op in query):
print(op)
#answer = get_operator_fn()(op1, op2)
engine.say("Good night sir! Have a nice sleep." if is_night else "Bye sir, have a great day!" )
engine.runAndWait()
exit()