-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.py
45 lines (41 loc) · 1.09 KB
/
mailer.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
import smtplib
import os
import config
import playsound
import speech_recognition as sr
from gtts import gTTS
def recognise():
r = sr.Recognizer()
with sr.Microphone() as source:
print("listening.....")
audio = r.listen(source)
try:
text = r.recognize_google(audio)
return text
except:
return False
def speak(text):
voice=gTTS(text=text,lang="en",slow=False)
file="voice.mp3"
voice.save(file)
playsound.playsound(file,True)
os.remove(file)
def send_mail(to,msg):
try:
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login(config.email,config.password)
s.sendmail(config.email,to, msg)
s.quit()
print()
print("message sent successfully")
speak("message sent successfully")
except:
print()
print("error sending the message")
speak("error sending the message")
speak("can you please specify the recipant of you mail")
to=recognise()
speak("what is the message you want to send")
msg=recognise()
send_mail(to,msg)