-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackup_04.txt
302 lines (199 loc) · 7.3 KB
/
backup_04.txt
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
import speech_recognition as sr
import pyttsx3
import webbrowser
import datetime
from datetime import date
import pywhatkit
import os
import smtplib
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import wikipedia
listener = sr.Recognizer()
listener_2 = sr.Recognizer()
engine = pyttsx3.init()
voices= engine.getProperty("voices")
engine.setProperty("voice",voices[1].id)
rate= engine.getProperty("rate")
engine.setProperty("rate", 150)
path="C:\\Program Files\\chromedriver.exe"
next=False
countSong=0
def speak(audio):
engine.say(audio)
engine.runAndWait()
engine.stop()
def confirm():
print(".................")
with sr.Microphone() as source:
listener.pause_threshold = 1
listener.adjust_for_ambient_noise(source, duration = 1)
voice= listener.listen(source)
try:
con= listener.recognize_google(voice, language='en-IN')
except Exception:
return ""
return con
def get_command():
with sr.Microphone() as source:
print("\nlistening...")
listener.pause_threshold = 1
voice= listener.listen(source, phrase_time_limit=5)
#listener.dynamic_energy_threshold = False
try:
print("recognizing...")
command= listener.recognize_google(voice, language='en-IN')
print(command+'\n')
except Exception:
print("I didn't catch it\n")
speak("I didn't catch it")
return "None"
return command
def date():
today= date.today()
date= today.strftime("%B %d, %Y")
print(date)
speak(date)
def play_onyt():
song= command.replace("play","")
speak("playing" +song)
pywhatkit.playonyt(song)
def music_offline(next,ftime):
music_source= "D:\\MC\\The Official UK Top 40 Singles Chart (06.11.2020) Mp3 (320kbps) [Hunter]\\The Official UK Top 40 Singles Chart (06.11.2020)"
songs= os.listdir(music_source)
if ftime==True:
print(songs)
else:
pass
global countSong
if next==True:
countSong+=1
songFile= os.startfile(os.path.join(music_source, songs[countSong]))
else:
songFile= os.startfile(os.path.join(music_source, songs[countSong]))
def send_email(reciever,msg):
x= reciever.replace(" ","")
y= x.lower()
print(f"Reciever's Email: {y}@gmail.com")
message=f'Subject: {"Email from Tharinda" }\n\n {msg}'
print(f"Message: {msg}")
server =smtplib.SMTP("smtp.gmail.com",587)
server.starttls()
server.login('tharindahp@gmail.com', 'seethepositiveside')
print("login ok")
server.sendmail('tharindahp@gmail.com', y+'@gmail.com' , message)
print("sent!!!")
def download_song(songName):
driver_1= webdriver.Chrome(path)
driver_1.get("https://musicpleer24.com/")
search= driver_1.find_element_by_id("searchField")
search.send_keys(songName)
search.send_keys(Keys.RETURN)
time.sleep(3)
speak("Now you can choose the exact one and click on it")
def go_to_wikipedia():
driver_2= webdriver.Chrome(path)
driver_2.get("https://www.wikipedia.org/")
time.sleep(2)
try:
with sr.Microphone() as source:
speak("What do you want to search?")
print("listening...")
voice= listener.listen(source, phrase_time_limit=6)
print("recognizing...")
thing= listener_2.recognize_google(voice, language="en-IN")
driver_2.maximize_window()
search= driver_2.find_element_by_id("searchInput")
search.send_keys(thing)
search.send_keys(Keys.RETURN)
speak("Here is what I found")
except Exception:
pass
def go_to_google(command):
editCommand= command.replace("search google", "")
try:
driver_3= webdriver.Chrome(path)
driver_3.get("https://www.google.com/")
search= driver_3.find_element_by_name("q")
search.send_keys(editCommand)
time.sleep(1)
search.send_keys(Keys.RETURN)
driver_3.maximize_window()
time.sleep(1)
speak("Here is what i found on google")
except Exception:
print("N")
def play_on_yt(command):
song= command.replace("play", "")
pywhatkit.playonyt(song)
time.sleep(2)
speak(f'Playing {song} on youtube')
def get_from_wikipedia(command):
try:
data= wikipedia.summary(command, sentences=2)
speak("According to wikipedia")
print(data)
speak(data)
except Exception:
print("sorry, I couldn't get there")
speak("sorry, I couldn't get there")
def start():
command= get_command().lower()
if "open bing" in command:
webbrowser.open("bing.com")
speak("Opening Bing")
elif "open youtube" in command:
webbrowser.open("youtube.com")
speak("Opening Youtube")
elif "search google" in command:
go_to_google(command)
elif "play" and "music" and "offline"in command:
music_offline(next=False, ftime=True)
elif "next song" in command:
music_offline(next=True, ftime=False)
elif "the date" in command:
date()
elif "time" in command:
time= datetime.datetime.now().strftime('%I:%M %p')
print(time)
speak(f'Current time is{time}')
elif "wikipedia" in command:
go_to_wikipedia()
elif "play" in command:
play_on_yt(command)
elif "who is" or "what is" or "where is" or "tell me about" in command:
get_from_wikipedia(command)
elif "download" and "song" in command:
songName= command.replace("download the song", "")
download_song(songName)
elif "send an email" or "send a mail" or "send mail" in command:
speak("Who do you want to send?")
with sr.Microphone() as source:
print("listening...")
voice= listener.listen(source, phrase_time_limit=5)
try:
reciever= listener.recognize_google(voice, language='en-IN')
print(reciever)
except Exception:
speak("sorry, I couldn't hear Say again")
time.sleep(4)
speak("Tell me your message")
with sr.Microphone() as source:
print("listening...")
voice= listener.listen(source, phrase_time_limit=8)
print("recognizing...")
try:
msg= listener.recognize_google(voice, language='en-IN')
except Exception:
speak("sorry, I couldn't hear.Say again.")
send_email(reciever,msg)
speak("Your email was sent")
elif "what's your name" or "your name" in command:
speak("I'm alpha")
elif "who are you" in command:
speak("I'm your personal assistance at the moment")
elif "are you single" in command:
speak("Yes, I'm single")
else:
go_to_google(command)