Ai project : computer asistent

import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib


engine = pyttsx3.init('sapi5')
voices= engine.getProperty('voices')
# print(voices[0].id)
engine.setProperty('voice', voices[1].id)
def speak (audio):
    # pass
    engine.say(audio)
    engine.runAndWait()


def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning!")

    elif hour>=12 and hour<18:
        speak("Good Afternoon!")   

    else:
        speak("Good Evening!")  

    speak("I am Riimaa . Please tell me how may I help you")

def takeCommand():
    #It takes microphone input from the user and returns string output

    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in')
        print(f"User said: {query}\n")

    except Exception as e:
        # print(e)    
        print("Say that again please...")  
        return "None"
    return query


def sendEmail(tocontent):
    server = smtplib.SMTP('smtp.gmail.com'587)
    server.ehlo()
    server.starttls()
    server.login('alauddinmallick52@gmail.com''Arman@class09')
    server.sendmail('aryanmollick10@gmail.com', to, content)
    server.close()


if __name__ == '__main__':

    wishMe()
    while True:
    # if 1:
        query = takeCommand().lower()

        # Logic for executing tasks based on query
        if 'wikipedia' in query:
            speak('Searching Wikipedia...')
            query = query.replace("wikipedia""")
            results = wikipedia.summary(query, sentences=2)
            speak("According to Wikipedia")
            print(results)
            speak(results)
        
        elif 'open youtube' in query:
            webbrowser.open("youtube.com")


        elif 'hello' in query:
            speak("Hi Aarryyaann! How can i Help you sir?")
        elif 'how are you' in query:
            speak("I am good. How may i help you.")
        elif 'nothing' in query:
            speak("Ok fine. I am always here.")
        elif 'thank you' in query:
            speak("No problem! i am always here to help you")
            





        elif 'open google' in query:
            webbrowser.open("google.com")

        elif 'open gmail' in query:
            webbrowser.open("https://mail.google.com/mail/u/1/#inbox")
        elif 'open wikipedia' in query:
            webbrowser.open("www.wikipedia.org")

        elif 'open stackoverflow' in query:
            webbrowser.open("stackoverflow.com")   

        elif 'play music' in query:
            music_dir = 'E:\Downloads\Music'
            songs = os.listdir(music_dir)
            print(songs)    
            os.startfile(os.path.join(music_dir, songs[1]))

        elif 'the time' in query:
            strTime = datetime.datetime.now().strftime("%H:%M:%S")    
            speak(f"Sir, the time is {strTime}")

        elif 'open code' in query:
            codePath = "C:\\Users\\Alauddin\\Desktop\\Visual Studio Code"
            os.startfile(codePath)

        elif 'open Chrome' in query:
            chPath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome"
            os.startfile(chPath)
        elif 'open paint' in query:
            pPath = "C:\\Windows\\system32\\mspaint"
            os.startfile(pPath)
        elif 'open calculator' in query:
            calPath = "C:\\Windows\\system32\\calc"
            os.startfile(calPath)
        elif 'open notepad' in query:
            notePath = "C:\\Windows\\system32\\notepad"
            os.startfile(notePath)      
        
        elif 'email' in query:
             try:
                 speak("what should I say")
                 content = takeCommand()
                 to = "aryanmollick10@gmail"
                 sendEmail(to, content)
                 speak("email has been sent!")
             except Exception as e:
                 print"sorry")
       
        # elif 'open computer' in query:

        #     codePath = "computer"
        #     os.startfile(codePath)
    # speak("Good Morning. How are you?")

Comments

Popular posts from this blog

Corona project(python)