Skip to content

Commit 1f97166

Browse files
ItsAakiftechyminati
authored andcommitted
Simple Desktop Assistant
1 parent b33a114 commit 1f97166

1 file changed

Lines changed: 186 additions & 0 deletions

File tree

‎Gideon.py‎

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
import pyttsx3
2+
import speech_recognition as sr
3+
import datetime
4+
import wikipedia
5+
import webbrowser
6+
import os
7+
import smtplib
8+
9+
engine = pyttsx3.init('sapi5')
10+
voices = engine.getProperty('voices')
11+
# print(voices[1].id)
12+
engine.setProperty('voice', voices[1].id)
13+
14+
15+
def speak(audio):
16+
engine.say(audio)
17+
engine.runAndWait()
18+
19+
20+
def wishMe():
21+
hour = int(datetime.datetime.now().hour)
22+
if hour>=0 and hour<12:
23+
speak("Good Morning!")
24+
25+
elif hour>=12 and hour<18:
26+
speak("Good Afternoon!")
27+
28+
else:
29+
speak("Good Evening!")
30+
31+
speak("I am Gideon master . Please tell me how may I help you")
32+
33+
34+
35+
def telltime():
36+
37+
38+
39+
time = str(datetime.datetime.now())
40+
41+
42+
43+
print(time)
44+
45+
hour = time[11:13]
46+
47+
min = time[14:16]
48+
49+
speak ("The time is sir" + hour + "Hours and" + min + "Minutes")
50+
51+
52+
def tellday():
53+
54+
Day_dict = {1: 'Monday', 2: 'Tuesday',
55+
56+
3: 'Wednesday', 4: 'Thursday',
57+
58+
5: 'Friday', 6: 'Saturday',
59+
60+
7: 'Sunday'}
61+
62+
63+
64+
for day in Day_dict.keys():
65+
66+
day_of_the_week = Day_dict[day]
67+
68+
print(day_of_the_week)
69+
70+
speak("The day is " + day_of_the_week)
71+
72+
73+
74+
def Hello():
75+
76+
77+
speak ("hello sir I am your desktop assistant,My name is gideon, Tell me how may I help you ")
78+
79+
80+
def takeCommand():
81+
82+
83+
r = sr.Recognizer()
84+
with sr.Microphone() as source:
85+
print("Listening...")
86+
r.pause_threshold = 1
87+
audio = r.listen(source)
88+
89+
try:
90+
print("Recognizing...")
91+
query = r.recognize_google(audio, language='en-in')
92+
print(f"User said: {query}\n")
93+
94+
except Exception as e:
95+
96+
print("Say that again please...")
97+
speak ("couldn't recognize it say that again please")
98+
return "None"
99+
return query
100+
101+
def sendEmail(to, content):
102+
server = smtplib.SMTP('smtp.gmail.com', 587)
103+
server.ehlo()
104+
server.starttls()
105+
server.login('Sender's Mail', 'pass')
106+
server.sendmail('sender's mail', to,)
107+
server.close()
108+
109+
if __name__ == "__main__":
110+
wishMe()
111+
while True:
112+
query = takeCommand().lower()
113+
114+
115+
if 'wikipedia' in query:
116+
speak('Searching Wikipedia...')
117+
query = query.replace("wikipedia", "")
118+
results = wikipedia.summary(query, sentences=2)
119+
speak("According to Wikipedia")
120+
print(results)
121+
speak(results)
122+
123+
124+
if 'youtube' in query:
125+
speak('opening youtube....')
126+
content=takeCommand
127+
128+
if 'google' in query:
129+
speak('opening google...')
130+
content=takeCommand
131+
132+
if 'spotify'in query:
133+
speak('opening spotify')
134+
content=takeCommand
135+
136+
if 'stack overflow'in query:
137+
speak('oepning stack overflow')
138+
content=takeCommand
139+
140+
141+
elif 'open youtube' in query:
142+
webbrowser.open("youtube.com")
143+
144+
elif 'open google' in query:
145+
webbrowser.open("google.com")
146+
147+
elif 'open stackoverflow' in query:
148+
webbrowser.open("stackoverflow.com")
149+
150+
elif 'open spotify' in query:
151+
webbrowser.open("spotify.com")
152+
153+
elif 'the time' in query:
154+
telltime()
155+
156+
elif "which day it is" in query:
157+
tellday()
158+
159+
160+
elif "tell me the time" in query:
161+
162+
telltime()
163+
164+
elif "Hello" in query:
165+
166+
Hello()
167+
168+
elif"terminate" in query:
169+
speak("Terminating the session, bye master")
170+
exit()
171+
172+
elif 'exit' in query:
173+
174+
exit()
175+
176+
177+
elif 'send email' in query:
178+
try:
179+
speak("What should I say?")
180+
content = takeCommand()
181+
to = "EMail"
182+
sendEmail(to, content)
183+
speak("Email has been sent!")
184+
except Exception as e:
185+
print(e)
186+
speak("Couldnot send due to some problem. My apologies sir")

0 commit comments

Comments
 (0)