import speech_recognition as sr
import pyttsx3
import requests
import webbrowser
import datetime
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
commands = {
"jarvis open youtube": lambda: webbrowser.open("https://www.youtube.com/"),
"jarvis open google": lambda: webbrowser.open("https://www.google.com"),
"jarvis open gpt": lambda: webbrowser.open("https://chatgpt.com/"),
"jarvis what's the time right now": lambda: speak("The current time is " + datetime.datetime.now().strftime("%H:%M:%S")),
"jarvis sleep": lambda: exit(),
"open note": lambda command: take_note(command)
}
def take_note(command):
speak("it start from now")
with open("note.txt", "a") as note:
note.write(command.split("open note ", 1)[1] + "\n")
def main():
speak("""HELLO ARNAV SIR,
WELCOME TO YOUR PERSONAL AREA,
WHAT ARE WE GOING TO DO TODAY!,
HOW ARE YOU?!?""")
while True:
try:
with sr.Microphone() as source:
print("keep on it started")
print("Initializing Jarvis;) ......")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source, timeout=10)
print("Recognizing the text :] ........ ")
command = recognizer.recognize_google_cloud(audio)
print("You said:", command)
command = command.upper()
if command in commands:
commands[command]()
else:
speak("Sorry, I didn't understand that.")
except sr.UnknownValueError:
speak("Sorry, I couldn't understand that.")
except sr.RequestError:
speak("Error occurred timeout crash")
if __name__ == "__main__":
main()
hope this code supports u in ur work and ur daily life style you'll get to see more projects soon