A powerful Python-based virtual assistant inspired by Iron Man's JARVIS
JARVIS (Just A Rather Very Intelligent System) is a Python-based voice-controlled AI assistant inspired by the AI system from the Iron Man movies. This project aims to create a personal assistant that can perform various tasks through voice commands, including:
Make sure you have Python 3.6+ installed on your system.
git clone https://github.com/Adnan-The-Coder/jarvis-build-v1
The script will attempt to install required packages automatically, but you can also install them manually:
pip install -r requirements.txt
For full functionality, you'll need to obtain the following API keys:
python main.py
Uses Google's Speech Recognition API to convert speech to text for processing commands.
Integrates with Wolfram Alpha and Wikipedia to answer questions and provide information.
Perform system operations like shutdown, restart, lock screen, and control system settings.
Open websites, search Google, and fetch weather information and news headlines.
Launch applications like Chrome, PowerPoint, and Blender with voice commands.
Retrieve detailed information about CPU, memory, network, and other system components.
The script begins with a comprehensive try-except block to import all necessary libraries. If imports fail, it attempts to install the required packages:
try:
import os
import subprocess
import wolframalpha
import pyttsx3
# ... more imports
except:
import os
try:
os.system('pip install -r requirements.txt')
except:
pass
# ... retry imports
The script initializes the text-to-speech engine:
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)
owner = "ADNAN"
my_current_location = "Hyderabad"
Several key functions power the assistant:
Converts text to speech using the pyttsx3 engine.
Plays audio files in the background using pygame.
Greets the user based on the time of day.
Listens for voice input and converts it to text using speech recognition.
Sends queries to Wolfram Alpha API and returns the results.
The main execution flow includes:
The script uses a series of conditional statements to process different commands:
if 'wikipedia' in query:
# Wikipedia search logic
elif 'open youtube' in query:
# YouTube opening logic
elif 'the time' in query:
# Time telling logic
# ... many more command handlers
Converts text to speech using the pyttsx3 engine.
def speak(audio):
engine.say(audio)
engine.runAndWait()
Parameters:
audio
(str): The text to be spokenPlays audio files in the background using pygame.
def play_audio_background(file_path: str, volume: float = 0.1):
def _play():
pygame.init()
pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=4096)
try:
pygame.mixer.music.load(file_path)
pygame.mixer.music.set_volume(volume)
pygame.mixer.music.play()
except pygame.error as e:
print(f"Error loading or playing sound: {e}")
threading.Thread(target=_play, daemon=True).start()
Parameters:
file_path
(str): Path to the audio filevolume
(float, optional): Volume level from 0.0 to 1.0. Default is 0.1Listens for voice input and converts it to text using speech recognition.
def takeCommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
r.pause_threshold = 1
audio = r.listen(source)
try:
print("Recognizing...")
query = r.recognize_google(audio, language ='en-in')
print(f"User said: {query}\n")
except Exception as e:
print(e)
print("Unable to Recognize your voice.")
return "None"
return query
Returns:
str
: The recognized text from speech, or "None" if recognition failsSends queries to Wolfram Alpha API and returns the results.
def wolfram(query):
api_key = "4Y594Q-5TAGRTVW86"
requester = wolframalpha.Client(api_key)
requested = requester.query(query)
try:
answer = next(requested.results).text
return answer
except:
speak("no data found")
Parameters:
query
(str): The query to send to Wolfram AlphaReturns:
str
: The answer from Wolfram Alpha, or None if no data is found"Hello"
Greets you and asks how it can help.
"What's your name?"
Responds with its name (JARVIS).
"What time is it?"
Tells you the current time.
"What's today's date?"
Tells you the current date.
"Open YouTube"
Opens YouTube in your default browser.
"Search for Python tutorials"
Searches Google for Python tutorials.
"Wikipedia artificial intelligence"
Searches Wikipedia for information about artificial intelligence.
"What's the weather?"
Provides current weather information.
"System information"
Provides detailed information about your system.
"CPU information"
Provides information about your CPU.
"Launch Chrome"
Opens Google Chrome browser.
"Lock window"
Locks your computer.
"Calculate 25 plus 17"
Performs the calculation and returns the result (42).
"What is the capital of France?"
Uses Wolfram Alpha to answer knowledge questions.
"Tell me a joke"
Tells you a random joke.
"Temperature in New York"
Provides the current temperature in New York.
JARVIS is a free and open-source project dedicated to advancing AI assistance. Your donations help us improve features, maintain servers, and continue development.
Support the project with a one-time contribution. Every donation helps us maintain and improve JARVIS.
Help improve JARVIS by contributing to the codebase. Join our community of developers.
Start ContributingSpecial thanks to our generous contributors who help make JARVIS possible!
Have questions, suggestions, or want to contribute to the project? Reach out through any of these channels:
The JARVIS project is always looking for contributors and testers. Whether you're a Python expert or just getting started, there are many ways to get involved: