-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanything.py
183 lines (135 loc) · 4.41 KB
/
anything.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
from asyncio import exceptions
from datetime import datetime
from email.mime import audio
import speech_recognition as sr
import googletrans
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes
import PyPDF2
import gtts
import playsound
import smtplib
from myid import password, my_gmail , destination
p = password
g = my_gmail
d = destination
r = sr.Recognizer()
translator = googletrans.Translator()
engine = pyttsx3.init()
def talk(text):
engine.say(text)
#engine.say('What can I do for you')
engine.runAndWait()
#mic = sr.Microphone()
#sr.Microphone.list_microphone_names()
def take_command():
try:
with sr.Microphone() as source:
print("Listening...")
r.adjust_for_ambient_noise(source, duration= 1)
voice = r.listen(source)
command = r.recognize_google(voice)
if 'alexa' in command:
command = command.replace('kari', '')
talk(command)
except:
print("sorry could not recognize")
return command
def pdf_reader():
book = open('os.pdf','rb')
read = PyPDF2.PdfFileReader(book)
pages = PyPDF2.PdfReader.numPages
engine("Total number of pages in this pdf{pages} ")
engine("Enter the page number i have to read:")
pg = int(input())
page = read.getPage(pg)
text = page.extractText()
talk(text)
def whatsAppmsg():
pywhatkit.sendwhatmsg('7976989128', 'hey! this is kanu ka kari :p')
def greet():
t_hour = datetime.datetime.now().hour
if 24> t_hour < 4:
talk('Good night and have sweet dreams ')
elif 12> t_hour > 4:
talk('Good morning')
elif 12< t_hour <17:
talk('Good afternoon')
else:
talk('Good evening')
print(t_hour)
def sendemail(to, content):
server = smtplib.SMTP('smtp.gmail.com',587)
server.ehlo() #to connect our server to gmail server
server.starttls()
server.login(g,p)
server.sendmail(g,d, 'Mail from kanu ka Kari' )
server.close()
def trans_text():
trans_lang = 'hi'
try:
with sr.Microphone() as source:
print("Listening...")
r.adjust_for_ambient_noise(source, duration= 1)
voice = r.listen(source)
command = r.recognize_google(voice)
regional = translator.translate(command , dest = trans_lang )
print(regional.command)
converted_audio = gtts.gTTS(regional.command, lang= trans_lang)
converted_audio.save('regionallang.mp3')
playsound.playsound('regionallang.mp3')
except:
print("sorry could not recognize")
return command
if __name__ == "__main__":
while True:
command = take_command()
print(command)
if 'play' in command:
song = command.replace('play','')
talk('playing'+ song)
pywhatkit.playonyt(song)
elif 'time' in command:
time = datetime.datetime.now().strftime('%I:%M %p')
print(time)
talk('Current time is ' + time)
elif 'tell me about ' in command:
person = command.replace('tell me about', '')
info = wikipedia.summary(person, 3)
print(info)
talk(info)
elif 'date' in command :
talk('sorry ,i have a date with wifi')
elif 'are you single' in command:
talk('i have a girlfriend')
elif 'joke' in command:
print(pyjokes.get_joke())
talk(pyjokes.get_joke())
elif 'read pdf' in command:
pdf_reader()
elif 'WhatsApp' in command:
pywhatkit.sendwhatmsg('+917976989128', 'hey! this is kanu ka Alexa :p',16,40)
elif 'send email' in command:
try:
talk("what should i mail")
content = take_command()
to = d
sendemail(to, content)
talk('email sent successfully')
except Exception as e:
print(e)
talk('email has not been sent')
elif 'translate' in command:
talk('what should i translate for you')
trans_text()
elif 'greet' in command:
greet()
elif 'bye' in command:
exit()
else:
talk('Please say the command again.')
#translated = translator.translate(text)
#print(translated.text)