-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAI(pyttsx3).py
231 lines (132 loc) · 6.21 KB
/
AI(pyttsx3).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
import pyttsx3 # pip install pyttsx3
import speech_recognition as sr # pip install speech_recognition
import datetime
import wikipedia # pip install wikipedia
import webbrowser
import os
import smtplib
import googlesearch #pip install googlesearch
from googlesearch import search
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) #id [1], for female voice.
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<18:
speak("Good Afternoon!")
else:
speak("Wonderfull evening")
speak("I am /NameOfYourAI\, what can i do for you, Master ")
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Let me listen")
r.pause_threshold = 0.5
audio = r.listen(source)
try:
print("i am processing")
query = r.recognize_google(audio, language='en-in') # Google is the best when inputing audio data from user
print(f"your query: {query}\n")
except Exception:
#keeps the Loop working until terminating command is run
speak(f'what else i can do for you?')
print("Please repeat")
return "None"
return query
if __name__ == "__main__":
wishMe()
while True:
query = takeCommand().lower()
if 'what is' in query :
chrome_path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s' #Your Google Chore directory
speak(f'let me search it for you')
query1=""
list_needed=""
str1=""
if 'what is' in query :
list_name=list(query)
list_needed=list_name[8:]
for ele in list_needed:
str1 += ele
for url in search(str1, tld="co.in", num=1, stop = 1, pause = 2):
webbrowser.open("https://google.com/search?q=%s" % str1)
elif 'who is' in query:
chrome_path = r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe %s'
speak(f'let me see who are you talking about')
query2=""
list_needed=""
str2=""
if 'who is' in query :
list_name=list(query)
list_needed=list_name[7:]
for word in list_needed:
str2 += word
for url in search(str2, tld="co.in", num=1, stop = 1, pause = 2):
webbrowser.open("https://google.com/search?q=%s" % str2)
elif 'wikipedia' in query :
print('Fetching results from Wikipedia, PLease stay patient')
query = query.replace("wikipedia", "")
results = wikipedia.summary(query, sentences=2)
speak(f' i ll fetch the results from wiki pedia , it takes me , seconds to read that data base, please wait')
speak("Wikipedia says")
print(results)
speak(results)
elif 'open youtube' in query:
print("Opening Youtube in a new window")
webbrowser.open("youtube.com")
elif 'open google' in query:
print("Opening Google")
webbrowser.open("google.com")
elif 'open facebook' in query:
print("Opening facebook")
webbrowser.open("facebook.com")
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"Sir, the time by my atomic clock is {strTime}")
print(strTime)
elif 'who are you' in query:
speak(f'I am a brainchild of my sole creator, /YourName\.')
elif 'why were you created' in query:
speak(f'#yourCreativeAnswer')
elif 'what is the best coding language' in query:
speak(f'Obviously Python and its other varyants, how come you even ask that, but more likely i should be biased, hence all are pretty amazing')
elif 'where to study coding' in query:
speak(f'there are a lot of websites that teach coding, still my favourite is W3 Schools, and geeks for geeks')
webbrowser.open("www.w3schools.com")
webbrowser.open("www.geeksforgeeks.org")
''''
elif 'where is' in query:
speak(f'let me see where you want to go')
list_needed=""
str3=""
if 'where is' in query :
list_name=list(query) # This section is underdevelopment, using the Google_Maps API
query2=""
list_needed=list_name[7:]
for word in list_needed:
str3 += word
for url in search(str3, tld="co.in", num=1, stop = 1, pause = 2):
webbrowser.open("https://www.google.com/search?q=%s" % str3)
''''
elif 'please open' in query:
speak(f'let me open it via your chosen browser')
list_needed=""
str4=""
if 'please open' in query :
list_name=list(query)
list_needed=list_name[11:]
for word in list_needed:
str4 += word
for url in search(str4, tld="co.in", num=1, stop = 1, pause = 2):
webbrowser.open("https://www.google.com/search?q=%s" % str4)
elif 'bye take care' in query:
speak(f"Thank you for listening to /YourAI\ ")
print("Exiting, thanks for using my interface")
break
# add your queries at will
# happy coding