Skip to content

Commit

Permalink
Merge pull request #79 from pratikwayal01/main
Browse files Browse the repository at this point in the history
Basic Voice Command Features
  • Loading branch information
suryanshsk authored Oct 9, 2024
2 parents 59c7e19 + d02a86b commit 0ed5ece
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 0 deletions.
2 changes: 2 additions & 0 deletions JARVIS/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
63 changes: 63 additions & 0 deletions JARVIS/Functions/Run.py
Original file line number Diff line number Diff line change
@@ -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.")
30 changes: 30 additions & 0 deletions JARVIS/Functions/Take_command.py
Original file line number Diff line number Diff line change
@@ -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
28 changes: 28 additions & 0 deletions JARVIS/Functions/application.py
Original file line number Diff line number Diff line change
@@ -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.")
10 changes: 10 additions & 0 deletions JARVIS/Functions/greet.py
Original file line number Diff line number Diff line change
@@ -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!")
15 changes: 15 additions & 0 deletions JARVIS/Functions/screenshot.py
Original file line number Diff line number Diff line change
@@ -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}")
11 changes: 11 additions & 0 deletions JARVIS/Functions/talk.py
Original file line number Diff line number Diff line change
@@ -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()
112 changes: 112 additions & 0 deletions JARVIS/README.md
Original file line number Diff line number Diff line change
@@ -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/
├── 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! 🌟

3 changes: 3 additions & 0 deletions JARVIS/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from Functions.Run import run_jarvis
run_jarvis()

9 changes: 9 additions & 0 deletions JARVIS/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
pillow
pyttsx3
pywhatkit
pyaudio
pipwin
pyautogui
SpeechRecognition
webbrowser
wikipedia

0 comments on commit 0ed5ece

Please sign in to comment.