Complete Code
Complete Code
In [2]:
def Text_to_speech(content):
engine = tts.init()
#engine.setProperty('rate', 580)
engine.say(content)
engine.runAndWait()
return
In [4]:
def Compose_email(recipients_Email_Id,subject,body):
print('Sending the Email, please wait.')
Text_to_speech('Sending the Email, please wait.')
message = MIMEMultipart()
message['From'] = sender_Email_Id
if(len(recipients_Email_Id) > 1):
message['To'] = ' ,'.join(recipients_Email_Id)
else:
message['To'] = ' '.join(recipients_Email_Id)
message['Subject'] = subject
message.attach(MIMEText(body,'plain'))
context = create_default_context()
try:
with SMTP_SSL('smtp.gmail.com',465,context = context) as server:
server.login(sender_Email_Id,sender_AppKey)
print('success')
server.sendmail(sender_Email_Id,recipients_Email_Id,message.as_
print('Email Sent Successfully!!!')
Text_to_speech('Email Sent Successfully')
print("Sir, I'm done with this task")
Text_to_speech("Sir, I'm done with this task")
return
except:
print('Error encountered while sending the email!!!\nPlease check t
Text_to_speech('Error encountered while sending the email. Please c
return
In [5]:
def contact_list():
recipient_emails = []
print('Sir, once please listen to the contact list')
Text_to_speech('Sir, once please listen to the contact list')
for i in contacts:
print(f'{i}:{contacts[i]}')
Text_to_speech(f'{i}:{contacts[i]}')
while(1):
print('Sir, please speak out the recipients you want to include (e.
Text_to_speech('Sir, please speak out the recipients you want to in
recipients_input = Speech_to_text().lower().split(' and ')
for recipient_input in recipients_input:
for j in contact_lst:
if any(alias.lower() in recipient_input for alias in [j] +
recipient_emails.append(contacts[j])
break
In [6]:
def sending_email():
recipients = contact_list()
Text_to_speech('Please speak the subject of the Email')
print('Please speak the subject of the Email:')
subject = Speech_to_text()
print(subject)
Text_to_speech('Please speak the body of the Email')
print('Please speak the body of the Email')
body = Speech_to_text()
print(body)
Compose_email(recipients,subject,body)
In [7]:
def sanitize_gmail_subject(subject):
return sanitized_subject
mail_obj = IMAP4_SSL("imap.gmail.com")
mail_obj.login(sender_Email_Id, sender_AppKey)
subject = decode_header(email_content_in_string_obj_format['Subject
if email_content_in_string_obj_format.is_multipart():
print("Subject: ", sanitize_gmail_subject(subject))
Text_to_speech(f"Subject: {sanitize_gmail_subject(subject)}")
print(f"From: {decode_header(email_content_in_string_obj_format
Text_to_speech(f"From: {decode_header(email_content_in_string_o
print(f"Date: {decode_header(email_content_in_string_obj_format
Text_to_speech(f"Date: {decode_header(email_content_in_string_o
for part in email_content_in_string_obj_format.walk():
content_disposition = part.get_content_disposition()
else:
print("Subject: ", sanitize_gmail_subject(subject))
Text_to_speech(f"Subject: {sanitize_gmail_subject(subject)}")
print(f"From: {decode_header(email_content_in_string_obj_format
Text_to_speech(f"From: {decode_header(email_content_in_string_o
print(f"Date: {decode_header(email_content_in_string_obj_format
Text_to_speech(f"Date: {decode_header(email_content_in_string_o
Text_to_speech("Sir, I encountered a HTML integrated email, so
print("HTML INTEGRATED EMAIL")
file_name = f'{sanitize_gmail_subject(subject)}.html'
if file_name:
output_location = os.path.join(default_path_to_save_html_in
os.makedirs(os.path.dirname(output_location), exist_ok=True
with open(output_location, 'w', encoding='utf-8') as op:
op.write(email_content_in_string_obj_format.get_payload
print("/" * 150)
mail_obj.logout()
In [ ]:
# Driver Code
print('Welcome to the Voice Powered Gmail Assistant')
Text_to_speech('Welcome to the Voice Powered Gmail Assistant')
while(1):