Merge pull request #39 from Jothin-kumar/issue_16

GUI support!
This commit is contained in:
Technerd Brainiac 2021-10-09 19:28:48 +05:30 committed by GitHub
commit 29ec429688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 139 additions and 88 deletions

View File

@ -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,10 +98,13 @@ def take_command():
speak("Initializing Jarvis....")
wish_me()
def execute_the_command_said_by_user():
query = take_command().lower()
# logic for executing basic tasks
if "wikipedia" in query.lower():
if "wikipedia" in query:
speak("Searching wikipedia....")
query = query.replace("wikipedia", "")
print_and_speak(wikipedia.summary(query, sentences=2))
@ -148,9 +154,7 @@ 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:
speak("okay")
@ -173,3 +177,7 @@ elif "play music" in query:
speak("Playing your request")
speak("Next Command! Sir!")
gui.set_speak_command(execute_the_command_said_by_user)
gui.mainloop()

View File

@ -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():

View File

@ -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
View 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