-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
277 lines (227 loc) · 8.89 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
import pyttsx3 #pip install pyttsx3
import datetime
import pyaudio #pipwin install pyaudio
import speech_recognition as sr #pip install SpeechRecognition
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib
import psutil
import pyjokes
import pyautogui
import random
import requests
from pprint import pprint
#pip install pprint
MASTER = "Hillary"
print("Initializing Samaritan...")
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def time():
Time = datetime.datetime.now().strftime("%H:%M:%S")
speak('The current time is')
speak(Time)
def date():
year = datetime.datetime.now().year
month = datetime.datetime.now().month
date = datetime.datetime.now().day
speak('The Current date is')
speak(date)
speak(month)
speak(year)
def wishme():
speak("Welcome back sir!")
#speak("the current time is")
time()
#speak("it's the")
date()
hour = datetime.datetime.now().hour
if hour >= 0 and hour<12:
speak("Good Morning" + MASTER)
elif hour >=12 and hour<18:
speak("Good Afternoon" + MASTER)
elif hour >=18 and hour <24:
speak("Good evening" + MASTER)
else:
speak("Good Night" + MASTER)
speak("Samaritan at your service. Please tell me how can i help you?")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language='en-US')
print(f"user said: {query}\n")
except Exception as e:
print(e)
speak("Say that again please...")
return "None"
return query
def sendEmail(to, content):
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.close()
def cpu():
usage = str(psutil.cpu_percent())
speak('CPU is at'+usage)
"""battery = psutil.sensors_battery()
speak('Battery is at')
speak(battery.percent)"""
def joke():
speak(pyjokes.get_joke())
def screenshot():
img = pyautogui.screenshot()
img.save('C:/Users/Tech/Desktop/Assets/screenshot.png')
def who_am_i():
speak('You are ' + MASTER + ', a brilliant person. I love you!')
def where_born():
speak('I was created by a magician named Hillary, in Nairobi, the magical land of Kenya.')
def how_are_you():
speak('I am fine, thank you. How can help you Sir?')
#speak('Initializing Samaritan...')
#wishme()
#query = takeCommand()
if __name__ == "__main__":
wishme()
while True:
query = takeCommand().lower()
if 'time' in query:
time()
elif 'date' in query:
date()
elif 'who am i' in query:
who_am_i()
elif 'where were you born' in query:
where_born()
elif 'how are you' in query:
how_are_you()
elif 'wikipedia' in query.lower():
speak('searching wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=3)
speak('According to Wikipedia...')
print(results)
speak(results)
elif 'send email' in query.lower():
try:
speak('What should I send...')
content = takeCommand()
speak('Who is the Receiver Sir?')
receiver = input("Enter Receiver's Email :")
to = receiver
sendEmail(to, content)
speak('Email sent Successfuly')
except Exception as e:
print(e)
speak('Unable to send Email')
elif 'search in chrome' in query.lower():
speak('What should I Search?')
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
search = takeCommand().lower()
webbrowser.get(chrome_path).open_new_tab(search+'.com')
elif 'search youtube' in query:
speak('What should I Search?')
search_term = takeCommand().lower()
speak("Opening YOUTUBE!")
webbrowser.open('https://www.youtube.com/results?search_query='+search_term)
elif 'weather details' in query: #weathermap Api
speak('Which City Sir!')
weather_up = takeCommand().lower()
speak('Getting Weather Update for '+ weather_up)
url = 'https://api.openweathermap.org/data/2.5/weather?q={}&appid={API KEY}&units=metric'.format(weather_up)
resi = requests.get(url)
data = resi.json()
temp = data['main']['temp'],
wind_speed = data['wind']['speed'],
latitude = data['coord']['lat'],
longitude = data['coord']['lon'],
description = data['weather'][0]['description']
speak('Temperature is at: {} degree celcius'.format(temp))
speak('Wind Speed is at: {} Micro Seconds'.format(wind_speed))
speak('Latitude is : {}'.format(latitude))
speak('Longitude is : {}'.format(longitude))
speak('Clouds Status are : {}'.format(description))
#update = webbrowser.open('https://api.openweathermap.org/data/2.5/weather?q={}&appid={API KEY}'.format(weather_up))
elif 'open google' in query:
speak('What should I Search?')
search_term = takeCommand().lower()
speak('Searching...')
url = 'google.com'
chrome_path = 'C:\Program Files (x86)\Google\Chrome\Application/chrome.exe %s'
webbrowser.open('https://www.google.com/search?q='+search_term)
elif 'open github' in query:
speak('Opening Github Sir!')
search_term = takeCommand().lower()
speak('Opening your Account Sir!')
url = 'github.com'
webbrowser.open('https://www.github.com/youraccount')
elif 'cpu' in query:
cpu()
elif 'joke' in query:
joke()
elif 'go offline' in query:
speak('Going Offline Sir!')
quit()
elif 'open word' in query:
speak('Opening MS Word....')
ms_word = r'C:/ProgramData/Microsoft/Windows/Start Menu/Programs/Microsoft Office/WINWORD.EXE'
os.startfile(ms_word)
elif 'open downloads' in query:
speak('Opening Downloads....')
downloads = r'C:/Users/Tech/Downloads'
os.startfile(downloads)
elif 'open python' in query:
speak('Opening PyCharm....')
pycharm = r'C:/Program Files/JetBrains/PyCharm Community Edition 2020.1.2/bin/pycharm64.exe'
os.startfile(pycharm)
elif 'open visual code' in query:
speak('Opening Visual Code....')
pycharm = r'C:/Program Files/Microsoft VS Code/Code.exe'
os.startfile(pycharm)
elif 'write a note' in query:
speak("What Should i write, Sir?")
notes = takeCommand()
file = open('notes.txt','w')
speak("Sir Should I include Date and Time?")
ans = takeCommand()
if 'yes' in ans or 'sure' in ans:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
file.write(strTime)
file.write(':-')
file.write(notes)
speak("Done taking Notes, Sir!")
else:
file.write(notes)
elif 'show notes' in query:
speak('Showing Notes')
file = open('notes.txt','r')
print(file.read())
speak(file.read())
elif 'screenshot' in query:
screenshot()
elif 'play music' in query:
songs_dir = 'E:/Bongo'
music = os.listdir(songs_dir)
speak('What should I play?')
speak('Select a number......')
answer = takeCommand().lower()
while('number' not in answer and answer != 'random' and answer != 'you choose'):
speak('I could not understand you. Please Come up again')
answer = takeCommand().lower()
if 'number' in answer:
no = int(answer.replace('number',''))
elif 'random' or 'you choose' in answer:
no = random.randint(1,100)
os.startfile(os.path.join(songs_dir,music[no]))
elif 'who are you' in query:
speak("I am Samaritan, The Smart Assistant of Hillary, Developed to help him around with his work and makes his life easier with his machine")