A brute solution would be to check if both of the commands are in the variable voice
def response(voice):
if 'saat ka?' in voice and 'Asistan kapan' in voice:
speak("which one would you like me to do first?")
new_voice = record()
response(new_voice)
else:
if 'saat ka?' in voice: #saat ka? = what time is it
speak(datetime.now().strftime('%H:%M:%S'))
if 'Asistan kapan' in voice: #asistan kapan = assistant shutdown
speak("g?rü?ürüz") #g?rü?ürüz = bye
exit()
But i wouldn't recommend this because as you add new commands you have to keep updating the new if statement that i've added.
Instead make the user say words like "and" when giving multiple commands. Now you can split the command based on that word and run each command.
def split_command(voice):
commands = voice.split(" and ") # splits the command into multiple parts for each " and " that means command like "what time is it and assistant shutdown" would become ["what time is it", "assistant shutdown"]
for command in commands:
response(command) # now for each command in the list it is calling the response function
def response(voice):
if 'saat ka?' in voice: #saat ka? = what time is it
speak(datetime.now().strftime('%H:%M:%S'))
elif 'Asistan kapan' in voice: #asistan kapan = assistant shutdown
speak("g?rü?ürüz") #g?rü?ürüz = bye
exit()
# now instead of multiple ifs you can use elif
# now inside the infinite while loop call split_command function instead of the response function
while True:
voice = record()
print(voice)
split_command(voice)
I have added a comment next to all of the new code that i've added. I'm happy to help if you are still confused.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…