Jarvis an ai that do your work like open chrome YouTube and etc.
To install the necessary packages, use the following commands:
```
pip install SpeechRecognition
pip install pyttsx3
```
Here is the script:
```python
import speech_recognition as sr
import pyttsx3
import webbrowser
# Initialize the recognizer and the text-to-speech engine
recognizer = sr.Recognizer()
engine = pyttsx3.init()
def speak(text):
engine.say(text)
engine.runAndWait()
def listen():
with sr.Microphone() as source:
print("Listening...")
audio = recognizer.listen(source)
try:
command = recognizer.recognize_google(audio).lower()
print(f"You said: {command}")
return command
except sr.UnknownValueError:
speak("Sorry, I did not understand that.")
return ""
except sr.RequestError:
speak("Sorry, my speech service is down.")
return ""
def main():
speak("Hello, I am Jarvis. How can I assist you today?")
while True:
command = listen()
if "open chrome" in command:
speak("Opening Chrome.")
webbrowser.open("http://www.google.com")
elif "youtube" in command:
speak("Opening YouTube.")
webbrowser.open("http://www.youtube.com")
elif "exit" in command or "quit" in command:
speak("Goodbye!")
break
if __name__ == "__main__":
main()
```
This script listens for your voice commands and responds accordingly. You can say “Jarvis, open Chrome” to open Google Chrome or “Jarvis, open YouTube” to open YouTube. To exit the program, you can say “exit” or “quit.”
Feel free to customize and expand this script to add more commands and functionalities! If you have any questions or need further assistance, just let me know.
Comments
Post a Comment