-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
193 lines (152 loc) · 6.57 KB
/
index.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
import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib
import random
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices[0].id)
engine.setProperty('voice', voices[1].id)
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Good Morning! ")
elif hour>=12 and hour<17:
speak("Good Afternoon! ")
elif hour>=17 and hour<19 :
speak("ooh hii! ")
else:
speak("you still awwake")
speak("I am your Vertual Assistant Olivia. Please tell me how may I help you")
def takeCommand():
#It takes microphone input from the user and returns string output
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-in')
print(f"User said: {query}\n")
except Exception as e:
#print(e)
print("Say that again please...")
speak("Connection error")
return "None"
return query
if __name__ == "__main__":
wishMe()
while True:
query = takeCommand().lower()
# Logic for executing tasks based on query
if 'wikipedia' in query:
speak('Searching Wikipedia...')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
elif "hello" in query or "hello Olivia" in query:
hello1 = "Hello ! How May i Help you.."
print(hello1)
speak(hello1)
elif "who are you" in query or "about you" in query or "your details" in query:
who_are_you = "I am Olivia an A I based computer program but i can help you lot like a your assistant ! try me to give simple command !"
print(who_are_you)
speak(who_are_you)
elif 'who make you' in query or 'who made you' in query or 'who created you' in query or 'who develop you' in query:
speak(" For your information Shobnom Islam Created me ! I can show you her Linked In profile if you want to see. Yes or no .....")
ans_from_user_who_made_you = takeCommand()
if 'yes' in ans_from_user_who_made_you or 'ok' in ans_from_user_who_made_you or 'yeah' in ans_from_user_who_made_you:
webbrowser.open("https://www.linkedin.com/in/shabnam-islam-50b7901b9")
speak('opening her profile...... please wait')
elif 'no' in ans_from_user_who_made_you or 'no thanks' in ans_from_user_who_made_you or 'not' in ans_from_user_who_made_you:
speak("All right ! OK...")
else :
speak("I can't understand. Please say that again !")
elif 'open youtube' in query:
webbrowser.open("www.youtube.com")
speak("opening youtube")
elif 'open github' in query:
webbrowser.open("https://www.github.com")
speak("opening github")
elif 'open facebook' in query:
webbrowser.open("https://www.facebook.com")
speak("opening facebook")
elif 'open instagram' in query:
webbrowser.open("https://www.instagram.com")
speak("opening instagram")
elif 'open google' in query:
webbrowser.open("google.com")
speak("opening google")
elif 'open stackoverflow' in query:
webbrowser.open("stackoverflow.com")
speak("opening stackoverflow")
elif 'open yahoo' in query:
webbrowser.open("https://www.yahoo.com")
speak("opening yahoo")
elif 'open gmail' in query:
webbrowser.open("https://mail.google.com")
speak("opening google mail")
elif 'open snapdeal' in query:
webbrowser.open("https://www.snapdeal.com")
speak("opening snapdeal")
elif 'open amazon' in query or 'shop online' in query:
webbrowser.open("https://www.amazon.com")
speak("opening amazon")
elif 'open flipkart' in query:
webbrowser.open("https://www.flipkart.com")
speak("opening flipkart")
elif 'play music' in query:
speak("ok i am playing music")
music_dir = 'E:\music'
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[1]))
elif 'video from pc' in query or "video" in query:
speak("ok i am playing videos")
video_dir = 'Videos'
Videos = os.listdir(video_dir)
print(Videos)
os.startfile(os.path.join(video_dir,Videos[1]))
elif 'good bye' in query:
speak("good bye")
exit()
elif "shutdown" in query:
speak("shutting down")
os.system('shutdown -s')
elif "what is your name" in query or "sweat name" in query:
naa_mme = "Thanks for Asking my self ! Olivia"
print(naa_mme)
speak(naa_mme)
elif "how are you feeling" in query:
print("feeling Very happy to help you")
speak("feeling Very happy to help you")
elif query == 'none':
continue
elif 'exit' in query or 'stop' in query or 'quit' in query :
exx_exit = 'See you soon. Bye'
speak(exx_exit)
exit()
elif 'What is the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"the time is {strTime}")
elif 'how are you' in query:
setMsgs = ['Just doing my thing!', 'I am fine!', 'Nice!']
ans_qus = random.choice(setMsgs)
speak(ans_qus)
speak(" How are you'")
ans_from_user_how_are_you = takeCommand()
if 'fine' in ans_from_user_how_are_you or 'happy' in ans_from_user_how_are_you or 'okey' in ans_from_user_how_are_you:
speak('Great')
elif 'not' in ans_from_user_how_are_you or 'sad' in ans_from_user_how_are_you or 'upset' in ans_from_user_how_are_you:
speak('Tell me how can i make you happy')
else :
speak("I can't understand. Please say that again !")