diff --git a/Jarvis2.py b/Jarvis2.py index a86f25c..657ed84 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,81 +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() diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 5dfef30..4681632 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -1,29 +1,30 @@ -import configparser -import os +import configparser # isort: skip +import os # isort: skip -import speech_recognition as sr - -from actions import ( - change_rate, - change_voice, - change_volume, - search_engine_selector, - speak, - wish_me, +import gui # isort: skip +import speech_recognition as sr # isort: skip +from actions import ( # isort: skip + change_rate, + change_voice, + change_volume, + search_engine_selector, + set_gui_speak, + speak, + wish_me ) -from commands import ( - command_bye, - command_hello, - command_mail, - command_nothing, - command_open, - command_pause_music, - command_play_music, - command_search, - command_stop_music, - command_unpause_music, - command_whatsup, - command_wikipedia, +from commands import ( # isort: skip + command_bye, + command_hello, + command_mail, + command_nothing, + command_open, + command_pause_music, + command_play_music, + command_search, + command_stop_music, + command_unpause_music, + command_whatsup, + command_wikipedia ) popular_websites = { @@ -36,7 +37,7 @@ popular_websites = { def main(search_engine, take_command, debug): - while True: + def execute_the_command_said_by_user(): query = take_command() # logic for executing commands without arguments @@ -85,6 +86,9 @@ def main(search_engine, take_command, debug): change_volume(query, take_command) speak("Next Command! Sir!") + gui.set_speak_command(execute_the_command_said_by_user) + set_gui_speak(gui.speak) + gui.mainloop() def run(): diff --git a/actions.py b/actions.py index 4dea1e3..5b28a52 100644 --- a/actions.py +++ b/actions.py @@ -44,7 +44,17 @@ def search(search_query, search_engine): open_url(f"{search_engine}/search?q={search_query}") +def gui_speak(text): + pass + + +def set_gui_speak(command): + global gui_speak + gui_speak = command + + def speak(text): + gui_speak(text) engine.say(text) engine.runAndWait() diff --git a/gui.py b/gui.py new file mode 100644 index 0000000..9bd6397 --- /dev/null +++ b/gui.py @@ -0,0 +1,29 @@ +import tkinter as tk + +root = tk.Tk() +main_frame = tk.Frame(master=root) +chat_listbox = tk.Listbox(master=main_frame, height=200, width=50) +scroll_bar = tk.Scrollbar(master=main_frame) +speak_button = tk.Button(master=root, text='Speak', command=lambda: None) + + +def set_speak_command(command): + speak_button.configure(command=command) + + +speak_button.pack(side=tk.LEFT, anchor=tk.SW) + + +def speak(text): + chat_listbox.insert('end', f'Assistant: {text}') + root.geometry('700x500') + + +chat_listbox.pack(fill=tk.Y, side=tk.LEFT) +scroll_bar.pack(side=tk.RIGHT, fill=tk.Y) +scroll_bar.configure(command=chat_listbox.yview) +chat_listbox.configure(yscrollcommand=scroll_bar.set) +main_frame.pack(fill=tk.BOTH) +root.wm_title('Desktop assistant') +root.resizable(False, False) +mainloop = root.mainloop