From ef9defa759e2dbdb76e144ced02a57513dc80d14 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Wed, 6 Oct 2021 21:48:16 +0200 Subject: [PATCH 01/26] windows version upgraded. Organized code, added config file and config reading, fixed 2 bugs and added a debug mode in wich you can type commands in the console instead of saying them. --- Jarvis2_4windows.py | 326 ++++++++++++++++++++++++-------------------- config.ini | 13 ++ 2 files changed, 194 insertions(+), 145 deletions(-) create mode 100644 config.ini diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index bb9aa14..c879f8d 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -9,166 +9,202 @@ import wikipedia from pygame import mixer -mixer.init() +import configparser +import os -print("Initializing Jarvis....") -MASTER = "Tony Stark" +mixer.init() engine = pyttsx3.init("sapi5") voices = engine.getProperty("voices") engine.setProperty("voice", voices[0].id) -popular_websites = { - "google": "https://www.google.com", - "youtube": "https://www.youtube.com", - "wikipedia": "https://www.wikipedia.org", - "amazon": "https://www.amazon.com", -} -search_engines = { - "google": "https://www.google.com", - "youtube": "https://www.youtube.com", - "bing": "https://www.bing.com", -} +def search_engine_selector(): + + if config['DEFAULT']['search_engine'] == 'Google': + return "https://www.google.com" + elif config['DEFAULT']['search_engine'] == 'Bing': + return "https://www.bing.com" + elif config['DEFAULT']['search_engine'] == 'DuckDuckGo': + return "https://www.duckduckgo.com" + elif config['DEFAULT']['search_engine'] == 'Youtube': + return "https://www.youtube.com" + else: + return f"https://www.{config['DEFAULT']['search_engine'].lower()}.com" def open_url(url): - webbrowser.open(url) - chrome_path = r"open -a /Applications/Google\ Chrome.app %s" - webbrowser.get(chrome_path).open(url) - + webbrowser.open(url) + chrome_path = r"open -a /Applications/Google\ Chrome.app %s" + webbrowser.get(chrome_path).open(url) def search(search_query, search_engine): - try: - open_url(f"{search_engines[search_engine]}/search?q={search_query}") - except IndexError: - open_url(f"https://www.google.com/search?q={search_query}") - + open_url(f"{search_engine}/search?q={search_query}") def speak(text): - engine.say(text) - engine.runAndWait() + engine.say(text) + engine.runAndWait() + +def wishMe(MASTER): + hour = datetime.datetime.now().hour + # print(hour) + if hour >= 0 and hour < 12: + speak("Good Morning" + MASTER) + + elif hour >= 12 and hour < 18: + speak("Good Afternoon" + MASTER) + + else: + speak("Good Evening" + MASTER) + + # speak("Hey I am Jarvis. How may I help you") + +def main(): + MASTER = config['DEFAULT']['MASTER'] + popular_websites = { + "google": "https://www.google.com", + "youtube": "https://www.youtube.com", + "wikipedia": "https://www.wikipedia.org", + "amazon": "https://www.amazon.com", + } -def wishMe(): - hour = datetime.datetime.now().hour - # print(hour) - if hour >= 0 and hour < 12: - speak("Good Morning" + MASTER) + search_engine = search_engine_selector() - elif hour >= 12 and hour < 18: - speak("Good Afternoon" + MASTER) + debug = config['DEFAULT']['debug'] + if debug == "True": + def takeCommand(): + query = input("Command |--> ") + return query else: - speak("Good Evening" + MASTER) - - # speak("Hey I am Jarvis. How may I help you") - - -# This is where our programme begins.... -def takeCommand(): - r = sr.Recognizer() - with sr.Microphone() as source: - print("Listening....") - r.pause_threshold = 0.5 - audio = r.listen(source) - - query = " " - try: - print("Recognizing....") - query = r.recognize_google(audio, language="en-in") - print("user said: " + query) - - except sr.UnknownValueError: - print("Sorry Could You please try again") - - except Exception as e: - print(e) - print("Say That Again Please") - query = None - - return query - - -speak("Initializing Jarvis....") -wishMe() -while True: - query = takeCommand() - - # logic for executing basic tasks - if "wikipedia" in query.lower(): - speak("Searching wikipedia....") - query = query.replace("wikipedia", "") - results = wikipedia.summary(query, sentences=2) - print(results) - speak(results) - - elif "what's up" in query or "how are you" in query: - stMsgs = [ - "Just doing my thing!", - "I am fine!", - "Nice!", - "I am nice and full of energy", - ] - speak(random.choice(stMsgs)) - - 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 "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 "mail" in query: - speak("Who is the recipient? ") - recipient = takeCommand() - - if "me" in recipient: + def takeCommand(): + r = sr.Recognizer() + with sr.Microphone() as source: + if debug == "True":print("Listening....") + else:pass + r.pause_threshold = 0.5 + audio = r.listen(source) + + query = " " try: - speak("What should I say? ") - content = takeCommand() - - 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 "nothing" in query or "abort" in query or "stop" in query: - speak("okay") - speak("Bye Sir, have a good day.") - sys.exit() - - elif "hello" in query: - speak("Hello 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") - random_music = music_folder + random.choice(music) + ".mp3" - speak("Playing your request") - mixer.music.load(random_music) - mixer.music.play() - - elif "pause music" in query: - mixer.music.pause() - - elif "stop music" in query: - mixer.music.stop() - - elif "unpause" in query: - mixer.music.unpause() - - speak("Next Command! Sir!") + if debug == "True":print("Recognizing....") + else:pass + query = r.recognize_google(audio, language="en-in") + if debug == "True":print("user said: " + query) + else:pass + + except sr.UnknownValueError: + if debug == "True":print("Sorry Could You please try again") + else:pass + speak("Sorry Could You please try again") + + except Exception as e: + if debug == "True": + print(e) + print("Say That Again Please") + else:pass + query = None + + return query + + speak("Initializing Jarvis....") + wishMe(MASTER) + while True: + query = takeCommand() + + # logic for executing basic tasks + if "wikipedia" in query.lower(): + speak("Searching wikipedia....") + query = query.replace("wikipedia", "") + results = wikipedia.summary(query, sentences=2) + if debug == "True":print(results) + else:pass + speak(results) + + elif "what's up" in query or "how are you" in query: + stMsgs = [ + "Just doing my thing!", + "I am fine!", + "Nice!", + "I am nice and full of energy", + ] + speak(random.choice(stMsgs)) + + elif "open" in query.lower(): + website = query.replace("open", "").strip().lower() + try: + open_url(popular_websites[website]) + except KeyError: # If the website is unknown + if debug == "True":print(f"Unknown website: {website}") + else:pass + speak(f"Sorry, i don't know the website {website}") + speak(f"¿Do you want me to search {website} in the web?") + if takeCommand() == "yes": + search(website, search_engine ) + else: + pass + + + elif "search" in query.lower(): + search_query = query.split("for")[-1] + search(search_query, search_engine) + + elif "mail" in query: + speak("Who is the recipient? ") + recipient = takeCommand() + + if "me" in recipient: + try: + speak("What should I say? ") + content = takeCommand() + + server = smtplib.SMTP(config['EMAIL']['server'], config['EMAIL']['port']) + server.ehlo() + server.starttls() + server.login(config['EMAIL']['username'], config['EMAIL']['password']) + server.sendmail(config['EMAIL']['username'], recipient, content) + server.close() + speak("Email sent!") + except Exception: + speak("Sorry Sir! I am unable to send your message at this moment!") + + elif "nothing" in query or "abort" in query or "stop" in query: + speak("okay") + speak("Bye Sir, have a good day.") + sys.exit() + + elif "hello" in query: + speak("Hello Sir") + + elif "bye" in query: + speak("Bye Sir, have a good day.") + sys.exit() + + elif "play music" in query: + try: + music_folder = "Your_music_folder_path(absolute_path)" + music = ("music1", "music2", "music3", "music4") + random_music = music_folder + random.choice(music) + ".mp3" + speak("Playing your request") + mixer.music.load(random_music) + mixer.music.play() + except Exception as e: + speak(e) + + + elif "pause music" in query: + mixer.music.pause() + + elif "stop music" in query: + mixer.music.stop() + + elif "unpause" in query: + mixer.music.unpause() + + speak("Next Command! Sir!") + +if os.path.isfile('./config.ini'): + config = configparser.ConfigParser() + config.read('config.ini') + main() +else: + print('You need a config.ini file. Check the documentation in the Github Repository.') \ No newline at end of file diff --git a/config.ini b/config.ini new file mode 100644 index 0000000..6799f7f --- /dev/null +++ b/config.ini @@ -0,0 +1,13 @@ +[DEFAULT] +MASTER = YourName +search_engine = Google + #Google/Bing/DuckDuckGo/Youtube +debug = True + #True/False +[EMAIL] +server = smtp.gmail.com + #You can use any email service provider that allows SMTP. Check docs to see how to configure your email provider here. +port = 587 + #In most cases you will need this port. +username = +password = From 750a84706d2902c58d1a3b42bb0dd3d2d00b9df6 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Wed, 6 Oct 2021 22:12:24 +0200 Subject: [PATCH 02/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index c879f8d..5ae7edc 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -3,14 +3,15 @@ import smtplib import sys import webbrowser - import pyttsx3 -import speech_recognition as sr import wikipedia -from pygame import mixer - import configparser import os +import requests + +import speech_recognition as sr + +from pygame import mixer mixer.init() @@ -18,8 +19,8 @@ voices = engine.getProperty("voices") engine.setProperty("voice", voices[0].id) -def search_engine_selector(): - + +def search_engine_selector(): # this funcition checks wich search engine is selected in config file. if config['DEFAULT']['search_engine'] == 'Google': return "https://www.google.com" elif config['DEFAULT']['search_engine'] == 'Bing': @@ -28,8 +29,14 @@ def search_engine_selector(): return "https://www.duckduckgo.com" elif config['DEFAULT']['search_engine'] == 'Youtube': return "https://www.youtube.com" - else: - return f"https://www.{config['DEFAULT']['search_engine'].lower()}.com" + else: #If none of default ones selected it tries to use https://{config['DEFAULT']['search_engine'].lower()}.com as search engine. + #if its a valid url, it returns it as the search engine. + try: + if requests.get(f"https://{config['DEFAULT']['search_engine'].lower()}.com", params= {'q':'example'}).status_code == 200: + return f"https://{config['DEFAULT']['search_engine'].lower()}.com" + + else: return "https://www.google.com" + except: return "https://www.google.com" def open_url(url): webbrowser.open(url) @@ -202,9 +209,9 @@ def takeCommand(): speak("Next Command! Sir!") -if os.path.isfile('./config.ini'): - config = configparser.ConfigParser() - config.read('config.ini') - main() +if os.path.isfile('./config.ini'): #Checks if config.ini exists. + config = configparser.ConfigParser() #if exists loads library. + config.read('config.ini') #and also the file. + main() #Then launchs the main program else: - print('You need a config.ini file. Check the documentation in the Github Repository.') \ No newline at end of file + print('You need a config.ini file. Check the documentation in the Github Repository.') #if it doesn't exist it drops an error message and exits. \ No newline at end of file From a378db0ab6dcdf3380119a5e4c68f1c7efae7f99 Mon Sep 17 00:00:00 2001 From: Dasemu <24dasemu@gmail.com> Date: Wed, 6 Oct 2021 22:23:57 +0200 Subject: [PATCH 03/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 5ae7edc..22428fd 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -20,7 +20,7 @@ engine.setProperty("voice", voices[0].id) -def search_engine_selector(): # this funcition checks wich search engine is selected in config file. +def search_engine_selector(): # this funcition checks which search engine is selected in config file. if config['DEFAULT']['search_engine'] == 'Google': return "https://www.google.com" elif config['DEFAULT']['search_engine'] == 'Bing': @@ -212,6 +212,6 @@ def takeCommand(): if os.path.isfile('./config.ini'): #Checks if config.ini exists. config = configparser.ConfigParser() #if exists loads library. config.read('config.ini') #and also the file. - main() #Then launchs the main program + main() #Then launches the main program else: - print('You need a config.ini file. Check the documentation in the Github Repository.') #if it doesn't exist it drops an error message and exits. \ No newline at end of file + print('You need a config.ini file. Check the documentation in the Github Repository.') #if it doesn't exist it drops an error message and exits. From d6004eac289a6c276c83c5af77b4dda673cce683 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 16:05:57 +0200 Subject: [PATCH 04/26] Improving Code to met flake 8 requirements --- Jarvis2_4windows.py | 114 ++++++++++++++++++++++++++------------------ config.ini | 4 +- 2 files changed, 69 insertions(+), 49 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 5ae7edc..6c326ea 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -20,7 +20,8 @@ engine.setProperty("voice", voices[0].id) -def search_engine_selector(): # this funcition checks wich search engine is selected in config file. +# this funcition checks wich search engine is selected in config file. +def search_engine_selector(): if config['DEFAULT']['search_engine'] == 'Google': return "https://www.google.com" elif config['DEFAULT']['search_engine'] == 'Bing': @@ -29,40 +30,52 @@ def search_engine_selector(): # this funcition checks wich search engine is sel return "https://www.duckduckgo.com" elif config['DEFAULT']['search_engine'] == 'Youtube': return "https://www.youtube.com" - else: #If none of default ones selected it tries to use https://{config['DEFAULT']['search_engine'].lower()}.com as search engine. - #if its a valid url, it returns it as the search engine. + else: + # If none of default ones selected try: - if requests.get(f"https://{config['DEFAULT']['search_engine'].lower()}.com", params= {'q':'example'}).status_code == 200: - return f"https://{config['DEFAULT']['search_engine'].lower()}.com" - - else: return "https://www.google.com" - except: return "https://www.google.com" + if requests.get( + f"https://{config['DEFAULT']['search_engine'].lower()}.com", + params={'q': 'example'} + ).status_code == 200: + return ( + f"https://{config['DEFAULT']['search_engine'].lower()}.com" + ) + else: + return "https://www.google.com" + except Exception as e: + print(e) + return "https://www.google.com" + def open_url(url): - webbrowser.open(url) - chrome_path = r"open -a /Applications/Google\ Chrome.app %s" - webbrowser.get(chrome_path).open(url) + webbrowser.open(url) + chrome_path = r"open -a /Applications/Google\ Chrome.app %s" + webbrowser.get(chrome_path).open(url) + def search(search_query, search_engine): open_url(f"{search_engine}/search?q={search_query}") + def speak(text): - engine.say(text) - engine.runAndWait() + engine.say(text) + engine.runAndWait() + def wishMe(MASTER): - hour = datetime.datetime.now().hour - # print(hour) - if hour >= 0 and hour < 12: - speak("Good Morning" + MASTER) + hour = datetime.datetime.now().hour + # print(hour) + if hour >= 0 and hour < 12: + speak("Good Morning" + MASTER) - elif hour >= 12 and hour < 18: - speak("Good Afternoon" + MASTER) + elif hour >= 12 and hour < 18: + speak("Good Afternoon" + MASTER) - else: - speak("Good Evening" + MASTER) + else: + speak("Good Evening" + MASTER) + + # speak("Hey I am Jarvis. How may I help you") - # speak("Hey I am Jarvis. How may I help you") def main(): MASTER = config['DEFAULT']['MASTER'] @@ -86,29 +99,29 @@ def takeCommand(): def takeCommand(): r = sr.Recognizer() with sr.Microphone() as source: - if debug == "True":print("Listening....") - else:pass + print("Listening....") r.pause_threshold = 0.5 audio = r.listen(source) query = " " try: - if debug == "True":print("Recognizing....") - else:pass + print("Recognizing....") query = r.recognize_google(audio, language="en-in") - if debug == "True":print("user said: " + query) - else:pass + print("user said: " + query) except sr.UnknownValueError: - if debug == "True":print("Sorry Could You please try again") - else:pass + if debug == "True": + print("Sorry Could You please try again") + else: + pass speak("Sorry Could You please try again") except Exception as e: if debug == "True": print(e) print("Say That Again Please") - else:pass + else: + pass query = None return query @@ -123,8 +136,10 @@ def takeCommand(): speak("Searching wikipedia....") query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=2) - if debug == "True":print(results) - else:pass + if debug == "True": + print(results) + else: + pass speak(results) elif "what's up" in query or "how are you" in query: @@ -141,16 +156,17 @@ def takeCommand(): try: open_url(popular_websites[website]) except KeyError: # If the website is unknown - if debug == "True":print(f"Unknown website: {website}") - else:pass + if debug == "True": + print(f"Unknown website: {website}") + else: + pass speak(f"Sorry, i don't know the website {website}") speak(f"¿Do you want me to search {website} in the web?") if takeCommand() == "yes": - search(website, search_engine ) + search(website, search_engine) else: pass - elif "search" in query.lower(): search_query = query.split("for")[-1] search(search_query, search_engine) @@ -164,15 +180,17 @@ def takeCommand(): speak("What should I say? ") content = takeCommand() - server = smtplib.SMTP(config['EMAIL']['server'], config['EMAIL']['port']) + email = config['EMAIL'] + server = smtplib.SMTP(email['server'], email['port']) server.ehlo() server.starttls() - server.login(config['EMAIL']['username'], config['EMAIL']['password']) - server.sendmail(config['EMAIL']['username'], recipient, content) + server.login(email['username'], email['password']) + server.sendmail(email['username'], recipient, content) server.close() speak("Email sent!") except Exception: - speak("Sorry Sir! I am unable to send your message at this moment!") + speak("Sorry Sir!") + speak("I am unable to send your message at this moment!") elif "nothing" in query or "abort" in query or "stop" in query: speak("okay") @@ -197,7 +215,6 @@ def takeCommand(): except Exception as e: speak(e) - elif "pause music" in query: mixer.music.pause() @@ -209,9 +226,12 @@ def takeCommand(): speak("Next Command! Sir!") -if os.path.isfile('./config.ini'): #Checks if config.ini exists. - config = configparser.ConfigParser() #if exists loads library. - config.read('config.ini') #and also the file. - main() #Then launchs the main program + +if os.path.isfile('./config.ini'): # Checks if config.ini exists. + config = configparser.ConfigParser() # if exists loads library. + config.read('config.ini') # and also the file. + main() # Then launchs the main program else: - print('You need a config.ini file. Check the documentation in the Github Repository.') #if it doesn't exist it drops an error message and exits. \ No newline at end of file + # if it doesn't exist it drops an error message and exits. + print('You need a config.ini file.') + print('Check the documentation in the Github Repository.') diff --git a/config.ini b/config.ini index 6799f7f..e4e5d32 100644 --- a/config.ini +++ b/config.ini @@ -1,8 +1,8 @@ [DEFAULT] MASTER = YourName -search_engine = Google +search_engine = Google #Google/Bing/DuckDuckGo/Youtube -debug = True +debug = False #True/False [EMAIL] server = smtp.gmail.com From 8acc3da1349edc0dc73f967ab33bf6e97aac5f63 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 16:09:11 +0200 Subject: [PATCH 05/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 115 ++++++++++++++++++++++++++++---------------- 1 file changed, 74 insertions(+), 41 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 22428fd..b7199ee 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -20,7 +20,12 @@ engine.setProperty("voice", voices[0].id) +<<<<<<< HEAD +# this funcition checks wich search engine is selected in config file. +def search_engine_selector(): +======= def search_engine_selector(): # this funcition checks which search engine is selected in config file. +>>>>>>> 05cd5b49df1eb083cc6e39fb9b246fd6630aa75f if config['DEFAULT']['search_engine'] == 'Google': return "https://www.google.com" elif config['DEFAULT']['search_engine'] == 'Bing': @@ -29,40 +34,52 @@ def search_engine_selector(): # this funcition checks which search engine is se return "https://www.duckduckgo.com" elif config['DEFAULT']['search_engine'] == 'Youtube': return "https://www.youtube.com" - else: #If none of default ones selected it tries to use https://{config['DEFAULT']['search_engine'].lower()}.com as search engine. - #if its a valid url, it returns it as the search engine. + else: + # If none of default ones selected try: - if requests.get(f"https://{config['DEFAULT']['search_engine'].lower()}.com", params= {'q':'example'}).status_code == 200: - return f"https://{config['DEFAULT']['search_engine'].lower()}.com" - - else: return "https://www.google.com" - except: return "https://www.google.com" + if requests.get( + f"https://{config['DEFAULT']['search_engine'].lower()}.com", + params={'q': 'example'} + ).status_code == 200: + return ( + f"https://{config['DEFAULT']['search_engine'].lower()}.com" + ) + else: + return "https://www.google.com" + except Exception as e: + print(e) + return "https://www.google.com" + def open_url(url): - webbrowser.open(url) - chrome_path = r"open -a /Applications/Google\ Chrome.app %s" - webbrowser.get(chrome_path).open(url) + webbrowser.open(url) + chrome_path = r"open -a /Applications/Google\ Chrome.app %s" + webbrowser.get(chrome_path).open(url) + def search(search_query, search_engine): open_url(f"{search_engine}/search?q={search_query}") + def speak(text): - engine.say(text) - engine.runAndWait() + engine.say(text) + engine.runAndWait() + def wishMe(MASTER): - hour = datetime.datetime.now().hour - # print(hour) - if hour >= 0 and hour < 12: - speak("Good Morning" + MASTER) + hour = datetime.datetime.now().hour + # print(hour) + if hour >= 0 and hour < 12: + speak("Good Morning" + MASTER) - elif hour >= 12 and hour < 18: - speak("Good Afternoon" + MASTER) + elif hour >= 12 and hour < 18: + speak("Good Afternoon" + MASTER) - else: - speak("Good Evening" + MASTER) + else: + speak("Good Evening" + MASTER) + + # speak("Hey I am Jarvis. How may I help you") - # speak("Hey I am Jarvis. How may I help you") def main(): MASTER = config['DEFAULT']['MASTER'] @@ -86,29 +103,29 @@ def takeCommand(): def takeCommand(): r = sr.Recognizer() with sr.Microphone() as source: - if debug == "True":print("Listening....") - else:pass + print("Listening....") r.pause_threshold = 0.5 audio = r.listen(source) query = " " try: - if debug == "True":print("Recognizing....") - else:pass + print("Recognizing....") query = r.recognize_google(audio, language="en-in") - if debug == "True":print("user said: " + query) - else:pass + print("user said: " + query) except sr.UnknownValueError: - if debug == "True":print("Sorry Could You please try again") - else:pass + if debug == "True": + print("Sorry Could You please try again") + else: + pass speak("Sorry Could You please try again") except Exception as e: if debug == "True": print(e) print("Say That Again Please") - else:pass + else: + pass query = None return query @@ -123,8 +140,10 @@ def takeCommand(): speak("Searching wikipedia....") query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=2) - if debug == "True":print(results) - else:pass + if debug == "True": + print(results) + else: + pass speak(results) elif "what's up" in query or "how are you" in query: @@ -141,16 +160,17 @@ def takeCommand(): try: open_url(popular_websites[website]) except KeyError: # If the website is unknown - if debug == "True":print(f"Unknown website: {website}") - else:pass + if debug == "True": + print(f"Unknown website: {website}") + else: + pass speak(f"Sorry, i don't know the website {website}") speak(f"¿Do you want me to search {website} in the web?") if takeCommand() == "yes": - search(website, search_engine ) + search(website, search_engine) else: pass - elif "search" in query.lower(): search_query = query.split("for")[-1] search(search_query, search_engine) @@ -164,15 +184,17 @@ def takeCommand(): speak("What should I say? ") content = takeCommand() - server = smtplib.SMTP(config['EMAIL']['server'], config['EMAIL']['port']) + email = config['EMAIL'] + server = smtplib.SMTP(email['server'], email['port']) server.ehlo() server.starttls() - server.login(config['EMAIL']['username'], config['EMAIL']['password']) - server.sendmail(config['EMAIL']['username'], recipient, content) + server.login(email['username'], email['password']) + server.sendmail(email['username'], recipient, content) server.close() speak("Email sent!") except Exception: - speak("Sorry Sir! I am unable to send your message at this moment!") + speak("Sorry Sir!") + speak("I am unable to send your message at this moment!") elif "nothing" in query or "abort" in query or "stop" in query: speak("okay") @@ -197,7 +219,6 @@ def takeCommand(): except Exception as e: speak(e) - elif "pause music" in query: mixer.music.pause() @@ -209,9 +230,21 @@ def takeCommand(): speak("Next Command! Sir!") +<<<<<<< HEAD + +if os.path.isfile('./config.ini'): # Checks if config.ini exists. + config = configparser.ConfigParser() # if exists loads library. + config.read('config.ini') # and also the file. + main() # Then launchs the main program +else: + # if it doesn't exist it drops an error message and exits. + print('You need a config.ini file.') + print('Check the documentation in the Github Repository.') +======= if os.path.isfile('./config.ini'): #Checks if config.ini exists. config = configparser.ConfigParser() #if exists loads library. config.read('config.ini') #and also the file. main() #Then launches the main program else: print('You need a config.ini file. Check the documentation in the Github Repository.') #if it doesn't exist it drops an error message and exits. +>>>>>>> 05cd5b49df1eb083cc6e39fb9b246fd6630aa75f From 0d19e93b3ccb5362158ede2a1db74e7c3869d32f Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 16:09:43 +0200 Subject: [PATCH 06/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index b7199ee..6c326ea 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -20,12 +20,8 @@ engine.setProperty("voice", voices[0].id) -<<<<<<< HEAD # this funcition checks wich search engine is selected in config file. def search_engine_selector(): -======= -def search_engine_selector(): # this funcition checks which search engine is selected in config file. ->>>>>>> 05cd5b49df1eb083cc6e39fb9b246fd6630aa75f if config['DEFAULT']['search_engine'] == 'Google': return "https://www.google.com" elif config['DEFAULT']['search_engine'] == 'Bing': @@ -230,7 +226,6 @@ def takeCommand(): speak("Next Command! Sir!") -<<<<<<< HEAD if os.path.isfile('./config.ini'): # Checks if config.ini exists. config = configparser.ConfigParser() # if exists loads library. @@ -240,11 +235,3 @@ def takeCommand(): # if it doesn't exist it drops an error message and exits. print('You need a config.ini file.') print('Check the documentation in the Github Repository.') -======= -if os.path.isfile('./config.ini'): #Checks if config.ini exists. - config = configparser.ConfigParser() #if exists loads library. - config.read('config.ini') #and also the file. - main() #Then launches the main program -else: - print('You need a config.ini file. Check the documentation in the Github Repository.') #if it doesn't exist it drops an error message and exits. ->>>>>>> 05cd5b49df1eb083cc6e39fb9b246fd6630aa75f From 59fab95aaec81ab49d960215bae0c6e7ec679084 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 16:11:28 +0200 Subject: [PATCH 07/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 6c326ea..6ff373b 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -20,7 +20,7 @@ engine.setProperty("voice", voices[0].id) -# this funcition checks wich search engine is selected in config file. +# this funcition checks which search engine is selected in config file. def search_engine_selector(): if config['DEFAULT']['search_engine'] == 'Google': return "https://www.google.com" @@ -230,7 +230,7 @@ def takeCommand(): if os.path.isfile('./config.ini'): # Checks if config.ini exists. config = configparser.ConfigParser() # if exists loads library. config.read('config.ini') # and also the file. - main() # Then launchs the main program + main() # Then it launches the main program else: # if it doesn't exist it drops an error message and exits. print('You need a config.ini file.') From cb3cb604b15bc1eb2844afaafff9b41bfb175616 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 16:16:42 +0200 Subject: [PATCH 08/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 108 +++++++++++++++++++++++--------------------- 1 file changed, 56 insertions(+), 52 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 6ff373b..50eec1b 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -19,6 +19,13 @@ voices = engine.getProperty("voices") engine.setProperty("voice", voices[0].id) +popular_websites = { + "google": "https://www.google.com", + "youtube": "https://www.youtube.com", + "wikipedia": "https://www.wikipedia.org", + "amazon": "https://www.amazon.com", + } + # this funcition checks which search engine is selected in config file. def search_engine_selector(): @@ -77,57 +84,7 @@ def wishMe(MASTER): # speak("Hey I am Jarvis. How may I help you") -def main(): - MASTER = config['DEFAULT']['MASTER'] - - popular_websites = { - "google": "https://www.google.com", - "youtube": "https://www.youtube.com", - "wikipedia": "https://www.wikipedia.org", - "amazon": "https://www.amazon.com", - } - - search_engine = search_engine_selector() - - debug = config['DEFAULT']['debug'] - - if debug == "True": - def takeCommand(): - query = input("Command |--> ") - return query - else: - def takeCommand(): - r = sr.Recognizer() - with sr.Microphone() as source: - print("Listening....") - r.pause_threshold = 0.5 - audio = r.listen(source) - - query = " " - try: - print("Recognizing....") - query = r.recognize_google(audio, language="en-in") - print("user said: " + query) - - except sr.UnknownValueError: - if debug == "True": - print("Sorry Could You please try again") - else: - pass - speak("Sorry Could You please try again") - - except Exception as e: - if debug == "True": - print(e) - print("Say That Again Please") - else: - pass - query = None - - return query - - speak("Initializing Jarvis....") - wishMe(MASTER) +def main(search_engine, takeCommand, debug): while True: query = takeCommand() @@ -227,10 +184,57 @@ def takeCommand(): speak("Next Command! Sir!") +def run(): + MASTER = config['DEFAULT']['MASTER'] + + search_engine = search_engine_selector() + + debug = config['DEFAULT']['debug'] + + if debug == "True": + def takeCommand(): + query = input("Command |--> ") + return query + else: + def takeCommand(): + r = sr.Recognizer() + with sr.Microphone() as source: + print("Listening....") + r.pause_threshold = 0.5 + audio = r.listen(source) + + query = " " + try: + print("Recognizing....") + query = r.recognize_google(audio, language="en-in") + print("user said: " + query) + + except sr.UnknownValueError: + if debug == "True": + print("Sorry Could You please try again") + else: + pass + speak("Sorry Could You please try again") + + except Exception as e: + if debug == "True": + print(e) + print("Say That Again Please") + else: + pass + query = None + + return query + + speak("Initializing Jarvis....") + wishMe(MASTER) + main(search_engine, takeCommand, debug) + + if os.path.isfile('./config.ini'): # Checks if config.ini exists. config = configparser.ConfigParser() # if exists loads library. config.read('config.ini') # and also the file. - main() # Then it launches the main program + run() # Then it launches the main program else: # if it doesn't exist it drops an error message and exits. print('You need a config.ini file.') From c11968cd91f11aeda6cbe6cabfa9100f1ac5f544 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 17:27:42 +0200 Subject: [PATCH 09/26] Changed execution estructure and fixed bugs --- Jarvis2_4windows.py | 181 +++++--------------- __pycache__/Jarvis2_4windows.cpython-37.pyc | Bin 0 -> 3577 bytes __pycache__/actions.cpython-37.pyc | Bin 0 -> 1709 bytes __pycache__/commands.cpython-37.pyc | Bin 0 -> 3414 bytes actions.py | 64 +++++++ commands.py | 115 +++++++++++++ config.ini | 3 +- 7 files changed, 222 insertions(+), 141 deletions(-) create mode 100644 __pycache__/Jarvis2_4windows.cpython-37.pyc create mode 100644 __pycache__/actions.cpython-37.pyc create mode 100644 __pycache__/commands.cpython-37.pyc create mode 100644 actions.py create mode 100644 commands.py diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 50eec1b..8f58f86 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -1,23 +1,27 @@ -import datetime -import random -import smtplib -import sys -import webbrowser -import pyttsx3 -import wikipedia import configparser import os -import requests - import speech_recognition as sr from pygame import mixer -mixer.init() +from actions import search_engine_selector, speak, wishMe + +from commands import ( + command_bye, + command_hello, + command_mail, + command_nothing, + command_pauseMusic, + command_playMusic, + command_stopMusic, + command_unpauseMusic, + command_whatsup, + command_wikipedia, + command_open, + command_search +) -engine = pyttsx3.init("sapi5") -voices = engine.getProperty("voices") -engine.setProperty("voice", voices[0].id) +mixer.init() popular_websites = { "google": "https://www.google.com", @@ -27,159 +31,56 @@ } -# this funcition checks which search engine is selected in config file. -def search_engine_selector(): - if config['DEFAULT']['search_engine'] == 'Google': - return "https://www.google.com" - elif config['DEFAULT']['search_engine'] == 'Bing': - return "https://www.bing.com" - elif config['DEFAULT']['search_engine'] == 'DuckDuckGo': - return "https://www.duckduckgo.com" - elif config['DEFAULT']['search_engine'] == 'Youtube': - return "https://www.youtube.com" - else: - # If none of default ones selected - try: - if requests.get( - f"https://{config['DEFAULT']['search_engine'].lower()}.com", - params={'q': 'example'} - ).status_code == 200: - return ( - f"https://{config['DEFAULT']['search_engine'].lower()}.com" - ) - else: - return "https://www.google.com" - except Exception as e: - print(e) - return "https://www.google.com" - - -def open_url(url): - webbrowser.open(url) - chrome_path = r"open -a /Applications/Google\ Chrome.app %s" - webbrowser.get(chrome_path).open(url) - - -def search(search_query, search_engine): - open_url(f"{search_engine}/search?q={search_query}") - - -def speak(text): - engine.say(text) - engine.runAndWait() - - -def wishMe(MASTER): - hour = datetime.datetime.now().hour - # print(hour) - if hour >= 0 and hour < 12: - speak("Good Morning" + MASTER) - - elif hour >= 12 and hour < 18: - speak("Good Afternoon" + MASTER) - - else: - speak("Good Evening" + MASTER) - - # speak("Hey I am Jarvis. How may I help you") - - def main(search_engine, takeCommand, debug): while True: query = takeCommand() # logic for executing basic tasks if "wikipedia" in query.lower(): - speak("Searching wikipedia....") - query = query.replace("wikipedia", "") - results = wikipedia.summary(query, sentences=2) - if debug == "True": - print(results) - else: - pass - speak(results) + command_wikipedia( + speak, + debug, + query + ) elif "what's up" in query or "how are you" in query: - stMsgs = [ - "Just doing my thing!", - "I am fine!", - "Nice!", - "I am nice and full of energy", - ] - speak(random.choice(stMsgs)) + command_whatsup() elif "open" in query.lower(): - website = query.replace("open", "").strip().lower() - try: - open_url(popular_websites[website]) - except KeyError: # If the website is unknown - if debug == "True": - print(f"Unknown website: {website}") - else: - pass - speak(f"Sorry, i don't know the website {website}") - speak(f"¿Do you want me to search {website} in the web?") - if takeCommand() == "yes": - search(website, search_engine) - else: - pass + command_open( + query, + popular_websites, + debug, + search_engine, + takeCommand + ) elif "search" in query.lower(): - search_query = query.split("for")[-1] - search(search_query, search_engine) + command_search(query, search_engine) elif "mail" in query: - speak("Who is the recipient? ") - recipient = takeCommand() - - if "me" in recipient: - try: - speak("What should I say? ") - content = takeCommand() - - email = config['EMAIL'] - server = smtplib.SMTP(email['server'], email['port']) - server.ehlo() - server.starttls() - server.login(email['username'], email['password']) - server.sendmail(email['username'], recipient, content) - server.close() - speak("Email sent!") - except Exception: - speak("Sorry Sir!") - speak("I am unable to send your message at this moment!") + command_mail(takeCommand) elif "nothing" in query or "abort" in query or "stop" in query: - speak("okay") - speak("Bye Sir, have a good day.") - sys.exit() + command_nothing() elif "hello" in query: - speak("Hello Sir") + command_hello() elif "bye" in query: - speak("Bye Sir, have a good day.") - sys.exit() + command_bye() elif "play music" in query: - try: - music_folder = "Your_music_folder_path(absolute_path)" - music = ("music1", "music2", "music3", "music4") - random_music = music_folder + random.choice(music) + ".mp3" - speak("Playing your request") - mixer.music.load(random_music) - mixer.music.play() - except Exception as e: - speak(e) + command_playMusic() elif "pause music" in query: - mixer.music.pause() + command_pauseMusic() elif "stop music" in query: - mixer.music.stop() + command_stopMusic elif "unpause" in query: - mixer.music.unpause() + command_unpauseMusic() speak("Next Command! Sir!") @@ -187,7 +88,7 @@ def main(search_engine, takeCommand, debug): def run(): MASTER = config['DEFAULT']['MASTER'] - search_engine = search_engine_selector() + search_engine = search_engine_selector(config) debug = config['DEFAULT']['debug'] @@ -226,7 +127,7 @@ def takeCommand(): return query - speak("Initializing Jarvis....") + speak(text="Initializing Jarvis....") wishMe(MASTER) main(search_engine, takeCommand, debug) diff --git a/__pycache__/Jarvis2_4windows.cpython-37.pyc b/__pycache__/Jarvis2_4windows.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c7c10263557dc2096f3acc7e25b339f9a1146b5c GIT binary patch literal 3577 zcmZ8kOOG4J5$<`A96t7;)oLHIqKq6{HVuoiWyJvuLzcXfBRSSa(XJzz5U`nLx5yEP zGjw;;6bGaak&`%po%kH&z&+-claU{gV@^Ky$v}Vr`3pYftLA7Un~SOHuBxuCM|V~4 zyGu(ohTj*BgXniB8T&U)p8iT0T*asU3BVb564qW|r|sCe+jcGX+MdOJ+qbyXE(5zs zWe~Ijht_yWbx>>92K9D*&}cU-%}RT`5K#4?jbS6zn4Mo&9<#DWfw*>@G zbh5!9O8LP!?#DyHi#dmQ6_S-r_U!g8Pciv)H3nXg^#&Hbr= z9P0 zt=c@)j+{-#&uy|<9qXRA`<#5VK0h_B)8)`K-k@FK*{g+Tu6)^HGhE5MfxI_p%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L9(&e`?3>TJF+b}}$?Po8?0gsP))n(UmG7fHO%)1A z1zMx0_8^vUWaSUaE{J>zidx(uzEtL=U@p)p6F2XhC6CP#gQ?1uBIf3mY2IVz`Zo8Z z;XlJKChbkGnUG70fFzg5yHuSQ!{DQS&WluhOqZ=9!-=iT&u-cqAl!x%ECr2VE%1U% MfgiY#P1NrH06Yu~NdN!< literal 0 HcmV?d00001 diff --git a/actions.py b/actions.py new file mode 100644 index 0000000..956db21 --- /dev/null +++ b/actions.py @@ -0,0 +1,64 @@ +import webbrowser +import requests +import datetime +import pyttsx3 + +engine = pyttsx3.init("sapi5") +voices = engine.getProperty("voices") +engine.setProperty("voice", voices[0].id) + + +def search_engine_selector(config): + if config['DEFAULT']['search_engine'] == 'Google': + return "https://www.google.com" + elif config['DEFAULT']['search_engine'] == 'Bing': + return "https://www.bing.com" + elif config['DEFAULT']['search_engine'] == 'DuckDuckGo': + return "https://www.duckduckgo.com" + elif config['DEFAULT']['search_engine'] == 'Youtube': + return "https://www.youtube.com" + else: + # If none of default ones selected + try: + if requests.get( + f"https://{config['DEFAULT']['search_engine'].lower()}.com", + params={'q': 'example'} + ).status_code == 200: + return ( + f"https://{config['DEFAULT']['search_engine'].lower()}.com" + ) + else: + return "https://www.google.com" + except Exception as e: + print(e) + return "https://www.google.com" + + +def open_url(url): + webbrowser.open(url) + chrome_path = r"open -a /Applications/Google\ Chrome.app %s" + webbrowser.get(chrome_path).open(url) + + +def search(search_query, search_engine): + open_url(f"{search_engine}/search?q={search_query}") + + +def speak(text): + engine.say(text) + engine.runAndWait() + + +def wishMe(MASTER): + hour = datetime.datetime.now().hour + # print(hour) + if hour >= 0 and hour < 12: + speak("Good Morning" + MASTER) + + elif hour >= 12 and hour < 18: + speak("Good Afternoon" + MASTER) + + else: + speak("Good Evening" + MASTER) + + # speak("Hey I am Jarvis. How may I help you") diff --git a/commands.py b/commands.py new file mode 100644 index 0000000..47185f3 --- /dev/null +++ b/commands.py @@ -0,0 +1,115 @@ +import wikipedia +import smtplib +import sys +import random +import configparser + +from pygame import mixer + +from actions import open_url, search, speak + +config = configparser.ConfigParser() # if exists loads library. +config.read('config.ini') + + +def command_wikipedia(debug, query): + speak("Searching wikipedia....") + query = query.replace("wikipedia", "") + results = wikipedia.summary(query, sentences=2) + if debug == "True": + print(results) + else: + pass + speak(results) + + +def command_whatsup(): + stMsgs = [ + "Just doing my thing!", + "I am fine!", + "Nice!", + "I am nice and full of energy", + ] + speak(random.choice(stMsgs)) + + +def command_open(query, popular_websites, debug, search_engine, takeCommand): + website = query.replace("open", "").strip().lower() + try: + open_url(popular_websites[website]) + except KeyError: # If the website is unknown + if debug == "True": + print(f"Unknown website: {website}") + else: + pass + speak(f"Sorry, i don't know the website {website}") + speak(f"¿Do you want me to search {website} in the web?") + if takeCommand() == "yes": + search(website, search_engine) + else: + pass + + +def command_search(query, search_engine): + search_query = query.split("for")[-1] + search(search_query, search_engine) + + +def command_mail(takeCommand): + speak("Who is the recipient? ") + recipient = takeCommand() + + try: + speak("What should I say? ") + content = takeCommand() + + email = config['EMAIL'] + server = smtplib.SMTP(email['server'], email['port']) + server.ehlo() + server.starttls() + server.login(email['username'], email['password']) + server.sendmail(email['username'], recipient, content) + server.close() + speak("Email sent!") + except Exception: + speak("Sorry Sir!") + speak("I am unable to send your message at this moment!") + + +def command_nothing(): + speak("okay") + speak("Bye Sir, have a good day.") + sys.exit() + + +def command_hello(): + speak("Hello Sir") + + +def command_bye(): + speak("Bye Sir, have a good day.") + sys.exit() + + +def command_playMusic(): + try: + music_folder = config['DEFAULT']['musicPath'] + music = ("music1", "music2", "music3", "music4") + random_music = music_folder + random.choice(music) + ".mp3" + speak("Playing your request") + mixer.music.load(random_music) + mixer.music.play() + except Exception as e: + speak(e) + + +def command_pauseMusic(): + mixer.music.pause() + + +def command_stopMusic(): + mixer.music.stop() + + +def command_unpauseMusic(): + mixer.music.unpause() diff --git a/config.ini b/config.ini index e4e5d32..b8f9bd0 100644 --- a/config.ini +++ b/config.ini @@ -2,8 +2,9 @@ MASTER = YourName search_engine = Google #Google/Bing/DuckDuckGo/Youtube -debug = False +debug = True #True/False +musicPath = [EMAIL] server = smtp.gmail.com #You can use any email service provider that allows SMTP. Check docs to see how to configure your email provider here. From 44a2ddf936af94eacca20d701c70466621bfa1e1 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 17:31:11 +0200 Subject: [PATCH 10/26] fixed imports --- Jarvis2_4windows.py | 21 +++++---------------- actions.py | 5 +++-- commands.py | 6 +++--- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 8f58f86..0b72dc1 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -1,25 +1,14 @@ import configparser import os -import speech_recognition as sr +import speech_recognition as sr from pygame import mixer from actions import search_engine_selector, speak, wishMe - -from commands import ( - command_bye, - command_hello, - command_mail, - command_nothing, - command_pauseMusic, - command_playMusic, - command_stopMusic, - command_unpauseMusic, - command_whatsup, - command_wikipedia, - command_open, - command_search -) +from commands import (command_bye, command_hello, command_mail, + command_nothing, command_open, command_pauseMusic, + command_playMusic, command_search, command_stopMusic, + command_unpauseMusic, command_whatsup, command_wikipedia) mixer.init() diff --git a/actions.py b/actions.py index 956db21..ab0464a 100644 --- a/actions.py +++ b/actions.py @@ -1,7 +1,8 @@ -import webbrowser -import requests import datetime +import webbrowser + import pyttsx3 +import requests engine = pyttsx3.init("sapi5") voices = engine.getProperty("voices") diff --git a/commands.py b/commands.py index 47185f3..34694d6 100644 --- a/commands.py +++ b/commands.py @@ -1,9 +1,9 @@ -import wikipedia +import configparser +import random import smtplib import sys -import random -import configparser +import wikipedia from pygame import mixer from actions import open_url, search, speak From f7542a5ae68bb6fc3a8ec325f0e9c69a135311ce Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 17:36:59 +0200 Subject: [PATCH 11/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 0b72dc1..22836d3 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -2,7 +2,6 @@ import os import speech_recognition as sr -from pygame import mixer from actions import search_engine_selector, speak, wishMe from commands import (command_bye, command_hello, command_mail, @@ -10,8 +9,6 @@ command_playMusic, command_search, command_stopMusic, command_unpauseMusic, command_whatsup, command_wikipedia) -mixer.init() - popular_websites = { "google": "https://www.google.com", "youtube": "https://www.youtube.com", From 1fada104ae1b2c3a803b8c071dd5bd155043ef0c Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 17:38:48 +0200 Subject: [PATCH 12/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 22836d3..05088f1 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -4,10 +4,20 @@ import speech_recognition as sr from actions import search_engine_selector, speak, wishMe -from commands import (command_bye, command_hello, command_mail, - command_nothing, command_open, command_pauseMusic, - command_playMusic, command_search, command_stopMusic, - command_unpauseMusic, command_whatsup, command_wikipedia) +from commands import ( + command_bye, + command_hello, + command_mail, + command_nothing, + command_open, + command_pauseMusic, + command_playMusic, + command_search, + command_stopMusic, + command_unpauseMusic, + command_whatsup, + command_wikipedia, +) popular_websites = { "google": "https://www.google.com", From 4a06c8fa4c1b1c85ab5f4db2be119459da28eb7d Mon Sep 17 00:00:00 2001 From: Dasemu <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 17:59:45 +0200 Subject: [PATCH 13/26] Update config.ini --- config.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.ini b/config.ini index b8f9bd0..4c9f381 100644 --- a/config.ini +++ b/config.ini @@ -2,7 +2,7 @@ MASTER = YourName search_engine = Google #Google/Bing/DuckDuckGo/Youtube -debug = True +debug = False #True/False musicPath = [EMAIL] From 4584b6f18c21475d2cea45af174c2d76eec02434 Mon Sep 17 00:00:00 2001 From: Dasemu <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 20:21:26 +0200 Subject: [PATCH 14/26] Update Jarvis2_4windows.py Co-authored-by: Christian Clauss --- Jarvis2_4windows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 05088f1..76b8a9a 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -73,7 +73,7 @@ def main(search_engine, takeCommand, debug): command_pauseMusic() elif "stop music" in query: - command_stopMusic + command_stopMusic() elif "unpause" in query: command_unpauseMusic() From 0682bbe1d3a7079c9dff632a510a41984b51565d Mon Sep 17 00:00:00 2001 From: Dasemu <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 20:21:48 +0200 Subject: [PATCH 15/26] Update Jarvis2_4windows.py Co-authored-by: Christian Clauss --- Jarvis2_4windows.py | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 76b8a9a..95b91b5 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -33,11 +33,7 @@ def main(search_engine, takeCommand, debug): # logic for executing basic tasks if "wikipedia" in query.lower(): - command_wikipedia( - speak, - debug, - query - ) + command_wikipedia(speak, debug, query) elif "what's up" in query or "how are you" in query: command_whatsup() From 76afa5bf537e83456497d0ddb916f92d188be60b Mon Sep 17 00:00:00 2001 From: Dasemu <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 20:27:30 +0200 Subject: [PATCH 16/26] Update Jarvis2_4windows.py Co-authored-by: Christian Clauss --- Jarvis2_4windows.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 95b91b5..39a666e 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -10,11 +10,11 @@ command_mail, command_nothing, command_open, - command_pauseMusic, - command_playMusic, + command_pause_music, + command_play_music, command_search, - command_stopMusic, - command_unpauseMusic, + command_stop_music, + command_unpause_music, command_whatsup, command_wikipedia, ) From 38b70f4d2258c92a054685033249c4c7fb926738 Mon Sep 17 00:00:00 2001 From: Dasemu <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 20:27:39 +0200 Subject: [PATCH 17/26] Update Jarvis2_4windows.py Co-authored-by: Christian Clauss --- Jarvis2_4windows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 39a666e..1c15894 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -29,7 +29,7 @@ def main(search_engine, takeCommand, debug): while True: - query = takeCommand() + query = takeCommand().lower() # logic for executing basic tasks if "wikipedia" in query.lower(): From f2305ab68526e98f9c8e86ef54a94db70d1fb1c5 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Thu, 7 Oct 2021 20:47:16 +0200 Subject: [PATCH 18/26] Included 4th request by cclauss and fixed bugs now its easier to use commands without arguments --- Jarvis2_4windows.py | 43 ++++++++++++---------------- __pycache__/actions.cpython-37.pyc | Bin 1709 -> 1709 bytes __pycache__/commands.cpython-37.pyc | Bin 3414 -> 3418 bytes commands.py | 8 +++--- 4 files changed, 22 insertions(+), 29 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 1c15894..21281e2 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -31,13 +31,27 @@ def main(search_engine, takeCommand, debug): while True: query = takeCommand().lower() - # logic for executing basic tasks + # logic for executing commands without arguments + phrases = { + "what's up": command_whatsup, + "nothing": command_nothing, + "abort": command_nothing, + "stop": command_nothing, + "hello": command_hello, + "bye": command_bye, + "play music": command_play_music, + "unpause": command_unpause_music, + "pause music": command_pause_music, + "stop music": command_stop_music, + } + for phrase, command in phrases.items(): + if phrase in query: + command() + + # logic for executing commands with arguments if "wikipedia" in query.lower(): command_wikipedia(speak, debug, query) - elif "what's up" in query or "how are you" in query: - command_whatsup() - elif "open" in query.lower(): command_open( query, @@ -53,27 +67,6 @@ def main(search_engine, takeCommand, debug): elif "mail" in query: command_mail(takeCommand) - elif "nothing" in query or "abort" in query or "stop" in query: - command_nothing() - - elif "hello" in query: - command_hello() - - elif "bye" in query: - command_bye() - - elif "play music" in query: - command_playMusic() - - elif "pause music" in query: - command_pauseMusic() - - elif "stop music" in query: - command_stopMusic() - - elif "unpause" in query: - command_unpauseMusic() - speak("Next Command! Sir!") diff --git a/__pycache__/actions.cpython-37.pyc b/__pycache__/actions.cpython-37.pyc index 711448d270f0b2e50ceb891baa9b8c58cc3b3a50..86bdcf1e1198310a911be0fdb98f2824d115358a 100644 GIT binary patch delta 129 zcmZ3>yOx*NiINiIHbA5A$P2waFitTN!mGm$6hc8f^Z= z!pvx53RGLn1Jc3B!z94S2g1xn3P8Rle~}E3DiQ(`QS1ekB_+ib#zh=J-egU-LSZHj VMh+$}MlMDnW)3M1HVzgJRsgRN7Cry~ delta 129 zcmZ3>yOx*NiIf{g1t&G}}%UG%z^*4WF zVP-Tj0je$L0qJ1mVG>~E17YSO1t4FOzeos36>)$F86XkGUQk(5Qe0s?S(B|$n302# UgNcigi&2P~LyCiqgN1_?0CSHO)c^nh diff --git a/__pycache__/commands.cpython-37.pyc b/__pycache__/commands.cpython-37.pyc index 97cea7bd17e75ac7719e2ebe4ec98e7d66f574f3..f2dd31265c8a39d0c0b3a05350ee5ca0f5980033 100644 GIT binary patch delta 267 zcmca6bxVrZiIi!+n6fJPNFfed6UvWBWun!K4?N&#+GaY=pw zL~$OHVq3Ukbskx7QJB%Cc?Af=i;&dY1KFBVw|J8C^U^ZY3lfWpQ;Uj(fPzIDAi@Ad numOpv$$dO&0+t}IHHfeU5%!Z0a!5>;;gw`&;$WO?!7B#<0*^-( delta 285 zcmca5bxn%biI@J47cs%^W2=`1&O7_sbD=>AU#ZA zJw-N9HA<7Wa!bj>%`Yy=F955}LsDx8SF6P%>m>qnOKBd$=prQL4nVf1R1q7HD$)QE z1|S0D)>}Nu`FUxX=>>^J#i>QNCQsr?6R-kF+JFc<5aBTSAcw?c1zt&JMh>RQHoS5G D=Zr=o diff --git a/commands.py b/commands.py index 34694d6..575fc16 100644 --- a/commands.py +++ b/commands.py @@ -91,7 +91,7 @@ def command_bye(): sys.exit() -def command_playMusic(): +def command_play_music(): try: music_folder = config['DEFAULT']['musicPath'] music = ("music1", "music2", "music3", "music4") @@ -103,13 +103,13 @@ def command_playMusic(): speak(e) -def command_pauseMusic(): +def command_pause_music(): mixer.music.pause() -def command_stopMusic(): +def command_stop_music(): mixer.music.stop() -def command_unpauseMusic(): +def command_unpause_music(): mixer.music.unpause() From b92bb6514ee8deec42905e491ca46197b77a38a8 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Fri, 8 Oct 2021 18:28:43 +0200 Subject: [PATCH 19/26] created requirements.txt --- __pycache__/gui.cpython-37.pyc | Bin 0 -> 1075 bytes __pycache__/tkscrolledframe.cpython-37.pyc | Bin 0 -> 6800 bytes requirements.txt | 10 ++++++++++ 3 files changed, 10 insertions(+) create mode 100644 __pycache__/gui.cpython-37.pyc create mode 100644 __pycache__/tkscrolledframe.cpython-37.pyc create mode 100644 requirements.txt diff --git a/__pycache__/gui.cpython-37.pyc b/__pycache__/gui.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..67ff71c2c13cc6b589d4ba4039963f56d1e83420 GIT binary patch literal 1075 zcmZ`%yKYo55Vd_Dd-weyNkNr%8w!Ldq9}q8LW(F98-!%7w0N(baQD7ewwI779clLq z5NKCa{E}NLJ^?DmPL?D{Sn|x+GxnT0GrP@Z4Z->~eaF5Lgnrn=Y6W0CgRQ=T;E3Z4 zQ4E@7B=@L?k-!UoiD)1^5pZvgX(+-)Mc_%a#Iy>!2KPP>czA_)W$w{Bk9hS8(T1o` zn&5B2Zu8olV8rXZ0iF(T@)qc>2wg;vx91o#1&ar~v%I#}c$asV@J0lab-K>+0QGx6 z0V6uQ%2zF6Vp((sL^<) zby=8dToxzE=}bc1F5VT$qp*@%vKV!)1wa zxHiDBxHNId$iiC!@D)1Z3Y50&zHf+5O>oG@A~Us|CB^8(Hpci<7N-EyM*R!32X%Y^ z!kJFWVwBmpT?kv@wDvt*fBEWxM*~-v=rj64KHV~QQMcVuwmn;$kkx+ipX7n#XZ=n- z`zs8Rf0AU`MfaxLn{4&ret*MMbea?}WwHsew5?NhGli~LX$dyuI5oa3OHErV?==^+ z#S=Bn*!k!z;ip2Iz|F2~+rPqH*IQYIgX@sALt*^Gm;1+*4Bom@q=iWR-PgwlG&;*i zI?|k!3zB%jq4e-I%+vh_>^R&oZ%Nhfh5O5#a`ja1A%`niu&!*pc6I F=Rcn4@^%0K literal 0 HcmV?d00001 diff --git a/__pycache__/tkscrolledframe.cpython-37.pyc b/__pycache__/tkscrolledframe.cpython-37.pyc new file mode 100644 index 0000000000000000000000000000000000000000..d139d4eba81e3528b2308375822007e7613d9ad7 GIT binary patch literal 6800 zcmb7J+ix6K8K2wE&aT&v9oxAyX?p4c$s*SvCTGl?s&#M zGaK8hjf7|gJdg?`BoN}k5l=`+{0ICW%o7sgA^!jpJOID%oSD6tw5aQx+c)R(ec$=6 zCpV_2s|J4mJa`mrUNelp(V+Nw=)8@RJV3>bhQUp4g=WK4t<|uPXI0PHFEvW0@z97C z97DL>s{EE|(BB6}Wc|S4_O96|f7jp+w?D>6*d6a9yHVlRmQgSDSKi$}2*tjL(jaZe z5sO`W#%4CXrM?TkK_8n0EPggRZ=)nXMHG?yB`~k5-)QPt;;LCinh$Bcnz&5JfO$;G@rrjs;D-m_^W)D z&tX*KXZbwlO!Ec4h<1iA@pJqCVW{0s1`KwFI>^SbRW)QI?IDS)OL6{^hw#FuS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c5U8` literal 0 HcmV?d00001 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..ce28810 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +pygame==2.0.1 +pyttsx3==2.90 +SpeechRecognition==3.8.1 +wikipedia==1.4.0 +PyAudio==0.2.11 +pygame==2.0.1 +pyttsx3==2.90 +SpeechRecognition==3.8.1 +wikipedia==1.4.0 + From 6f5fece60e227d86e43d20b8aa49bbacdc052b31 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Fri, 8 Oct 2021 18:43:18 +0200 Subject: [PATCH 20/26] fixed everything --- Jarvis2.py | 11 ++++++----- Jarvis2_4windows.py | 5 ++--- actions.py | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Jarvis2.py b/Jarvis2.py index b37d890..67e13b6 100755 --- a/Jarvis2.py +++ b/Jarvis2.py @@ -13,7 +13,7 @@ import wikipedia print("Initializing Jarvis....") -MASTER = getpass.getuser() +master = getpass.getuser() engine = pyttsx3.init("nsss") voices = engine.getProperty("voices") @@ -58,11 +58,11 @@ def print_and_speak(text): def wish_me(): hour = datetime.datetime.now().hour if hour < 12: - speak("Good Morning" + MASTER) + speak("Good Morning" + master) elif hour < 18: - speak("Good Afternoon" + MASTER) + speak("Good Afternoon" + master) else: - speak("Good Evening" + MASTER) + speak("Good Evening" + master) # speak("Hey I am Jarvis. How may I help you") @@ -148,7 +148,8 @@ def take_command(): server.close() speak("Email sent!") except Exception: - speak("Sorry Sir! I am unable to send your message at this moment!") + speak("Sorry Sir!") + speak("I am unable to send your message at this moment!") elif "nothing" in query or "abort" in query or "stop" in query: speak("okay") diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index f6b1a5d..5287e1a 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -72,7 +72,7 @@ def main(search_engine, takeCommand, debug): def run(): - MASTER = config['DEFAULT']['MASTER'] + master = config['DEFAULT']['MASTER'] search_engine = search_engine_selector(config) @@ -114,7 +114,7 @@ def takeCommand(): return query speak(text="Initializing Jarvis....") - wishMe(MASTER) + wishMe(master) main(search_engine, takeCommand, debug) @@ -126,4 +126,3 @@ def takeCommand(): # if it doesn't exist it drops an error message and exits. print('You need a config.ini file.') print('Check the documentation in the Github Repository.') - diff --git a/actions.py b/actions.py index ab0464a..1d86ace 100644 --- a/actions.py +++ b/actions.py @@ -50,16 +50,16 @@ def speak(text): engine.runAndWait() -def wishMe(MASTER): +def wishMe(master): hour = datetime.datetime.now().hour # print(hour) if hour >= 0 and hour < 12: - speak("Good Morning" + MASTER) + speak("Good Morning" + master) elif hour >= 12 and hour < 18: - speak("Good Afternoon" + MASTER) + speak("Good Afternoon" + master) else: - speak("Good Evening" + MASTER) + speak("Good Evening" + master) # speak("Hey I am Jarvis. How may I help you") From 295e6fa322a5363b425829931c295c2b4ad43df5 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Fri, 8 Oct 2021 18:46:20 +0200 Subject: [PATCH 21/26] fixed everything 2 --- Jarvis2_4windows.py | 2 +- config.ini | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 5287e1a..436b23f 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -72,7 +72,7 @@ def main(search_engine, takeCommand, debug): def run(): - master = config['DEFAULT']['MASTER'] + master = config['DEFAULT']['master'] search_engine = search_engine_selector(config) diff --git a/config.ini b/config.ini index 4c9f381..a429e48 100644 --- a/config.ini +++ b/config.ini @@ -1,5 +1,5 @@ [DEFAULT] -MASTER = YourName +master = YourName search_engine = Google #Google/Bing/DuckDuckGo/Youtube debug = False From 3350726592cd4fdd465e5c558c450a964ce694bb Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Fri, 8 Oct 2021 18:53:12 +0200 Subject: [PATCH 22/26] fixed everything again --- Jarvis2_4windows.py | 26 ++++++++++++-------------- __pycache__/actions.cpython-37.pyc | Bin 1709 -> 1710 bytes __pycache__/commands.cpython-37.pyc | Bin 3418 -> 3420 bytes actions.py | 2 +- commands.py | 14 +++++++------- config.ini | 2 +- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 436b23f..845fc80 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -3,7 +3,7 @@ import speech_recognition as sr -from actions import search_engine_selector, speak, wishMe +from actions import search_engine_selector, speak, wish_me from commands import ( command_bye, command_hello, @@ -24,13 +24,13 @@ "youtube": "https://www.youtube.com", "wikipedia": "https://www.wikipedia.org", "amazon": "https://www.amazon.com", - "GitHub": "https://www.github.com", + "github": "https://www.github.com", } -def main(search_engine, takeCommand, debug): +def main(search_engine, take_command, debug): while True: - query = takeCommand().lower() + query = take_command().lower() # logic for executing commands without arguments phrases = { @@ -59,14 +59,14 @@ def main(search_engine, takeCommand, debug): popular_websites, debug, search_engine, - takeCommand + take_command ) elif "search" in query.lower(): command_search(query, search_engine) elif "mail" in query: - command_mail(takeCommand) + command_mail(take_command) speak("Next Command! Sir!") @@ -79,11 +79,10 @@ def run(): debug = config['DEFAULT']['debug'] if debug == "True": - def takeCommand(): - query = input("Command |--> ") - return query + def take_command(): + return input("Command |--> ") else: - def takeCommand(): + def take_command(): r = sr.Recognizer() with sr.Microphone() as source: print("Listening....") @@ -109,13 +108,12 @@ def takeCommand(): print("Say That Again Please") else: pass - query = None - return query + return None speak(text="Initializing Jarvis....") - wishMe(master) - main(search_engine, takeCommand, debug) + wish_me(master) + main(search_engine, take_command, debug) if os.path.isfile('./config.ini'): # Checks if config.ini exists. diff --git a/__pycache__/actions.cpython-37.pyc b/__pycache__/actions.cpython-37.pyc index 86bdcf1e1198310a911be0fdb98f2824d115358a..007000dcf2513c8289a04bd835c4150bc92fb26b 100644 GIT binary patch delta 61 zcmZ3>yN;LFiIlS-?W^qP*?&L45 FI{~u|4~PH& delta 60 zcmZ3-yOx*NiI= 0 and hour < 12: diff --git a/commands.py b/commands.py index 575fc16..c930b71 100644 --- a/commands.py +++ b/commands.py @@ -24,16 +24,16 @@ def command_wikipedia(debug, query): def command_whatsup(): - stMsgs = [ + st_msgs = [ "Just doing my thing!", "I am fine!", "Nice!", "I am nice and full of energy", ] - speak(random.choice(stMsgs)) + speak(random.choice(st_msgs)) -def command_open(query, popular_websites, debug, search_engine, takeCommand): +def command_open(query, popular_websites, debug, search_engine, take_command): website = query.replace("open", "").strip().lower() try: open_url(popular_websites[website]) @@ -44,7 +44,7 @@ def command_open(query, popular_websites, debug, search_engine, takeCommand): pass speak(f"Sorry, i don't know the website {website}") speak(f"¿Do you want me to search {website} in the web?") - if takeCommand() == "yes": + if take_command() == "yes": search(website, search_engine) else: pass @@ -55,13 +55,13 @@ def command_search(query, search_engine): search(search_query, search_engine) -def command_mail(takeCommand): +def command_mail(take_command): speak("Who is the recipient? ") - recipient = takeCommand() + recipient = take_command() try: speak("What should I say? ") - content = takeCommand() + content = take_command() email = config['EMAIL'] server = smtplib.SMTP(email['server'], email['port']) diff --git a/config.ini b/config.ini index a429e48..3b76e46 100644 --- a/config.ini +++ b/config.ini @@ -2,7 +2,7 @@ master = YourName search_engine = Google #Google/Bing/DuckDuckGo/Youtube -debug = False +debug = True #True/False musicPath = [EMAIL] From a2d5789db91bbf266fccefe120cb8e565b17fc05 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Fri, 8 Oct 2021 18:54:13 +0200 Subject: [PATCH 23/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index 845fc80..cf5c922 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -109,7 +109,7 @@ def take_command(): else: pass - return None + return speak(text="Initializing Jarvis....") wish_me(master) From 84113c17645da4f963ad0fea26513d6452713376 Mon Sep 17 00:00:00 2001 From: Dasemu <24dasemu@gmail.com> Date: Fri, 8 Oct 2021 20:12:33 +0200 Subject: [PATCH 24/26] Update Jarvis2.py Co-authored-by: Christian Clauss --- Jarvis2.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Jarvis2.py b/Jarvis2.py index 67e13b6..a86f25c 100755 --- a/Jarvis2.py +++ b/Jarvis2.py @@ -148,8 +148,9 @@ def take_command(): server.close() speak("Email sent!") except Exception: - speak("Sorry Sir!") - speak("I am unable to send your message at this moment!") + speak( + "Sorry, Sir! I am unable to send your message at this moment!" + ) elif "nothing" in query or "abort" in query or "stop" in query: speak("okay") From a4bed18e5bfc579261353efa1a960c2818082da1 Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Sat, 9 Oct 2021 12:46:14 +0200 Subject: [PATCH 25/26] Update Jarvis2_4windows.py --- Jarvis2_4windows.py | 99 ++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 51 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index a5403dc..b973dc9 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -37,57 +37,54 @@ def main(search_engine, take_command, debug): while True: - try: - query = take_command() - - # logic for executing commands without arguments - phrases = { - "what's up": command_whatsup, - "nothing": command_nothing, - "abort": command_nothing, - "stop": command_nothing, - "hello": command_hello, - "bye": command_bye, - "play music": command_play_music, - "unpause": command_unpause_music, - "pause music": command_pause_music, - "stop music": command_stop_music - } - for phrase, command in phrases.items(): - if phrase in query: - command() - - # logic for executing commands with arguments - if "wikipedia" in query: - command_wikipedia(speak, debug, query) - - elif "open" in query: - command_open( - query, - popular_websites, - debug, - search_engine, - take_command - ) - - elif "search" in query: - command_search(query, search_engine) - - elif "mail" in query: - command_mail(take_command) - - elif "change rate" in query: - change_rate(query, take_command) - - elif "change voice" in query.lower(): - change_voice(query, take_command) - - elif "change volume" in query.lower(): - change_volume(query, take_command) - - speak("Next Command! Sir!") - except Exception: - pass + query = take_command() + + # logic for executing commands without arguments + phrases = { + "what's up": command_whatsup, + "nothing": command_nothing, + "abort": command_nothing, + "stop": command_nothing, + "hello": command_hello, + "bye": command_bye, + "play music": command_play_music, + "unpause": command_unpause_music, + "pause music": command_pause_music, + "stop music": command_stop_music + } + for phrase, command in phrases.items(): + if phrase in query: + command() + + # logic for executing commands with arguments + if "wikipedia" in query: + command_wikipedia(speak, debug, query) + + elif "open" in query: + command_open( + query, + popular_websites, + debug, + search_engine, + take_command + ) + + elif "search" in query: + command_search(query, search_engine) + + elif "mail" in query: + command_mail(take_command) + + elif "change rate" in query: + change_rate(query, take_command) + + elif "change voice" in query.lower(): + change_voice(query, take_command) + + elif "change volume" in query.lower(): + change_volume(query, take_command) + + speak("Next Command! Sir!") def run(): From c7e24cf9d46fd55ae35f9f9264ece0d3119a169e Mon Sep 17 00:00:00 2001 From: TallGorilla <24dasemu@gmail.com> Date: Sat, 9 Oct 2021 12:47:49 +0200 Subject: [PATCH 26/26] fixed imports --- Jarvis2_4windows.py | 2 +- actions.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Jarvis2_4windows.py b/Jarvis2_4windows.py index b973dc9..5dfef30 100644 --- a/Jarvis2_4windows.py +++ b/Jarvis2_4windows.py @@ -4,9 +4,9 @@ import speech_recognition as sr from actions import ( - change_volume, change_rate, change_voice, + change_volume, search_engine_selector, speak, wish_me, diff --git a/actions.py b/actions.py index f33d84a..4dea1e3 100644 --- a/actions.py +++ b/actions.py @@ -1,9 +1,9 @@ +import configparser import datetime import webbrowser import pyttsx3 import requests -import configparser def search_engine_selector(config):