How to make personal ai using python || Jarvish ai using python
CODE:
import pyttsx3 #pip install wikipedia
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')#sapi5 is used for ai voice
voices = engine.getProperty('voices')
# print(voices[1].id)
engine.setProperty('voice', voices[0].id) #there are two ai voice 0 and 1
def speak(audio):
engine.say(audio)
engine.runAndWait()
def wishme():
speak("Hii,<YOUR NAME>")
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 jarvish ai,")
speak("please tell me how may i help you")
def takecommand():
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
if __name__ == "__main__":
wishme()
while True:
query = takecommand().lower()
if 'wikipedia' in query:
speak("searching wikipedia....")
query= query.replace("wikipedia","")
results = wikipedia.summary(query, sentences = 2)
speak("Accourding to wikipedia")
print(results)
speak(results)
elif 'open google' in query:
webbrowser.open("google.com")
elif 'open youtube' in query:
webbrowser.open("youtube.com")
elif 'open chat GPT' in query:
webbrowser.open("chatgpt.com")
elif 'open code' in query:
codepath = "Visual studio code path"
os.startfile(codepath)
elif 'open watsapp' in query:
webbrowser.open("web.watsapp.com")
elif 'play song' in query:
music_dir ='<MUSIC DIRECTORY LINK>'
songs=os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir,songs[0]))
elif 'open website' in query:
speak("Which website would you like to open?")
website_query = takecommand().lower()
open_website(website_query)
elif 'exit' in query or 'stop' in query:
speak("Thank you sir!")
speak("Good bye!")
break
OUTPUT:
Comments
Post a Comment