commit
29ec429688
16
Jarvis2.py
16
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,10 +98,13 @@ def take_command():
|
|||||||
|
|
||||||
speak("Initializing Jarvis....")
|
speak("Initializing Jarvis....")
|
||||||
wish_me()
|
wish_me()
|
||||||
|
|
||||||
|
|
||||||
|
def execute_the_command_said_by_user():
|
||||||
query = take_command().lower()
|
query = take_command().lower()
|
||||||
|
|
||||||
# logic for executing basic tasks
|
# logic for executing basic tasks
|
||||||
if "wikipedia" in query.lower():
|
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))
|
||||||
@ -148,9 +154,7 @@ elif "email" in query:
|
|||||||
server.close()
|
server.close()
|
||||||
speak("Email sent!")
|
speak("Email sent!")
|
||||||
except Exception:
|
except Exception:
|
||||||
speak(
|
speak("Sorry Sir! I am unable to send your message at this moment!")
|
||||||
"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")
|
||||||
@ -173,3 +177,7 @@ 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()
|
||||||
|
|||||||
@ -1,17 +1,18 @@
|
|||||||
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,
|
||||||
|
set_gui_speak,
|
||||||
speak,
|
speak,
|
||||||
wish_me,
|
wish_me
|
||||||
)
|
)
|
||||||
from commands import (
|
from commands import ( # isort: skip
|
||||||
command_bye,
|
command_bye,
|
||||||
command_hello,
|
command_hello,
|
||||||
command_mail,
|
command_mail,
|
||||||
@ -23,7 +24,7 @@ from commands import (
|
|||||||
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