From 935415f8f77b7630783231a2f941e8bb7cd48e4d Mon Sep 17 00:00:00 2001 From: "B.Jothin kumar" Date: Fri, 8 Oct 2021 12:30:04 +0530 Subject: [PATCH] Update Jarvis2.py --- Jarvis2.py | 132 ++++++++++++++++++++++++++++------------------------- 1 file changed, 71 insertions(+), 61 deletions(-) diff --git a/Jarvis2.py b/Jarvis2.py index b37d890..b6736e5 100755 --- a/Jarvis2.py +++ b/Jarvis2.py @@ -12,6 +12,8 @@ import pyttsx3 import speech_recognition as sr import wikipedia +import gui + print("Initializing Jarvis....") MASTER = getpass.getuser() @@ -46,6 +48,7 @@ def search(search_query, search_engine): def speak(text): + gui.speak(text) engine.say(text) engine.runAndWait() @@ -95,79 +98,86 @@ def take_command(): speak("Initializing Jarvis....") wish_me() -query = take_command().lower() -# logic for executing basic tasks -if "wikipedia" in query.lower(): - speak("Searching wikipedia....") - query = query.replace("wikipedia", "") - print_and_speak(wikipedia.summary(query, sentences=2)) -elif "what's up" in query or "how are you" in query: - st_msgs = ( - "Just doing my thing!", - "I am fine!", - "Nice!", - "I am nice and full of energy", - ) - speak(random.choice(st_msgs)) +def execute_the_command_said_by_user(): + query = take_command().lower() -elif "date" in query: - print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}") + # logic for executing basic tasks + if "wikipedia" in query: + speak("Searching wikipedia....") + query = query.replace("wikipedia", "") + print_and_speak(wikipedia.summary(query, sentences=2)) -elif "time" in query: - print_and_speak(f"{datetime.datetime.now():%I %M %p}") + elif "what's up" in query or "how are you" in query: + st_msgs = ( + "Just doing my thing!", + "I am fine!", + "Nice!", + "I am nice and full of energy", + ) + speak(random.choice(st_msgs)) -elif "open" in query.lower(): - website = query.replace("open", "").strip().lower() - try: - open_url(popular_websites[website]) - except IndexError: # If the website is unknown - print(f"Unknown website: {website}") - speak(f"Sorry, I don't know the website {website}") + elif "date" in query: + print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}") -elif "search" in query.lower(): - search_query = query.split("for")[-1] - search_engine = query.split("for")[0].replace("search", "").strip().lower() - search(search_query, search_engine) + elif "time" in query: + print_and_speak(f"{datetime.datetime.now():%I %M %p}") -elif "email" in query: - speak("Who is the recipient? ") - recipient = take_command() - - if "me" in recipient: + elif "open" in query.lower(): + website = query.replace("open", "").strip().lower() try: - speak("What should I say? ") - content = take_command() + open_url(popular_websites[website]) + except IndexError: # If the website is unknown + print(f"Unknown website: {website}") + speak(f"Sorry, I don't know the website {website}") - server = smtplib.SMTP("smtp.gmail.com", 587) - server.ehlo() - server.starttls() - server.login("Your_Username", "Your_Password") - server.sendmail("Your_Username", "Recipient_Username", content) - server.close() - speak("Email sent!") - except Exception: - speak("Sorry Sir! I am unable to send your message at this moment!") + elif "search" in query.lower(): + search_query = query.split("for")[-1] + search_engine = query.split("for")[0].replace("search", "").strip().lower() + search(search_query, search_engine) -elif "nothing" in query or "abort" in query or "stop" in query: - speak("okay") - speak("Bye Sir, have a good day.") - sys.exit() + elif "email" in query: + speak("Who is the recipient? ") + recipient = take_command() -elif "hello" in query: - speak("Hello Sir") + if "me" in recipient: + try: + speak("What should I say? ") + content = take_command() -elif "bye" in query: - speak("Bye Sir, have a good day.") - sys.exit() + server = smtplib.SMTP("smtp.gmail.com", 587) + server.ehlo() + server.starttls() + server.login("Your_Username", "Your_Password") + server.sendmail("Your_Username", "Recipient_Username", content) + server.close() + speak("Email sent!") + except Exception: + speak("Sorry Sir! I am unable to send your message at this moment!") -elif "play music" in query: - music_folder = "Your_music_folder_path(absolute_path)" - music = ("music1", "music2", "music3", "music4", "music5") - random_music = music_folder + random.choice(music) + ".mp3" - os.system(random_music) + elif "nothing" in query or "abort" in query or "stop" in query: + speak("okay") + speak("Bye Sir, have a good day.") + sys.exit() - speak("Playing your request") + elif "hello" in query: + speak("Hello Sir") -speak("Next Command! Sir!") + elif "bye" in query: + speak("Bye Sir, have a good day.") + sys.exit() + + elif "play music" in query: + music_folder = "Your_music_folder_path(absolute_path)" + music = ("music1", "music2", "music3", "music4", "music5") + random_music = music_folder + random.choice(music) + ".mp3" + os.system(random_music) + + speak("Playing your request") + + speak("Next Command! Sir!") + + +gui.set_speak_command(execute_the_command_said_by_user) +gui.mainloop()