-
Notifications
You must be signed in to change notification settings - Fork 104
/
Voice_Recognition_AutomationBot.py
73 lines (56 loc) · 2.03 KB
/
Voice_Recognition_AutomationBot.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
import smtplib
from email.message import EmailMessage
import speech_recognition as sr
import pyttsx3
listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[1].id)
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server_login_mail = "[email protected]" # enter your own email here,if it raises SMTPAuthenticationError(code, resp) then allow less secure apps in your email security settings to login using this script
server_login_password = "yourpassword13@$" # enter your own email password here
server.login(server_login_mail, server_login_password)
def say(text):
engine.say(text)
engine.runAndWait()
say("hello sir, how can i help you? myself email assistant")
def assistant_listener():
try:
with sr.Microphone() as source:
print("Listening...")
voice = listener.listen(source)
info = listener.recognize_google(voice, language="en-in").lower()
return info
except:
return "no"
def send_email(rec, subject, message):
email = EmailMessage()
email["From"] = server_login_mail
email["To"] = rec
email["Subject"] = subject
email.set_content(message)
server.send_message(email)
contact = {
"google": "[email protected]",
# please add your contacts mails here
}
def whattodo():
listen_me = assistant_listener()
if "assistant" in listen_me: # say "assistant to call the bot"
if "write mail" in listen_me:
say("To whom you want to send mail?")
user = assistant_listener()
try:
email = contact[user]
except:
say(user + " not found in your contacts!")
return 0
say("What you want to be subject?")
subject = assistant_listener()
say("what should be the message?")
message = assistant_listener()
send_email(email, subject, message)
say("Email Send Successfully")
while True:
whattodo()