Oct-17-2020, 12:39 AM
so I'm working on an alarm for a virtual assistant the alarm is running in a while true loop while it waits for the time to go off. However I would like to leave that while loop to preform other functions with the virtual assistant but keep it running in the back ground is this possible here is the code let me know.
import datetime import os import random from gtts import gTTS from playsound import playsound def assistant_response(text): print(text) tts = gTTS(text=text, lang="en-US", slow=False, ) filename = "voicee.mp3" tts.save(filename) playsound(filename) while True: text = input("cmd: ") if "hi" in text: assistant_response("hi") elif "alarm" in text: alarm_hour = int(input("Set hour: ")) alarm_minutes = int(input("Set minutes: ")) am_pm = input("am or pm? ") print(f"Waiting for time: {alarm_hour}:{alarm_minutes} {am_pm}") if am_pm == 'pm': alarm_hour += 12 elif alarm_hour == 12 and am_pm == 'am': alarm_hour -= 12 else: pass while True: if alarm_hour == datetime.datetime.now().hour and alarm_minutes == datetime.datetime.now().minute: print("\nIt's the time!") assistant_response("alarm") break