From c4c1850df0c2c07875cb07c11a7a3ffa28f5fe51 Mon Sep 17 00:00:00 2001 From: Pratik Wayal Date: Tue, 8 Oct 2024 11:53:49 +0530 Subject: [PATCH 1/3] jarvis code added --- JARVIS/.gitattributes | 2 + JARVIS/Functions/Run.py | 63 +++++++++++++++++ JARVIS/Functions/Take_command.py | 30 +++++++++ JARVIS/Functions/application.py | 28 ++++++++ JARVIS/Functions/greet.py | 10 +++ JARVIS/Functions/screenshot.py | 15 +++++ JARVIS/Functions/talk.py | 11 +++ JARVIS/README.md | 112 +++++++++++++++++++++++++++++++ JARVIS/main.py | 3 + JARVIS/requirements.txt | 9 +++ 10 files changed, 283 insertions(+) create mode 100644 JARVIS/.gitattributes create mode 100644 JARVIS/Functions/Run.py create mode 100644 JARVIS/Functions/Take_command.py create mode 100644 JARVIS/Functions/application.py create mode 100644 JARVIS/Functions/greet.py create mode 100644 JARVIS/Functions/screenshot.py create mode 100644 JARVIS/Functions/talk.py create mode 100644 JARVIS/README.md create mode 100644 JARVIS/main.py create mode 100644 JARVIS/requirements.txt diff --git a/JARVIS/.gitattributes b/JARVIS/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/JARVIS/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/JARVIS/Functions/Run.py b/JARVIS/Functions/Run.py new file mode 100644 index 0000000..819d6d4 --- /dev/null +++ b/JARVIS/Functions/Run.py @@ -0,0 +1,63 @@ +import datetime +import webbrowser +import pywhatkit +import wikipedia +from Functions.greet import greet_user +from Functions.talk import talk +from Functions.Take_command import take_command +from Functions.screenshot import take_screenshot +from Functions.application import open_application +def run_jarvis(): + while True: + command = take_command() + if command is None: + continue + elif 'activate' in command: + talk("initializing jarvis") + greet_user + talk("how are you") + elif 'launch' in command: + open_application(command) + elif 'open youtube' in command: + talk("Opening YouTube") + webbrowser.open("https://www.youtube.com") + + elif 'open google' in command: + talk("Opening Google") + webbrowser.open("https://www.google.com") + + elif 'open facebook' in command: + talk("Opening Facebook") + webbrowser.open("https://www.facebook.com") + + elif 'open linkedin' in command: + talk("Opening LinkedIn") + webbrowser.open("https://www.linkedin.com") + + elif 'search google for' in command: + search_query = command.replace('search google for', '') + talk(f"Searching Google for {search_query}") + pywhatkit.search(search_query) + + elif 'time' in command: + time = datetime.datetime.now().strftime('%I:%M %p') + talk(f"The current time is {time}") + + elif 'tell me about' in command: + topic = command.replace('tell me about', '') + info = wikipedia.summary(topic, 1) + talk(info) + elif 'screenshot' in command: + print("What should be the file name for the screenshot?") + talk("What should be the file name for the screenshot?") + file_name = take_command() # Take voice input for the screenshot name + + if file_name: + take_screenshot(file_name) # Capture and save the screenshot + elif 'exit' in command or 'stop' in command: + talk("closing jarvis...") + talk("take care") + break + + else: + talk("Sorry, I didn't understand. Please try again.") diff --git a/JARVIS/Functions/Take_command.py b/JARVIS/Functions/Take_command.py new file mode 100644 index 0000000..8de7b0b --- /dev/null +++ b/JARVIS/Functions/Take_command.py @@ -0,0 +1,30 @@ +import speech_recognition as sr + +def take_command(): + recognizer = sr.Recognizer() # Initialize recognizer + try: + with sr.Microphone() as source: + print("Listening...") + recognizer.adjust_for_ambient_noise(source, duration=1) # Adjust for ambient noise + voice = recognizer.listen(source, timeout=5, phrase_time_limit=5) # Limit listen time + + try: + command = recognizer.recognize_google(voice) # Convert speech to text + command = command.lower() + print(f"User said: {command}") + return command + + except sr.UnknownValueError: + # Handles when speech is not understood + print("Sorry, I couldn't understand that.") + return None + + except sr.RequestError as e: + # Handles any errors related to Google's API + print(f"API request error: {e}") + return None + + except sr.WaitTimeoutError: + # Handles the case when no speech is detected within the timeout + print("No speech detected. Please try again.") + return None diff --git a/JARVIS/Functions/application.py b/JARVIS/Functions/application.py new file mode 100644 index 0000000..c663084 --- /dev/null +++ b/JARVIS/Functions/application.py @@ -0,0 +1,28 @@ +import os +import subprocess + +def open_application(command): + command = command.lower() # Convert the command to lowercase for easier matching + + if 'calculator' in command: + # For Windows + subprocess.Popen('calc') # Opens Calculator + print("Opening Calculator...") + + elif 'notepad' in command: + # For Windows + subprocess.Popen('notepad') # Opens Notepad + print("Opening Notepad...") + + elif 'word' in command: + # For Windows, adjust this command based on your installation + subprocess.Popen('winword') # Opens Microsoft Word + print("Opening Microsoft Word...") + + elif 'excel' in command: + # For Windows, adjust this command based on your installation + subprocess.Popen('excel') # Opens Microsoft Excel + print("Opening Microsoft Excel...") + + else: + print("Application not recognized. Please try again.") diff --git a/JARVIS/Functions/greet.py b/JARVIS/Functions/greet.py new file mode 100644 index 0000000..a048e62 --- /dev/null +++ b/JARVIS/Functions/greet.py @@ -0,0 +1,10 @@ +import datetime +from Functions.talk import talk +def greet_user(): + hour = int(datetime.datetime.now().hour) + if hour >= 0 and hour < 12: + talk("Good morning!") + elif hour >= 12 and hour < 18: + talk("Good afternoon!") + else: + talk("Good evening!") diff --git a/JARVIS/Functions/screenshot.py b/JARVIS/Functions/screenshot.py new file mode 100644 index 0000000..7928f79 --- /dev/null +++ b/JARVIS/Functions/screenshot.py @@ -0,0 +1,15 @@ +import pyautogui +import os + +# Function to take a screenshot and save it with a custom name +def take_screenshot(file_name): + # Define the path where screenshots will be saved + save_path = os.path.join("E:/JARVIS", f"{file_name}.png") + + # Take the screenshot + screenshot = pyautogui.screenshot() + + # Save the screenshot to the defined path + screenshot.save(save_path) + + print(f"Screenshot saved as {save_path}") diff --git a/JARVIS/Functions/talk.py b/JARVIS/Functions/talk.py new file mode 100644 index 0000000..87f389c --- /dev/null +++ b/JARVIS/Functions/talk.py @@ -0,0 +1,11 @@ +import pyttsx3 +import speech_recognition as sr + +# Initialize the speech recognizer and text-to-speech engine +recognizer = sr.Recognizer() +engine = pyttsx3.init() + +# Function to convert text to speech +def talk(text): + engine.say(text) + engine.runAndWait() \ No newline at end of file diff --git a/JARVIS/README.md b/JARVIS/README.md new file mode 100644 index 0000000..07a49aa --- /dev/null +++ b/JARVIS/README.md @@ -0,0 +1,112 @@ +# πŸš€ JARVIS: AI Chatbot Assistant +**Your Personal Voice Assistant Powered by Python** + +Welcome to **JARVIS**, a Python-based voice assistant that listens to your commands and helps you perform tasks effortlessly! From opening apps to searching the web and even playing music, JARVIS is here to assist youβ€”all with just your voice. πŸŽ™οΈ + +--- + +## 🌟 **Features** +- 🎀 **Voice Command Recognition**: JARVIS listens to your voice and processes commands with ease. +- πŸ—‚οΈ **Open Applications**: Launch apps like Calculator, Notepad, and more via simple voice commands. +- 🌐 **Web Search**: Speak your query and JARVIS will search Google for you! +- 🎢 **Play Music**: Request songs, and JARVIS will search YouTube and play your favorite music. +- πŸ“Έ **Screenshot Capture**: Take screenshots with a custom name and save them to a specified folder. +- πŸ‘‹ **Greeting**: JARVIS greets you warmly at the start of each session. +- πŸ› οΈ **Customizable**: Easily add new functionality to expand JARVIS’s capabilities. + + +## βš™οΈ **Installation** + +### **Prerequisites**: +Make sure you have the following: +- 🐍 **Python 3.x** installed on your machine. +- πŸ“¦ Required Python libraries: +``` +pip install -r requirements.txt +``` + +### **Setup**: +1. Clone this repository to your local machine: + ```bash + git clone https://github.com/pratikwayal01/Python-Voice-Assistant-Suryanshsk.git + cd Python-Voice-Assistant-Suryanshsk + ``` + +2. Install the required Python libraries using `pip`: + ```bash + pip install speechrecognition pyttsx3 pywhatkit pyautogui pillow + ``` + +3. Ensure your microphone is correctly configured to allow voice input. + +--- + +## πŸ“‚ **Project Structure** +``` +jarvis-assistant/ +β”‚ +β”œβ”€β”€ Functions/ # Core functionalities +β”‚ β”œβ”€β”€ Run.py # Core logic for running JARVIS +β”‚ β”œβ”€β”€ Take_command.py # Voice command processing +β”‚ β”œβ”€β”€ OpenApplications.py # Open apps like Calculator, Notepad, etc. +β”‚ β”œβ”€β”€ Screenshot.py # Take screenshots +β”‚ +β”œβ”€β”€ main.py # Entry point for JARVIS +β”œβ”€β”€ README.md # Project documentation +β”œβ”€β”€ .venv/ # Virtual environment (optional) +└── requirements.txt # Dependencies (optional) +``` + +--- + +## πŸ› οΈ **How to Use** + +To run JARVIS, simply execute the `main.py` file: + +```bash +python main.py +``` + +Once JARVIS is running, you can speak commands like: +- **Opening Applications**: + - "Open Calculator" + - "Open Notepad" + +- **Web Search**: + - "Search for Python tutorials on Google" + +- **Play Music**: + - "Play Shape of You on YouTube" + +- **Screenshots**: + - "Take a screenshot" (You'll be prompted for a file name) + +- **Exit**: + - "Exit" to stop the assistant. + +--- + +## πŸ“‹ **Example Commands**: +- πŸ” **Search**: "Search for machine learning tutorials on Google" +- 🎢 **Play Music**: "Play [song name] on YouTube" +- πŸ“ **Open Applications**: "Open Notepad", "Open Calculator" +- πŸ“Έ **Screenshot**: "Take a screenshot" + +--- + +## 🀝 **Contributing** +We welcome contributions! Feel free to open an issue or submit a pull request to improve JARVIS. + +--- + +## πŸ“œ **License** +This project is licensed under the **MIT License**. + +--- + +With JARVIS, your personal AI assistant, you can streamline daily tasks and focus on what really matters. πŸš€βœ¨ + +## Contributing 🀝 + +contributor:**Pratik Wayal**. Feel free to connect: [GitHub](https://github.com/pratikwayal01). All contributions are welcome! 🌟 +``` \ No newline at end of file diff --git a/JARVIS/main.py b/JARVIS/main.py new file mode 100644 index 0000000..8129fd7 --- /dev/null +++ b/JARVIS/main.py @@ -0,0 +1,3 @@ +from Functions.Run import run_jarvis +run_jarvis() + diff --git a/JARVIS/requirements.txt b/JARVIS/requirements.txt new file mode 100644 index 0000000..1e22b26 --- /dev/null +++ b/JARVIS/requirements.txt @@ -0,0 +1,9 @@ +pillow +pyttsx3 +pywhatkit +pyaudio +pipwin +pyautogui +SpeechRecognition +webbrowser +wikipedia \ No newline at end of file From 4d84a1d172b99dca27b0d4e11201782c6d3a3fed Mon Sep 17 00:00:00 2001 From: Pratik wayal <97722446+pratikwayal01@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:58:03 +0530 Subject: [PATCH 2/3] Update README.md minor fix --- JARVIS/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/JARVIS/README.md b/JARVIS/README.md index 07a49aa..fd39361 100644 --- a/JARVIS/README.md +++ b/JARVIS/README.md @@ -43,7 +43,7 @@ pip install -r requirements.txt ## πŸ“‚ **Project Structure** ``` -jarvis-assistant/ +JARVIS/ β”‚ β”œβ”€β”€ Functions/ # Core functionalities β”‚ β”œβ”€β”€ Run.py # Core logic for running JARVIS @@ -109,4 +109,4 @@ With JARVIS, your personal AI assistant, you can streamline daily tasks and focu ## Contributing 🀝 contributor:**Pratik Wayal**. Feel free to connect: [GitHub](https://github.com/pratikwayal01). All contributions are welcome! 🌟 -``` \ No newline at end of file +``` From d02a86becdc0badee99d673718a544c6891a536a Mon Sep 17 00:00:00 2001 From: Pratik wayal <97722446+pratikwayal01@users.noreply.github.com> Date: Tue, 8 Oct 2024 11:58:54 +0530 Subject: [PATCH 3/3] Update README.md nano fix --- JARVIS/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/JARVIS/README.md b/JARVIS/README.md index fd39361..aba0eda 100644 --- a/JARVIS/README.md +++ b/JARVIS/README.md @@ -109,4 +109,4 @@ With JARVIS, your personal AI assistant, you can streamline daily tasks and focu ## Contributing 🀝 contributor:**Pratik Wayal**. Feel free to connect: [GitHub](https://github.com/pratikwayal01). All contributions are welcome! 🌟 -``` +