Update Jarvis2.py
This commit is contained in:
parent
2f2077a868
commit
935415f8f7
38
Jarvis2.py
38
Jarvis2.py
@ -12,6 +12,8 @@ import pyttsx3
|
|||||||
import speech_recognition as sr
|
import speech_recognition as sr
|
||||||
import wikipedia
|
import wikipedia
|
||||||
|
|
||||||
|
import gui
|
||||||
|
|
||||||
print("Initializing Jarvis....")
|
print("Initializing Jarvis....")
|
||||||
MASTER = getpass.getuser()
|
MASTER = getpass.getuser()
|
||||||
|
|
||||||
@ -46,6 +48,7 @@ def search(search_query, search_engine):
|
|||||||
|
|
||||||
|
|
||||||
def speak(text):
|
def speak(text):
|
||||||
|
gui.speak(text)
|
||||||
engine.say(text)
|
engine.say(text)
|
||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
|
|
||||||
@ -95,15 +98,18 @@ def take_command():
|
|||||||
|
|
||||||
speak("Initializing Jarvis....")
|
speak("Initializing Jarvis....")
|
||||||
wish_me()
|
wish_me()
|
||||||
query = take_command().lower()
|
|
||||||
|
|
||||||
# logic for executing basic tasks
|
|
||||||
if "wikipedia" in query.lower():
|
def execute_the_command_said_by_user():
|
||||||
|
query = take_command().lower()
|
||||||
|
|
||||||
|
# logic for executing basic tasks
|
||||||
|
if "wikipedia" in query:
|
||||||
speak("Searching wikipedia....")
|
speak("Searching wikipedia....")
|
||||||
query = query.replace("wikipedia", "")
|
query = query.replace("wikipedia", "")
|
||||||
print_and_speak(wikipedia.summary(query, sentences=2))
|
print_and_speak(wikipedia.summary(query, sentences=2))
|
||||||
|
|
||||||
elif "what's up" in query or "how are you" in query:
|
elif "what's up" in query or "how are you" in query:
|
||||||
st_msgs = (
|
st_msgs = (
|
||||||
"Just doing my thing!",
|
"Just doing my thing!",
|
||||||
"I am fine!",
|
"I am fine!",
|
||||||
@ -112,13 +118,13 @@ elif "what's up" in query or "how are you" in query:
|
|||||||
)
|
)
|
||||||
speak(random.choice(st_msgs))
|
speak(random.choice(st_msgs))
|
||||||
|
|
||||||
elif "date" in query:
|
elif "date" in query:
|
||||||
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
|
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
|
||||||
|
|
||||||
elif "time" in query:
|
elif "time" in query:
|
||||||
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
|
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
|
||||||
|
|
||||||
elif "open" in query.lower():
|
elif "open" in query.lower():
|
||||||
website = query.replace("open", "").strip().lower()
|
website = query.replace("open", "").strip().lower()
|
||||||
try:
|
try:
|
||||||
open_url(popular_websites[website])
|
open_url(popular_websites[website])
|
||||||
@ -126,12 +132,12 @@ elif "open" in query.lower():
|
|||||||
print(f"Unknown website: {website}")
|
print(f"Unknown website: {website}")
|
||||||
speak(f"Sorry, I don't know the website {website}")
|
speak(f"Sorry, I don't know the website {website}")
|
||||||
|
|
||||||
elif "search" in query.lower():
|
elif "search" in query.lower():
|
||||||
search_query = query.split("for")[-1]
|
search_query = query.split("for")[-1]
|
||||||
search_engine = query.split("for")[0].replace("search", "").strip().lower()
|
search_engine = query.split("for")[0].replace("search", "").strip().lower()
|
||||||
search(search_query, search_engine)
|
search(search_query, search_engine)
|
||||||
|
|
||||||
elif "email" in query:
|
elif "email" in query:
|
||||||
speak("Who is the recipient? ")
|
speak("Who is the recipient? ")
|
||||||
recipient = take_command()
|
recipient = take_command()
|
||||||
|
|
||||||
@ -150,19 +156,19 @@ elif "email" in query:
|
|||||||
except Exception:
|
except Exception:
|
||||||
speak("Sorry Sir! 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:
|
elif "nothing" in query or "abort" in query or "stop" in query:
|
||||||
speak("okay")
|
speak("okay")
|
||||||
speak("Bye Sir, have a good day.")
|
speak("Bye Sir, have a good day.")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif "hello" in query:
|
elif "hello" in query:
|
||||||
speak("Hello Sir")
|
speak("Hello Sir")
|
||||||
|
|
||||||
elif "bye" in query:
|
elif "bye" in query:
|
||||||
speak("Bye Sir, have a good day.")
|
speak("Bye Sir, have a good day.")
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif "play music" in query:
|
elif "play music" in query:
|
||||||
music_folder = "Your_music_folder_path(absolute_path)"
|
music_folder = "Your_music_folder_path(absolute_path)"
|
||||||
music = ("music1", "music2", "music3", "music4", "music5")
|
music = ("music1", "music2", "music3", "music4", "music5")
|
||||||
random_music = music_folder + random.choice(music) + ".mp3"
|
random_music = music_folder + random.choice(music) + ".mp3"
|
||||||
@ -170,4 +176,8 @@ elif "play music" in query:
|
|||||||
|
|
||||||
speak("Playing your request")
|
speak("Playing your request")
|
||||||
|
|
||||||
speak("Next Command! Sir!")
|
speak("Next Command! Sir!")
|
||||||
|
|
||||||
|
|
||||||
|
gui.set_speak_command(execute_the_command_said_by_user)
|
||||||
|
gui.mainloop()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user