import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import smtplib
import pywhatkit
a = pyttsx3.init('sapi5')
voices = a.getProperty('voices')
a.setProperty('voice', voices[1].id)
def speak(audio):
a.say(audio)
a.runAndWait()
def wishMe():
hour = int(datetime.datetime.now().hour)
if hour>=0 and hour<12:
speak("Hello,Good Morning!")
elif hour>=12 and hour<18:
speak("Hello,Good Afternoon!")
else:
speak("Hello,Good Evening!")
speak("I am sesa. Please tell me how may I help you")
def take():
#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)
speak(audio)
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
if __name__ == "__main__":
wishMe()
while True:
# if 1:
query = take().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:
speak("Opening Youtube..")
webbrowser.open("youtube.com")
elif 'open Google' in query:
speak("Opening Google..")
webbrowser.open("google.com")
elif 'open photos' in query:
speak("Opening photos from your device..")
codePath = "C:\\Users\\HP\\Pictures"
os.startfile(codePath)
elif 'open documents' in query:
speak("Opening documents from your device..")
codePath = "C:\\Users\\HP\\Documents"
os.startfile(codePath)
elif 'open downloads' in query:
speak("Opening downloads from your device..")
codePath = "C:\\Users\\HP\\Downloads"
os.startfile(codePath)
elif 'desktop' in query:
speak("Please wait..")
codePath = "C:\\Users\\HP\\Desktop"
os.startfile(codePath)
elif 'play music' in query:
speak("Please choose the song you want to be played..")
music_dir = "C:\\Users\\HP\\Music"
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir))
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H:%M:%S")
speak(f"the time is {strTime}")
elif 'who are you' in query:
speak('I am sesa')
elif 'what can you do' in query:
speak('I can open utube,google,downloads,documents,desktop and
photos...i can play music..i can tell wikipedia..and i can search for the things
you want..')
elif 'search' in query:
import wikipedia as googlescrap
query=query.replace("google search","")
query=query.replace("google","")
speak("Here are your results..")
try:
pywhatkit.search(query)
result=googlescrap.summary(query,2)
print(result)
speak(result)
except:
speak("No readable data available...")
elif 'exit' in query or 'bye' in query or 'quit' in query:
speak("Ok bye...I am quiting....Thanks for your time.")
exit()