Jarvis
Jarvis
import os
import random
import time
import webbrowser
from googletrans import Translator
from gtts import gTTS
import cap
import cv2
import googleapiclient.discovery
import psutil
import pyttsx3
import pywhatkit
import speech_recognition as sr
import wikipedia
from requests import get
import subprocess
import pygame
import sys
import time
import geocoder
import psutil
import pyautogui
import winsound
import pyjokes
import requests
from bs4 import BeautifulSoup
from win10toast import ToastNotifier
smartphone_details = {
"iphone 12": {
"brand": "Apple",
"price": "$699",
"display_size": "6.1 inches",
"camera": "Dual 12 MP",
"storage": "64GB/128GB/256GB",
"availability": "Available on Apple Store"
},
def get_smartphone_details(smartphone_name):
if smartphone_name in smartphone_details:
return smartphone_details[smartphone_name]
else:
return "Smartphone details not found for {}".format(smartphone_name)
API_KEY = 'Y83abe34985994044801c95a92b9b5449'
NEWS_API_ENDPOINT = 'https://newsapi.org/v2/everything?q=tesla&from=2023-07-
18&sortBy=publishedAt&apiKey=83abe34985994044801c95a92b9b5449'
PARAMS = {'apiKey': API_KEY , 'country': 'us'}
if response.status_code == 200:
news_data = response.json()
articles = news_data.get('articles' , [])
if articles:
news_text = "Top news headlines:\n"
for index , article in enumerate(articles , start=1):
title = article.get('title' , 'N/A')
source = article.get('source' , {}).get('name' , 'N/A')
news_text += f"{index}. {title} - {source}\n"
speak(news_text)
else:
speak("No news articles available.")
else:
speak("Error fetching news. Please check your API key or try again later.")
YOUTUBE_API_KEY = "AIzaSyBwkb4V6znFaYCX80x3YSPOMI7BPWwxBS4"
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice' , voices[0].id)
def get_location():
location = geocoder.ip('me')
return location.address
cap.release()
cv2.destroyAllWindows()
listening_enabled = True
def is_video_playing(video_process_name):
for process in psutil.process_iter(['pid', 'name']):
if video_process_name.lower() in process.info['name'].lower():
return True
return False
def take_command():
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Listening...")
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)
try:
print("Recognizing...")
query = recognizer.recognize_google(audio).lower()
print("You said:", query)
except Exception as e:
speak("")
return "none"
return query
speak(" i am jarvis aadi sir's persnal assistant, how can i help you sir ")
def play_youtube_video(query):
try:
speak(f"Searching for {query} on YouTube.")
youtube_url = f"https://www.youtube.com/results?search_query={query}"
webbrowser.open(youtube_url)
except Exception as e:
print(f"Error playing video: {e}")
speak("Sorry, I couldn't play the video.")
if __name__ == "__main__":
wish()
while True:
query = take_command()
global listening_enabled
location = get_location()
if "translate" in query:
parts = query.replace("translate" , "").strip().split(" in ")
if len(parts) == 2:
text , target_lang = parts
translated_text = translate_text(text , target_lang)
print(f"Translated: {translated_text}")
speak(f"The translation is: {translated_text}")
else:
speak("Invalid translation format. Please use 'translate <text> to
<target_language>'")
if "yes" in query:
take_photo()
break
elif "no" in query:
speak("Okay, closing the camera.")
break
else:
speak("Sorry, I didn't catch that. Please say 'yes' or 'no'.")