commit
29ec429688
134
Jarvis2.py
134
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,81 +98,86 @@ 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():
|
|
||||||
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:
|
def execute_the_command_said_by_user():
|
||||||
st_msgs = (
|
query = take_command().lower()
|
||||||
"Just doing my thing!",
|
|
||||||
"I am fine!",
|
|
||||||
"Nice!",
|
|
||||||
"I am nice and full of energy",
|
|
||||||
)
|
|
||||||
speak(random.choice(st_msgs))
|
|
||||||
|
|
||||||
elif "date" in query:
|
# logic for executing basic tasks
|
||||||
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
|
if "wikipedia" in query:
|
||||||
|
speak("Searching wikipedia....")
|
||||||
|
query = query.replace("wikipedia", "")
|
||||||
|
print_and_speak(wikipedia.summary(query, sentences=2))
|
||||||
|
|
||||||
elif "time" in query:
|
elif "what's up" in query or "how are you" in query:
|
||||||
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
|
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():
|
elif "date" in query:
|
||||||
website = query.replace("open", "").strip().lower()
|
print_and_speak(f"{datetime.datetime.now():%A, %B %d, %Y}")
|
||||||
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():
|
elif "time" in query:
|
||||||
search_query = query.split("for")[-1]
|
print_and_speak(f"{datetime.datetime.now():%I %M %p}")
|
||||||
search_engine = query.split("for")[0].replace("search", "").strip().lower()
|
|
||||||
search(search_query, search_engine)
|
|
||||||
|
|
||||||
elif "email" in query:
|
elif "open" in query.lower():
|
||||||
speak("Who is the recipient? ")
|
website = query.replace("open", "").strip().lower()
|
||||||
recipient = take_command()
|
|
||||||
|
|
||||||
if "me" in recipient:
|
|
||||||
try:
|
try:
|
||||||
speak("What should I say? ")
|
open_url(popular_websites[website])
|
||||||
content = take_command()
|
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)
|
elif "search" in query.lower():
|
||||||
server.ehlo()
|
search_query = query.split("for")[-1]
|
||||||
server.starttls()
|
search_engine = query.split("for")[0].replace("search", "").strip().lower()
|
||||||
server.login("Your_Username", "Your_Password")
|
search(search_query, search_engine)
|
||||||
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:
|
elif "email" in query:
|
||||||
speak("okay")
|
speak("Who is the recipient? ")
|
||||||
speak("Bye Sir, have a good day.")
|
recipient = take_command()
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
elif "hello" in query:
|
if "me" in recipient:
|
||||||
speak("Hello Sir")
|
try:
|
||||||
|
speak("What should I say? ")
|
||||||
|
content = take_command()
|
||||||
|
|
||||||
elif "bye" in query:
|
server = smtplib.SMTP("smtp.gmail.com", 587)
|
||||||
speak("Bye Sir, have a good day.")
|
server.ehlo()
|
||||||
sys.exit()
|
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:
|
elif "nothing" in query or "abort" in query or "stop" in query:
|
||||||
music_folder = "Your_music_folder_path(absolute_path)"
|
speak("okay")
|
||||||
music = ("music1", "music2", "music3", "music4", "music5")
|
speak("Bye Sir, have a good day.")
|
||||||
random_music = music_folder + random.choice(music) + ".mp3"
|
sys.exit()
|
||||||
os.system(random_music)
|
|
||||||
|
|
||||||
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()
|
||||||
|
|||||||
@ -1,29 +1,30 @@
|
|||||||
import configparser
|
import configparser # isort: skip
|
||||||
import os
|
import os # isort: skip
|
||||||
|
|
||||||
import speech_recognition as sr
|
import gui # isort: skip
|
||||||
|
import speech_recognition as sr # isort: skip
|
||||||
from actions import (
|
from actions import ( # isort: skip
|
||||||
change_rate,
|
change_rate,
|
||||||
change_voice,
|
change_voice,
|
||||||
change_volume,
|
change_volume,
|
||||||
search_engine_selector,
|
search_engine_selector,
|
||||||
speak,
|
set_gui_speak,
|
||||||
wish_me,
|
speak,
|
||||||
|
wish_me
|
||||||
)
|
)
|
||||||
from commands import (
|
from commands import ( # isort: skip
|
||||||
command_bye,
|
command_bye,
|
||||||
command_hello,
|
command_hello,
|
||||||
command_mail,
|
command_mail,
|
||||||
command_nothing,
|
command_nothing,
|
||||||
command_open,
|
command_open,
|
||||||
command_pause_music,
|
command_pause_music,
|
||||||
command_play_music,
|
command_play_music,
|
||||||
command_search,
|
command_search,
|
||||||
command_stop_music,
|
command_stop_music,
|
||||||
command_unpause_music,
|
command_unpause_music,
|
||||||
command_whatsup,
|
command_whatsup,
|
||||||
command_wikipedia,
|
command_wikipedia
|
||||||
)
|
)
|
||||||
|
|
||||||
popular_websites = {
|
popular_websites = {
|
||||||
@ -36,7 +37,7 @@ popular_websites = {
|
|||||||
|
|
||||||
|
|
||||||
def main(search_engine, take_command, debug):
|
def main(search_engine, take_command, debug):
|
||||||
while True:
|
def execute_the_command_said_by_user():
|
||||||
query = take_command()
|
query = take_command()
|
||||||
|
|
||||||
# logic for executing commands without arguments
|
# logic for executing commands without arguments
|
||||||
@ -85,6 +86,9 @@ def main(search_engine, take_command, debug):
|
|||||||
change_volume(query, take_command)
|
change_volume(query, take_command)
|
||||||
|
|
||||||
speak("Next Command! Sir!")
|
speak("Next Command! Sir!")
|
||||||
|
gui.set_speak_command(execute_the_command_said_by_user)
|
||||||
|
set_gui_speak(gui.speak)
|
||||||
|
gui.mainloop()
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
|
|||||||
10
actions.py
10
actions.py
@ -44,7 +44,17 @@ def search(search_query, search_engine):
|
|||||||
open_url(f"{search_engine}/search?q={search_query}")
|
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):
|
def speak(text):
|
||||||
|
gui_speak(text)
|
||||||
engine.say(text)
|
engine.say(text)
|
||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
|
|
||||||
|
|||||||
29
gui.py
Normal file
29
gui.py
Normal file
@ -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
|
||||||
Loading…
x
Reference in New Issue
Block a user