-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassistant.py
More file actions
301 lines (223 loc) · 9.35 KB
/
Copy pathassistant.py
File metadata and controls
301 lines (223 loc) · 9.35 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# What you can do with it
# open Google, instagram , facebook , youtube , visual studio code , Pycharm , Notepad, open folder in your pc with given path , any topic wikipedia
# you can shutdown
# if it will not recognize any query then it will give you google link and also it will Automaticlly open that link..
# APP NAME: Rishi
#
# APPID: WYY24K-VA3VVGAG88
#
# USAGE TYPE: Personal/Non-commercial Only
# for input voice
import speech_recognition as sr
# import pyaudio
import pyttsx3
# for opening webbrower any link or your pc path location..
import webbrowser
# direct fatch data from google
from googlesearch import search
# for os operation..
import os
# for searching wikipedia...
import wikipedia
# for taking exact time..
import time
from datetime import datetime
import datetime
import wolframalpha
import cv2
import pywhatkit as kit
import sys
# All Functions
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[0].id)
# we can Use below three function to speak ....
# def SpeakText(command):
# # Initialize the engine
# engine = pyttsx3.init()
# engine.say(command)
# engine.runAndWait()
# def speak(str):
# from win32com.client import Dispatch
# speak = Dispatch("SAPI.SpVoice")
# speak.Speak(str)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wish():
# nowtime = datetime.datetime.today()
# nowtime = datetime.now().time()
nowtime = datetime.datetime.now()
if nowtime.hour >= 0 and nowtime.hour <= 11:
print("Good Morning Rishi Sir...")
speak("Good Morning Rishi Sir...")
print("How may I help You..")
speak("How may I help You..")
elif nowtime.hour == 12 and nowtime.minute == 0:
print("Good Noon Rishi sir...")
speak("Good Noon Rishi sir...")
print("how may i help you")
speak("how may i help you")
elif nowtime.hour >= 12 and nowtime.hour <= 15:
print("Good Afternoon Rishi Sir...")
speak("Good Afternoon Rishi Sir...")
print("How may I help You..")
speak("How may I help You..")
elif nowtime.hour >= 16 and nowtime.hour <= 19:
print("Good Evening Rishi Sir...")
speak("Good Evening Rishi Sir...")
print("How may I help You..")
speak("How may I help You..")
else:
speak("Good Night Rishi Sir...")
speak("Sleep well sir..")
def takecommand():
# Initialize the recognizer
r = sr.Recognizer()
with sr.Microphone() as source2:
# wait for a second to let the recognizer
# adjust the energy threshold based on
# the surrounding noise level
r.adjust_for_ambient_noise(source2, duration=0.2)
# listens for the user's input
print("listening....")
r.pause_threshold = 1
our_audio = r.listen(source2)
try:
print("recognizing...")
# Using google to recognize audio
YourText = r.recognize_google(our_audio, language='en-in')
print(f"did you say this {YourText}")
except Exception as e:
print(e)
print("Say that again please")
return None
return YourText
# register chrome brower woth their part
webbrowser.register('chrome',
None,
webbrowser.BackgroundBrowser(
"C://Program Files (x86)//Google//Chrome//Application//chrome.exe"))
if __name__ == '__main__':
wish()
while True:
AudioToText = takecommand().lower()
try:
if "google" in AudioToText:
webbrowser.get('chrome').open("https://www.google.com")
elif "close chrome" in AudioToText:
os.system('taskkill /f /im chrome.exe')
elif "time" in AudioToText:
currentime = time.asctime( time.localtime(time.time()) )
print(currentime)
speak(f"Date and Time : {currentime}")
elif "send message in whatsapp" in AudioToText:
kit.sendwhatmsg("+919100090525", "hi i am rishi from python program... I am not your Rishi", 12, 5)
elif "facebook" in AudioToText:
# speak("you are speaking facebook right..")
speak("Opening Facebook")
webbrowser.get('chrome').open('https://www.facebook.com/')
elif "instagram" in AudioToText:
# speak("you are speaking instagram right..")
speak("Opening instagram")
webbrowser.get('chrome').open('https://www.instagram.com/')
elif "youtube" in AudioToText or "video" in AudioToText:
speak("Opening youtube")
webbrowser.get('chrome').open('https://www.youtube.com/')
elif "visual studio code" in AudioToText or "code" in AudioToText:
webbrowser.open(
"C://Users//patel//AppData//Local//Programs//Microsoft VS Code//Code.exe")
elif "pycharm" in AudioToText:
webbrowser.open(
"C://Users//patel//AppData//Local//Programs//PyCharm Community Edition 2020.1.1//bin//pycharm64.exe")
elif "notepad" in AudioToText:
webbrowser.open(
"C://Users//patel//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Accessories//Notepad.lnk")
elif "marvel cinema" in AudioToText:
webbrowser.open("E://marvel sequense")
elif "command" in AudioToText:
os.system('start cmd')
elif "close command" in AudioToText:
os.system('KILL')
# elif "close" in AudioToText:
# try:
# os.system('TASKKILL /F /IM C://Users/patel//PycharmProjects//pythonProject//project//assistant.py')
# except Exception as e:
# print(e)
# os.stop()
elif "wikipedia" in AudioToText:
print(wikipedia.summary(AudioToText, sentences=2))
elif "take a photo" in AudioToText:
cap = cv2.VideoCapture(0)
while True:
ret,img = cap.read()
cv2.imshow('webcam',img)
k = cv2.waitKey(3)
if k == 27:
break
cap.release()
cv2.destroyAllWindows()
elif "tell me" in AudioToText:
speak(
"i can answer to computational and geographical question do you want to ask now..")
question = takecommand().lower()
print(f"Your question : {question}?")
print("Wait a moment sir..")
speak("wait a moment sir..")
try:
app_id = 'WYY24K-VA3VVGAG88'
client = wolframalpha.Client(app_id)
res = client.query(question)
answer = next(res.results).text
print(f"Your Answer : {answer}.")
speak(answer)
except:
speak("Sorry Sir , I can not find answer from my data..")
elif ("shut down" and "down") in AudioToText:
# listens for the user's input
print("Do you want to shutdown.....")
speak("Do you want to shutdown sir.....")
try:
lastans = takecommand().lower()
except:
lastans = "no"
if "yes" in lastans:
print("shutting down your computer..")
speak("shutting down your computer")
os.system("shutdown /s /t 30")
elif "no" in lastans:
print("Thank you sir")
speak("Keep it up sir")
# SpeakText(AudioToText)
# speak(AudioToText)
else:
print("I have some information link about your query..")
speak("I have some information link about your query..")
print("May be it will help you.")
speak("May be it will help you.")
speak("please wait a moment sir..")
for j in search(AudioToText, tld="co.in", num=1, stop=1, pause=2):
print(j)
speak("opening for you...")
webbrowser.get('chrome').open(j)
except Exception as e:
print(e)
finally:
speak("thank you for using me..")
print("Do you want to continue.....")
speak("Do you want to continue sir.....")
try:
loopans = takecommand().lower()
except Exception as e:
loopans = "no"
print("exeption")
if "continue" in loopans:
print("Ok sir \n")
speak("ok Sir")
else:
print("Thank you sir")
speak("Thank you sir")
print("Keep it up sir")
speak("Keep it up sir")
break