Skip to content

Commit 7934b50

Browse files
Create assistant.py
1 parent 37ab727 commit 7934b50

File tree

1 file changed

+227
-0
lines changed

1 file changed

+227
-0
lines changed

assistant.py

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
import pyttsx3 as p
2+
import datetime as d
3+
import speech_recognition as s
4+
import os
5+
import subprocess
6+
import webbrowser as w
7+
import wikipedia
8+
9+
10+
# todo speed up down
11+
a=p.init()
12+
r=a.getProperty("rate")
13+
a.setProperty("rate",180)
14+
15+
# todo function for voice
16+
def voice(v):
17+
a = p.init()
18+
b = a.getProperty("voices")
19+
a.setProperty("voice", b[1].id)
20+
a.say(v)
21+
a.runAndWait()
22+
23+
# todo function for wish
24+
def wish():
25+
h=int(d.datetime.now().hour)
26+
if h>=0 and h<12:
27+
voice("Good Morning Prince Singh,i am your Assistant,how can i help you")
28+
elif h>=12 and h<18:
29+
voice("Good after noon Prince Singh,i am your Assistant,how can i help you")
30+
else:
31+
voice("Good evining Prince Singh,i am your Assistant,how can i help you")
32+
33+
wish()
34+
35+
# todo function for speek
36+
def speek():
37+
a = s.Recognizer()
38+
a.energy_threshold=20000
39+
with s.Microphone() as m:
40+
audio = a.listen(m)
41+
q = a.recognize_google(audio, language='eng-in')
42+
q = str(q)
43+
q = q.lower()
44+
print(q)
45+
return q
46+
47+
fun=speek()
48+
49+
# todo for shutdown
50+
if "shut down" in fun:
51+
x="are you sure to shut down your pc"
52+
voice(x)
53+
x1 = speek()
54+
if "yes" in x1:
55+
g="thank you,for your confirmation , now i am goining to shut down your pc"
56+
voice(g)
57+
# todo shut down
58+
os.system('shutdown /s /t 1')
59+
else:
60+
voice("thank you,for your confirmation , now i am rejected your command")
61+
62+
# todo for restart
63+
elif "restart" in fun:
64+
x = "are you sure to restart your pc"
65+
voice(x)
66+
x1 = speek()
67+
if "yes" in x1:
68+
g = "thank you,for your confirmation , now i am goining to restart your pc"
69+
voice(g)
70+
# todo shut down
71+
os.system('shutdown /r /t 1')
72+
else:
73+
voice("thank you,for your confirmation , now i am rejected your command")
74+
75+
76+
# todo file open
77+
elif "open file" in fun:
78+
g = "thank you,for your confirmation , now i am goining to open your File mannager"
79+
voice(g)
80+
subprocess.Popen("explorer")
81+
82+
elif "open installation area" in fun:
83+
g = "thank you,for your confirmation , now i am goining to open your installation area "
84+
voice(g)
85+
os.startfile("E:\\")
86+
87+
elif "open coding world" in fun:
88+
g = "thank you,for your confirmation , now i am goining to open your coding world"
89+
voice(g)
90+
os.startfile("F:\\")
91+
92+
elif "open college world" in fun:
93+
g = "thank you,for your confirmation , now i am goining to open your college world"
94+
voice(g)
95+
os.startfile("G:\\")
96+
97+
# todo webbrowser or internet
98+
elif "open youtube" in fun:
99+
g = "thank you,let's enjoy , now i am goining to open youtube"
100+
voice(g)
101+
w.open("http://youtube.com")
102+
103+
elif "open google" in fun:
104+
g = "thank you,let's go and explore , now i am goining to Google"
105+
voice(g)
106+
w.open("http://google.com")
107+
108+
elif "open gmail" in fun:
109+
g = "thank you,for your confirmation , now i am goining to open Gmail"
110+
voice(g)
111+
w.open("http://gmail.com")
112+
113+
# todo searching or playing
114+
115+
elif 'play and search' in fun:
116+
voice("where you want to search, Google or Youtube")
117+
f = speek()
118+
if f == 'google':
119+
voice("what you want to search, on googel")
120+
a = speek()
121+
voice("ok, i am searching on google" + a)
122+
w.open("http://google.com/search?q=" + a)
123+
elif f == 'youtube':
124+
voice("ok, what you want searching or playining on youtube")
125+
b = speek()
126+
if b == "searching":
127+
voice("ok, what you want to searching")
128+
a = speek()
129+
w.open("http://youtube.com/results?search_query=" + a)
130+
elif b == "playing":
131+
voice("ok, what you want to playing")
132+
a = speek()
133+
p.playonyt(a)
134+
135+
# todo command for system application
136+
137+
elif 'open vs code' in fun:
138+
g = "thank you,for your confirmation , now i am goining to open your vs code"
139+
voice(g)
140+
path = "C:/Users/hp/AppData/Local/Programs/Microsoft VS Code/Code.exe"
141+
os.startfile(path)
142+
143+
elif 'open pycharm' in fun:
144+
g = "thank you,for your confirmation , now i am goining to open your pycharm IDE"
145+
voice(g)
146+
path = "C:\\Program Files\\JetBrains\\PyCharm Community Edition 2022.1.3\\bin\\pycharm64.exe"
147+
os.startfile(path)
148+
149+
elif 'open firefox' in fun:
150+
g = "thank you,for your confirmation , now i am goining to open firefox"
151+
voice(g)
152+
path = "C:\\Program Files\\Mozilla Firefox\\firefox.exe"
153+
os.startfile(path)
154+
155+
elif 'open chrome' in fun:
156+
g = "thank you,for your confirmation , now i am goining to open chrome"
157+
voice(g)
158+
path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
159+
os.startfile(path)
160+
161+
elif 'open paint' in fun:
162+
g = "thank you,for your confirmation , now i am goining to open paint"
163+
voice(g)
164+
path = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Accessories\\Paint.lnk"
165+
os.startfile(path)
166+
167+
elif 'open notepad' in fun:
168+
g = "thank you,for your confirmation , now i am goining to open notepad"
169+
voice(g)
170+
path = "C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Accessories\\Notepad.lnk"
171+
os.startfile(path)
172+
173+
elif 'open python' in fun:
174+
g = "thank you,for your confirmation , now i am goining to open your python IDE"
175+
voice(g)
176+
path = "C:\\Users\\HP\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Python 3.9\\IDLE (Python 3.9 64-bit).lnk"
177+
os.startfile(path)
178+
179+
elif 'open any disc' in fun:
180+
g = "thank you,for your confirmation , now i am goining to open anydisk"
181+
voice(g)
182+
path = "C:\\Program Files (x86)\\AnyDesk\\AnyDesk.exe"
183+
os.startfile(path)
184+
185+
elif 'open java' in fun:
186+
g = "thank you,for your confirmation , now i am goining to open IntelliJ Java"
187+
voice(g)
188+
path = "C:\\Program Files\\JetBrains\\IntelliJ IDEA Community Edition 2021.3\\bin\\idea64.exe"
189+
os.startfile(path)
190+
191+
# todo command promt
192+
elif 'command line' in fun:
193+
g = "thank you,for your confirmation , now i am goining to open command line"
194+
voice(g)
195+
path = "C:\\Users\\HP\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\System Tools\\Command Prompt.lnk"
196+
os.startfile(path)
197+
198+
# todo send whatsaap msg
199+
elif 'whatsapp' in fun:
200+
g = "are you sure to open WhatsApp"
201+
voice(g)
202+
a=speek()
203+
if a=="yes":
204+
voice("please enter your security password")
205+
password = input("Password = ")
206+
if password == str(5550):
207+
g = "thank you,for your confirmation , now i am goining to open your WhatsApp"
208+
voice(g)
209+
w.open("https://web.whatsapp.com/")
210+
else:
211+
voice("Sorry Your Password is wrong please try after some time,Thankyou")
212+
else:
213+
voice("thank you,for your confirmation , now i am rejected your command")
214+
215+
# todo search in wikipedia
216+
elif 'wikipedia' in fun:
217+
voice("Searching Wikipidea......")
218+
cmd = speek()
219+
quary = fun.replace("wikipedia", "")
220+
result = wikipedia.summary(cmd, sentences=2)
221+
voice("According to wekipidea")
222+
print(result)
223+
voice(result)
224+
225+
else:
226+
g = "sorry,I'm not able to reconize your command please repeat it once"
227+
voice(g)

0 commit comments

Comments
 (0)