-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev_assistant.py
233 lines (178 loc) · 7.31 KB
/
dev_assistant.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
import pyttsx3 as ps
import datetime as dt
import speech_recognition as sr
import wikipedia as wiki
import webbrowser as wb
import os
import random
import time
import smtplib
from selenium import webdriver
import re
from mutagen.mp3 import MP3
engine=ps.init('sapi5')
voices=engine.getProperty('voices')
#print(voices[1].id) #to get the voices from window
engine.setProperty('voice',voices[1].id)
chrome_path="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
wb.register('google-chrome', None,wb.BackgroundBrowser(chrome_path))
def welcome():
print("|||||||||| ||||||||||||| ||| ||| |||||||||")
time.sleep(0.5)
print("||| ||| ||| ||| ||| ||| |||")
time.sleep(0.5)
print("||| ||| ||| |||||| ||| |||")
time.sleep(0.5)
print("|||||||||| ||| || ||| |||")
time.sleep(0.5)
print("||| || ||| || |||||||||")
time.sleep(0.5)
print("||| || ||| || ||| |||")
time.sleep(0.5)
print("||| || ||| || ||| |||")
time.sleep(0.5)
print("||| || ||||||||||||| || ||| |||")
time.sleep(1)
print("\033[1m", "\n Your personel voice assistant", "\033[0m")
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour= int(dt.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning Mate! \n Have a good day.")
elif hour>=12 and hour<=18:
speak("Good Afternoon Good Afternoon Jay! \n Hope,you are having a good day.")
else:
speak("Good Evening! \n Hope you had a great day.")
speak("I am Riya. The personnel voice assistant created by Jay Khandelwal. Please tell me How may I help you?")
def takeCommand():
#takes microphone input from user and return string output
r=sr.Recognizer()
with sr.Microphone() as source:
print("I'm listening....")
r.pause_threshold=1
audio=r.listen(source)
try:
print("I'm Recognizing....")
query= r.recognize_google(audio, language='en-in')
print(f"You just said: {query}\n")
except Exception as e:
print(e)
print("Unable to recognize! Can you please say it again...")
return "None"
return query
def sendEmail(to,content):
server=smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
mail='[email protected]'
server.login(mail,'Dev_jay18')
server.sendmail(mail,to,content)
server.close()
def search_google(query):
chrome_driver = webdriver.Chrome(executable_path="C:\Drivers\chrome\chromedriver.exe")
chrome_driver.get(url="https://www.google.com")
search_query=chrome_driver.find_element_by_xpath('//*[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input')
search_query.click()
search_query.send_keys(query)
submit=chrome_driver.find_element_by_name('btnK')
#submit=self.driver.find_element_by_xpath('//*[@id="tsf"]/div[2]/div[1]/div[3]/center/input[1]').click()
submit.click()
def play_youtube(query):
chrome_driver = webdriver.Chrome(executable_path="C:\Drivers\chrome\chromedriver.exe")
chrome_driver.get(url="https://www.youtube.com/results?search_query="+query)
video_play=chrome_driver.find_element_by_xpath('//*[@id="img"]')
video_play.click()
#time.sleep(90)
def general_chat(query):
if query in question:
answer=question[query]
speak(answer)
def sleep(sleep_time):
time.sleep(sleep_time)
speak("Again available to serve you, Jay Sir")
def close_chrome():
os.system('taskkill /f /im chrome.exe')
if __name__ == '__main__':
welcome()
wishMe()
#load general chat/conversion data
question = {}
with open("dict.txt") as f:
for line in f:
(key, val) = line.split('-')
question[(key)] = val
while True:
query=takeCommand().lower()
#logics for executing tasks based on query
if 'search' in query:
speak('Searching your query...')
query=query.replace("search","")
search_google(query)
elif 'open youtube' in query:
speak('We will getting that from youtube soon')
query=query.replace("open youtube ","")
play_youtube(query)
elif 'tell me about' in query:
speak('We will let you know soon...')
query = query.replace("tell me about", "")
results = wiki.summary(query, sentences=2)
speak("According to our research")
speak(results)
print(results)
elif 'website open ' in query:
position_open=query.find('open')
position_open+=5
ur=query[position_open:]+".com"
urL=ur.replace(" ", "")
wb.get('google-chrome').open(urL)
elif 'close chrome' in query:
speak("closing chrome")
close_chrome()
elif 'play music' in query:
music_dir=r'C:\Data\Songs'
songs=os.listdir(music_dir)
song_number=random.randint(0,len(songs)-1)
#audio=MP3(songs[song_number])
#song_length=audio.info.length
os.startfile(os.path.join(music_dir,songs[song_number]))
time.sleep(30)
elif 'play video' in query:
video_dir = r'C:\Data\Mobile'
video = os.listdir(video_dir)
video_number = random.randint(0, len(video) - 1)
os.startfile(os.path.join(video_dir, video[video_number]))
time.sleep(30)
elif 'the time' in query:
strTime=dt.datetime.now().strftime("%H:%M:%S")
speak(f"Jay, The time is {strTime}")
elif 'open world' in query:
word_path=r"C:\Softwares\word.lnk"
os.startfile(word_path)
elif 'open powerpoint' in query:
point_path=r"C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE"
os.startfile(point_path)
elif 'open excel' in query:
excel_path=r"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE"
os.startfile(excel_path)
elif 'open python editor' in query:
pycharm_path=r"C:\Users\Dev_jay\AppData\Local\JetBrains\Toolbox\apps\PyCharm-P\ch-0\201.7846.77\bin\pycharm64.exe"
os.startfile(pycharm_path)
elif 'hold' in query:
temp = re.findall(r'\d+', query)
res = list(map(int, temp))
sleep_time=res[0]
sleep(sleep_time)
elif 'send email' in query:
try:
speak("What should I say?")
content=takeCommand()
to="[email protected]"
sendEmail(to,content)
speak("Email has been sent successfully!")
except Exception as e:
print(e)
speak("Sorry, Unable to send Email")
else:
general_chat(query)