Sunday, August 30, 2020

Eaglesoft Assistant Source code

import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import os
import smtplib

engine=pyttsx3.init('sapi5')
voices=engine.getProperty('voices')
# print(voices[0].id)
engine.setProperty('voice',voices[0].id)

def spkeak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
hour=int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
spkeak("Good Morning")

elif hour>=12 and hour<18:
spkeak("Good Afternoon")
else:
spkeak("Good Evening")

spkeak("I am Eaglesoft Assistant sir. Please tell me how may help you")

def takeCommand():
#it takes input from microphone and return string
r=sr.Recognizer()
with sr.Microphone() as source :
print("Listening...")
r.pause_threshold=1
audio=r.listen(source)
try:
print("Recognizing...")
qurey=r.recognize_google(audio,language='en-in')
print(f"User said: {qurey}\n")

except Exception as e:
# print(e)
print("Say that again please...")
return "None"
return qurey
def sendemail(to,content):
server=smtplib.SMTP("smtp@gmail.com",587)
server.ehlo()
server.starttls()
server.login("youreemail@gmail.com","you're-password")
server.sendmail("you'reemail@gmail.com",to,content)
server.close()




if __name__ == '__main__':
wishme()
while True:
query=takeCommand().lower()
#Logic for executing base on query
if "wikipedia" in query:
spkeak("Searching Wikipedia...")
query=query.replace("wikipedia","")
results=wikipedia.summary(query,sentences=2)
spkeak("According to Wikipedai")
print(results)
spkeak(results)
elif "open youtube" in query:
webbrowser.open("youtube.com")
elif "open google" in query:
webbrowser.open("google.com")
#elif "open Developer of this program" in query:
# webbrowser.open("https://eaglesoftpk.blogspot.com/")
elif "open facebook" in query:
webbrowser.open("facebook.com")
elif "open stackoverflow" in query:
webbrowser.open("stackoverflow.com")
elif "Play music" in query:
music_dir='G:\\Media\\audio tool'
songs=os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir,songs[0]))
elif "The time" in query:
strTime=datetime.datetime.now().strftime("%H:%M:%S")
spkeak(f"Sir, the time is {strTime}")
print(strTime)
elif "open code" in query:
codePath="C:\\Users\\Eaglesoft\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
os.startfile(codePath)
elif "open Chrome" in query:
Gpath="C:\\Users\\Eaglesoft\\AppData\\Local\\Google\Chrome\\Application\\chrome.exe"
os.startfile(Gpath)
elif "Email to Ansir" in query:
try:
spkeak("What should I say?")
content=takeCommand()
to="ansar.eaglesoft@gmail.com"
sendemail(to,content)
spkeak("Email has been sent!")
except Exception as e:
print(e)
spkeak("Sorry sir. I am not able to send email")
elif "quit" in query:
exit()



# spkeak("Eaglesoft is one of the best Software Company in Pakistan")

1 comment: