Code for Jarvis Gui
from tkinter import *
import speech_recognition as sr
from PIL import Image
import wikipedia
from PIL.ImageTk import PhotoImage
import pyttsx3
import datetime
import tkinter
# from tkinter.scrolledtext import ScrolledText
import webbrowser
import os
import random
import pywhatkit
import pyjokes
import time
import tkinter.messagebox as tmsg
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[0].id)
engine.setProperty(voices, voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
text1="User: "
def wishMe():
global statusvar
statusvar.set("Introduction....")
sbar.update()
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning Sir")
elif hour>=12 and hour<18:
speak("Good Afternoon Sir")
else:
speak("Good Evening Sir")
speak("I am Jarvis, your personal assistant, Please tell me how may I help You")
statusvar.set("Press the Button to say something..")
sbar.update()
def Rate():
value = tmsg.askquestion("Rate us", "Was your experience good?")
if value=="yes":
msg="Great, rate us on appstore"
else:
msg="Please tell what went wrong with you in feedback"
tmsg.showinfo("Experience", msg)
def Feedback():
value = tmsg.askquestion("Rate us", "Was your experience good?")
if value=="yes":
msg="Great, rate us on appstore"
else:
msg="Please tell what went wrong with you in feedback"
tmsg.showinfo("Experience", msg)
def About():
hacker = Tk()
hacker.geometry("700x400")
hacker.title("About")
heading = Label(hacker, text="Information", font="Castellar 20 bold", borderwidth=3).pack()
information = Label(hacker, text = "Name: Jarvis\nDescription: It is a simple personal assistant.\n Company: Master V.\n Version: 1.0\n Developer: Piyush Verma\nRequirement: Operating System\n RAM : 2 GB\n Processor:1Ghz",font="FrankRuehl 18 italic", bg= "red", fg="black", padx=20, pady=10, borderwidth=5).pack()
hacker.mainloop()
def takeCommand():
global statusvar
global text1
r = sr.Recognizer()
with sr.Microphone() as source:
# print("listening")
# statusvar.set("Listening")
# sbar.update()
statusvar.set("Listening")
sbar.update()
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing.....")
# statusvar.set("Recognizing")
# sbar.update()
statusvar.set("Recognizing.....")
sbar.update()
query = r.recognize_google(audio, language='en-in')
# print(f"User said: {query}\n")
time.sleep(4)
statusvar.set("Say Something")
sbar.update()
except Exception as e:
# print("Say that again please........")
# statusvar.set("Say that again please........")
# sbar.update()
statusvar.set("Say that again please........")
sbar.update()
speak("say that again please.....")
return "None"
return query
a = {
"hello" : "hey!.............",
"your name":"My name is Jarvis",
"namaste":"Raaam Raaam",
"radhe radhe": "jai shree krishna..",
"who created you":"I am created by Master Piyush",
"what can you do": "I can do what ever you say.",
"what is your real name": "My real name is Jatayu",
"what is your country name": "India",
"nice":"Thanks you ...",
"what is your channel name":"Youtube Gaming. Youtube Gaming is my channel name",
"what do you eat":"Code...",
}
b = "A quote by Abdul Kalam 'A dream is not that which you see while sleeping, it is something that does not let you sleep.'"
c = "Those who are prepared to die for any cause are seldom defeated. -Pandit Jawarharlal Nehru"
d = " quote by Rabindranath Tagore is that, Where the mind is led forward by thee into ever-widening thought and action-Into that heaven of freedom, my father, let my country awake."
e = "Revolution is an inalienable right of mankind. Freedom is an imperishable birthright of all. ― Bhagat Singh"
f = random.randint(1, 2)
g = random.randint(1, 2)
h = random.randint(1, 2)
def Quotes():
if h ==1:
if f == 1:
text2 =b
screen1.insert(END, text2)
screen1.update()
speak(b)
elif f==2:
text2 =c
screen1.insert(END, text2)
screen1.update()
speak(c)
elif h==2:
if g==1:
text2 =d
screen1.insert(END, text2)
screen1.update()
speak(d)
elif g==2:
text2 =e
screen1.insert(END, text2)
screen1.update()
speak(e)
def Query():
global text1
global text2
global text3
strTime = datetime.datetime.now().strftime("%H:%M:%S")
query = takeCommand().lower()
text3.set(f"{strTime}: {query}\n")
screen.insert(END, text3.get())
screen.update()
if 'wikipedia' in query:
speak('Searching in wikipedia.....')
query = query.replace("wikipedia", "")
statusvar.set("Searching....")
sbar.update()
result = wikipedia.summary(query, sentences=1)
text2 = f"{strTime}: {result}"
screen1.insert(END, text2)
screen1.update()
speak("According to Wikipedia")
time.sleep(2)
statusvar.set("Say Something...")
sbar.update()
speak(result)
elif query in a.keys():
text2 =f"{strTime}: {a.get(query)}\n"
screen1.insert(END, text2)
screen1.update()
speak(a.get(query))
elif 'open youtube' in query:
webbrowser.open("youtube.com")
text2 = f"{strTime}: Opening Youtube\n"
screen1.insert(END, text2)
screen1.update()
statusvar.set("Opening Youtube...")
sbar.update()
speak("Opening Youtube")
time.sleep(2)
statusvar.set("Say something...")
sbar.update()
elif 'open google' in query:
webbrowser.open("google.com")
text2 =f"{strTime}: Opening Google\n"
screen1.insert(END, text2)
screen1.update()
statusvar.set("Opening Google")
sbar.update()
speak("Opening Google")
time.sleep(2)
statusvar.set("Say something...")
sbar.update()
elif 'open codewithharry' in query:
webbrowser.open("codewithharry.com")
elif 'play music' in query:
music_dir = "" #Enter the directory
song = os.listdir(music_dir)
# (songs)print
os.startfile(os.path.join(music_dir, songs[0]))
pass
elif 'the time' in query:
text2 = {strTime}
screen1.insert(END, text2)
screen1.update()
speak(f"Sir, the time is {strTime}")
elif 'open visual studio code' in query:
codePath = "C:\\Users\\haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)
elif 'email to mom' in query:
try:
speak("What should I say?")
content = takeCommand()
to = "hv1535760@gmail.com"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
# print(e)
speak("Sorry Sir, I am not able to sent email")
pass
elif 'open chrome' in query:
chromePath = "C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe"
os.startfile(chromePath)
elif 'good night' in query:
text2 =f"{strTime}: Good Night"
screen1.insert(END, text2)
screen1.update()
speak("Good night! Sir")
elif 'quotes by some famous indian personalities' in query:
Quotes()
elif "remember that" in query:
with open('Remember.txt', 'w') as f:
f.append(query)
text2 =f"{strTime}: I will remember"
screen1.insert(END, text2)
screen1.update()
speak("I will remember")
elif 'remind' in query:
with open('Remember.txt', 'r') as f:
hello = f.read()
text2 =f"{strTime}:{f.read()}"
screen1.insert(END, text2)
screen1.update()
speak(hello)
elif 'play' in query:
song = query.replace('play', '')
speak('playing' + song)
text2 =f"{strTime}: {song}"
screen1.insert(END, text2)
screen1.update()
pywhatkit.playonyt(song)
elif 'joke' in query:
joke = pyjokes.get_joke()
text2 =f"{strTime}: {joke}"
screen1.insert(END, text2)
screen1.update()
speak(joke)
elif 'quit' or 'exit' in query:
text2 =f"{strTime}: Thank you Sir for giving me chance"
screen1.insert(END, text2)
screen1.update()
speak("Thank you Sir for giving me chance")
exit()
def status():
global statusvar
root=Tk()
root.geometry("900x600")
root.title("Jarvis")
root.wm_iconbitmap("unnamed.ico")
root.attributes('-alpha', 0.9)
label = Label(root, text="User")
# image = Image.open("45-458500_transparent-button-microphone-rod-of-asclepius-png.png")
# # Reszie the image using resize() method
# resize_image = image.resize((100, 90))
# img = ImageTk.PhotoImage(resize_image)
# # create label and add resize image
# label1 = Label(image=img)
# label1.image = img
# label1.pack()
photo = PhotoImage(file='45-458500_transparent-button-microphone-rod-of-asclepius-png (2).png')
text4 = StringVar()
text4.set("")
Button(image=photo, command=Query, relief=FLAT).pack()
text3=StringVar()
text3.set("User: ")
screen = Text(root, font="Helvetica 16 italic", width=50, height=2, borderwidth=5, relief=RIDGE)
screen.insert("end", text3.get())
screen.pack(side=TOP, anchor=E, pady=40)
statusvar=StringVar()
statusvar.set("Start")
sbar = Label(root, textvariable=statusvar, relief=SUNKEN, anchor='w')
sbar.pack(side=BOTTOM, fill=X)
yourmenu = Menu(root)
m1=Menu(yourmenu, tearoff=0)
m1.add_command(label="Rate us", command=Rate)
m1.add_command(label="Feedback", command= Feedback)
m1.add_command(label="About", command=About)
root.config(menu=yourmenu)
yourmenu.add_cascade(label="...",menu=m1)
text2=('Result : ')
screen1 = Text(root, font="Helvetica 15 italic", borderwidth=8, width=60, height=4 )
screen1.insert(END, text2)
screen1.pack(anchor=W)
wishMe()
root.mainloop()
This is working
ReplyDelete