commit
29ec429688
42
Jarvis2.py
42
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,15 +98,18 @@ def take_command():
|
||||
|
||||
speak("Initializing Jarvis....")
|
||||
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....")
|
||||
query = query.replace("wikipedia", "")
|
||||
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 = (
|
||||
"Just doing my thing!",
|
||||
"I am fine!",
|
||||
@ -112,13 +118,13 @@ elif "what's up" in query or "how are you" in query:
|
||||
)
|
||||
speak(random.choice(st_msgs))
|
||||
|
||||
elif "date" in query:
|
||||
elif "date" in query:
|
||||
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}")
|
||||
|
||||
elif "open" in query.lower():
|
||||
elif "open" in query.lower():
|
||||
website = query.replace("open", "").strip().lower()
|
||||
try:
|
||||
open_url(popular_websites[website])
|
||||
@ -126,12 +132,12 @@ elif "open" in query.lower():
|
||||
print(f"Unknown 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_engine = query.split("for")[0].replace("search", "").strip().lower()
|
||||
search(search_query, search_engine)
|
||||
|
||||
elif "email" in query:
|
||||
elif "email" in query:
|
||||
speak("Who is the recipient? ")
|
||||
recipient = take_command()
|
||||
|
||||
@ -148,23 +154,21 @@ elif "email" in query:
|
||||
server.close()
|
||||
speak("Email sent!")
|
||||
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("Bye Sir, have a good day.")
|
||||
sys.exit()
|
||||
|
||||
elif "hello" in query:
|
||||
elif "hello" in query:
|
||||
speak("Hello Sir")
|
||||
|
||||
elif "bye" in query:
|
||||
elif "bye" in query:
|
||||
speak("Bye Sir, have a good day.")
|
||||
sys.exit()
|
||||
|
||||
elif "play music" in query:
|
||||
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"
|
||||
@ -172,4 +176,8 @@ elif "play music" in query:
|
||||
|
||||
speak("Playing your request")
|
||||
|
||||
speak("Next Command! Sir!")
|
||||
speak("Next Command! Sir!")
|
||||
|
||||
|
||||
gui.set_speak_command(execute_the_command_said_by_user)
|
||||
gui.mainloop()
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
import configparser
|
||||
import os
|
||||
import configparser # isort: skip
|
||||
import os # isort: skip
|
||||
|
||||
import speech_recognition as sr
|
||||
|
||||
from actions import (
|
||||
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,
|
||||
wish_me
|
||||
)
|
||||
from commands import (
|
||||
from commands import ( # isort: skip
|
||||
command_bye,
|
||||
command_hello,
|
||||
command_mail,
|
||||
@ -23,7 +24,7 @@ from commands import (
|
||||
command_stop_music,
|
||||
command_unpause_music,
|
||||
command_whatsup,
|
||||
command_wikipedia,
|
||||
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():
|
||||
|
||||
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}")
|
||||
|
||||
|
||||
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()
|
||||
|
||||
|
||||
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