E-mail Sender using Voice Recognition

This is a gui program which utilises tkinter (for gui), smtplib (to send email), pyttsx3 (text to speech) and speech_recognition (for voice recognition) libraries to send emails with a very little effort.

Code:

from tkinter import *
from PIL import ImageTk, Image
import speech_recognition as sr
import pyttsx3
import smtplib

def speak(c):
    e = pyttsx3.init()
    e.say(c)
    e.runAndWait()

r = sr.Recognizer()

def click():
    o = smtplib.SMTP("smtp.gmail.com"587)
    o.starttls()
    o.login("visualspprt@gmail.com""Help@123")

    while(1):
        try:
            with sr.Microphone() as st:
                r.adjust_for_ambient_noise(st,duration=0.2)
                speak("Welcome to the voice recognition mail sender, how may i help
you")
                a2 = r.listen(st)
                mt = r.recognize_google(a2)
                mt = mt.lower()
                #print(f"Did you said '{mt}'?")
                if "send mail" in mt:
                    speak("ok, what is the recipents id")
                    a2 = r.listen(st)
                    mt = r.recognize_google(a2)
                    re = mt.replace(" ","") + "@gmail.com"
                    recipent = [re]
                    speak("ok, got it, what should be the subject of your mail")
                    a2 = r.listen(st)
                    mt = r.recognize_google(a2)
                    subject = mt
                    speak("ok, what is the message you want to send")
                    a2 = r.listen(st)
                    mt = r.recognize_google(a2)
                    body = mt
                    message = f"Subject:{subject}\n\n{body}"
                    o.sendmail("visualspprt", recipent, message)  
                    o.quit()
                    speak("email succwssfully sent")         
                if "exit" in mt:
                    speak("Thanks for using our service, hope you liked it Please
provide your valuable feedback on our mail, visualspprt@gmail.com, have a great day")
                    break
        except Exception as e:
            #print(e)
            speak("exception occored")


root = Tk()
root.title(" Voice based Email service for visually challenged people")
root.geometry("1000x900+10+10")
root.configure(bg="white")
img = ImageTk.PhotoImage(Image.open("mic.png"))
Button(root, image=img, border=0command=click).place(relx=0.5rely=0.5,
anchor=CENTER)

Button(root, text="Exit"command=root.quit).pack(side=BOTTOM)


root.mainloop()


Comments

Popular posts from this blog

HangMan game in PYTHON

Projects to consider as a bigener in PYTHON

Tic-Tac-Toe (multiplayer) using pthon