# pip install pyaudio
import datetime
import os
import smtplib
import webbrowser
import pyttsx3 # pip install pyttsx3
import pywhatkit
import speech_recognition as sr # pip install speechRecognition
import wikipedia # pip install wikipedia
engine = [Link]('sapi5')
voices = [Link]('voices')
# print(voices[1].id)
[Link]('voice', voices[1].id)
def speak(audio):
[Link](audio)
[Link]()
def wishMe():
hour = int([Link]().hour)
if hour>=0 and hour<12:
speak("Good Morning!")
elif hour>=12 and hour<18:
speak("Good Afternoon!")
else:
speak("Good Evening!")
speak("hello i am your assistant sofia how may I help you ")
def takeCommand():
#It takes microphone input from the user and returns string output
r = [Link]()
with [Link]() as source:
print("Listening...")
r.pause_threshold = 1
audio = [Link](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(to, content):
server = [Link]('[Link]', 587)
[Link]()
[Link]()
[Link]('projectminiv@[Link]', 'vnlxewvpyqtprupj')
[Link]('projectminiv@[Link]', to, content)
[Link]()
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 = [Link]("wikipedia", "")
results = [Link](query, sentences=2)
speak("According to Wikipedia")
print(results)
speak(results)
elif 'open youtube' in query:
[Link]("[Link]")
elif 'please introduce us and yourself' in query:
speak("Hello everyone my name is sofia and i am a voice
assistant created by Omkar,Snehal and Shivraj")
print("Hello everyone my name is sofia and i am a voice
assistant created by Omkar,Snehal ,Shivraj")
elif 'open google' in query:
[Link]("[Link]")
elif 'open stackoverflow' in query:
[Link]("[Link]")
elif 'hello sofia' in query or "hello" in query:
speak("hello nice to meet you How are you")
elif 'how are you' in query:
speak("i am fine thank you for asking")
elif 'i am good' in query or 'i am fine' in query:
speak("nice to hear that")
elif 'play bhajans' in query:
music_dir = 'C:\\Users\\music\\bhajans'
songs = [Link](music_dir)
print(songs)
[Link]([Link](music_dir, songs[0]))
elif 'play songs' in query:
music_dir = 'C:\\Users\\music\\Arijit Singh'
songs = [Link](music_dir)
print(songs)
[Link]([Link](music_dir, songs[0]))
elif 'whatsapp to snehal' in query:
speak("What should I say?")
content = takeCommand()
from datetime import datetime, timedelta
current_time = [Link]()
scheduled_time = current_time + timedelta(seconds=60)
[Link]("+919004946621", content,
scheduled_time.hour, scheduled_time.minute)
elif 'whatsapp to omkar' in query:
speak("What should I say?")
content = takeCommand()
from datetime import datetime, timedelta
current_time = [Link]()
scheduled_time = current_time + timedelta(seconds=60)
[Link]("+919967253454", content,
scheduled_time.hour, scheduled_time.minute)
elif 'the time' in query:
strTime = [Link]().strftime("%H:%M:%S")
speak(f"the time is {strTime}")
print(strTime)
elif 'open my ppt' in query:
speak("opening Power Point presentation")
power = r"C:\Users\barka\OneDrive\Documents\[Link]"
[Link](power)
elif 'open code' in query:
codePath =
"C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\[Link]"
[Link](codePath)
elif 'send email to snehal' in query:
try:
speak("What should I say?")
content = takeCommand()
print(content)
to = "barkalesnehal1@[Link]"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Sorry I am not able to send this email")
elif 'send email to omkar' in query:
try:
speak("What should I say?")
content = takeCommand()
print(content)
to = "barkalesnehal1@[Link]"
sendEmail(to, content)
speak("Email has been sent!")
except Exception as e:
print(e)
speak("Sorry I am not able to send this email")
elif " search youtube" in query:
try:
speak("this is what i found")
query = [Link]("youtube search","")
query = [Link]("youtube", "")
query = [Link]("sofia", "")
web = "[Link] +
query
[Link](web)
[Link](query)
except Exception as e:
print(e)
speak("Sorry")
else:
print("No query matched")