Jarvis is a Python-based voice-controlled personal assistant that uses Google's Speech Recognition API and the pyttsx3 text-to-speech engine to respond to user commands. It works on a wake-word system — when the user says "Jarvis", the assistant activates and listens for the next instruction. It can open websites, tell the current time, respond to basic conversational queries, and gracefully shut down when instructed. The system includes ambient noise handling, error handling, and continuous real-time microphone listening.
import speech_recognition as sr
import pyttsx3
import webbrowser
import time
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
def processCommand(command):
command = command.lower()
if 'open google' in command:
speak("Opening Google.")
webbrowser.open("http://www.google.com")
elif 'open youtube' in command:
speak("Opening YouTube.")
webbrowser.open("https://www.youtube.com")
elif 'open facebook' in command:
speak("Opening Facebook.")
webbrowser.open("https://facebook.com")
elif 'time' in command:
current_time = time.strftime("%I:%M %p")
speak(f"The current time is {current_time}.")
elif 'how are you' in command:
speak("I'm doing great, thank you for asking!")
elif 'stop' in command:
speak("Goodbye! I am shutting down.")
exit()
else:
speak("Sorry, I didn't understand that.")
while True:
try:
with sr.Microphone() as source:
print("Listening for wake word...")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source, timeout=5, phrase_time_limit=3)
word = recognizer.recognize_google(audio)
print("Recognized:", word)
if word.lower() == "jarvis":
speak("Yes, how can I assist you?")
with sr.Microphone() as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source, timeout=5, phrase_time_limit=5)
command = recognizer.recognize_google(audio)
processCommand(command)
except Exception as e:
print("Error:", e)