Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

jarvis project for ur device ai support

+8 votes
asked Oct 13, 2024 by Arnav Grover (260 points)

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

1 Answer

0 votes
answered Oct 13, 2024 by Arnav Grover (260 points)

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()

   

commented Jan 16 by JASON EBAGUA (180 points)
it doesnt work
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...