Делаю голосового помощника и столкнулся с проблемой. Вроде бы я закончил цикл, но все равно функция отвечает много раз.
Код:
def main():
commands = [greeting, jarvis, browser, vpn, telegram, viber, who_are_you, thank_you, youtube, fortnine, protocol_update,
protocol_studies, new_year, chatgpt]
while True:
recognized_commands = listen_command()
command_found = False
for recognized_command in recognized_commands:
for command in commands:
if recognized_command.lower() in command.activation_phrases:
command.execute()
command.voice_acting()
command_found = True
break
elif "какая сегодня дата" in recognized_command.lower():
command.date()
command_found = True
break
elif "закончи работу" in recognized_command.lower():
mus = pyglet.resource.media("Jarvis Sound Pack от Jarvis Desktop/Как пожелаете.wav")
mus.play()
pyglet.app.exit()
time.sleep(1)
exit()
elif "выключи пк" in recognized_command.lower():
command.Turn_Off_PC()
command_found = True
break
elif "выключи звук" in recognized_command.lower():
pyautogui.press("volumemute")
command_found = True
break
if not command_found:
Command.AI(recognized_command)
break