0% found this document useful (0 votes)
84 views2 pages

Jarvis

The document defines functions for a voice assistant using Python libraries like pyttsx3, speech recognition and Wikipedia. It initializes the text-to-speech engine, defines functions for greeting the user based on time of day, taking the user's voice command and performing actions like opening websites, searching Wikipedia or exiting based on the command.

Uploaded by

Sravya Tummala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views2 pages

Jarvis

The document defines functions for a voice assistant using Python libraries like pyttsx3, speech recognition and Wikipedia. It initializes the text-to-speech engine, defines functions for greeting the user based on time of day, taking the user's voice command and performing actions like opening websites, searching Wikipedia or exiting based on the command.

Uploaded by

Sravya Tummala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

import pyttsx3

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

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

def speak(audio):
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(" Hi, I am jarvis . 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("Recongnizing...")
query = r.recognize_google(audio, language='en-in')
print(f"user said: {query}\n")

except Exception as e:
#print(e)
print("please repeat ...")
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("According to wikipedia")
print(results)
speak(results)
elif 'open youtube' in query:
webbrowser.open("youtube.com")
elif 'open google' in query:
webbrowser.open("google.com")
elif 'open stackoverflow' in query:
webbrowser.open("stackoverflow.com")
elif 'the time' in query:
strTime = datetime.datetime.now().strftime("%H;%M:%S")
speak(f"The time is {strTime}")
elif 'open code' in query:
codePath = "C:\\Users\\Sravya\\AppData\\Local\\Programs\\Microsoft VS
Code\\Code.exe"
os.startfile(codePath)
elif 'bye' in query:
speak("bye,see you soon")
exit()
elif 'exit' in query:
speak("bye,see you soon")
exit()

You might also like