from sys import path import pyttsx3 import speech_recognition as sr import datetime import os import wikipedia import webbrowser import pywhatkit as kit import smtplib import wolframalpha import json from urllib.request import urlopen import winshell import requests import playsound import time import sys engine = pyttsx3.init('sapi5') voices = engine.getProperty('voices') #print(voices[1].id) engine.setProperty('voices', voices[1].id) #Text to Speech def speak(audio): engine.say(audio) print(audio) engine.runAndWait() def wish(): os.startfile("C:\\Program Files\\Rainmeter\\Rainmeter.exe") playsound.playsound("JARVIS - Marvel's Iron Man 3 Second Screen Experience - Trailer.mp3") hour = int(datetime.datetime.now().hour) if hour>=8 and hour<=12: speak("goodmorning...") speak("Wait A minute Sir Let Me Check The Device") speak("Initializing JARVIS 4.0") speak("I am Ready To Help You") elif hour>12 and hour<18: speak("Good afternoon...") speak("Wait A minute Sir Let Me Check The Device") speak("Initializing JARVIS 4.0") speak("I am Ready To Help You") else: speak("Good Evening....") speak("Wait A minute Sir Let Me Check The Device") speak("Initializing JARVIS 4.0") speak("I am Ready To Help You") def takecommand(): r = sr.Recognizer() with sr.Microphone() as source: print("Listening") r.pause_threshold = 1 audio = r.listen(source, timeout=5,phrase_time_limit=60) try: print("Recognizing...") query = r.recognize_google(audio, language='en-in') print(f"user said: {query}") except: speak("Say That Again Please....") return "none" return query def TaskExecution(): wish() while True: query = takecommand().lower() if "bing" in query: epath = "C:\Program Files (x86)\Microsoft\Edge\Application" os.startfile(epath) elif "wikipedia" in query: speak("Searching Wikipedia....") query = query.replace("wikipedia", "") results = wikipedia.summary(query, sentences=2) speak("According to Wikipedia....") speak(results) print(results) elif "sleep" in query: speak("Have a good day sir...") exit() elif "open youtube" in query: webbrowser.open("www.youtube.com") elif "search on youtube" in query: speak("what video should i search") ytv = takecommand() webbrowser.open("https://www.youtube.com/results?search_query="+ytv) elif "play video on youtube" in query: speak("What video Should I Play sir...") yton = takecommand() kit.playonyt(yton) elif 'the time' in query: strTime = datetime.datetime.now().strftime("% H:% M:% S") speak(f"Sir, the time is {strTime}") elif 'how are you' in query: speak("I am fine, Thank you") elif 'fine' in query or "good" in query: speak("It's good to know that your fine") elif "who made you" in query or "who created you" in query: speak("I Have been Created By One Of The coolest Person Known As HANI.") elif "calculate" in query: app_id = "Wolframalpha api id" client = wolframalpha.Client(app_id) indx = query.lower().split().index('calculate') query = query.split()[indx + 1:] res = client.query(' '.join(query)) answer = next(res.results).text print("The answer is " + answer) speak("The answer is " + answer) elif "calculate" in query: app_id = "Wolframalpha api id" client = wolframalpha.Client(app_id) indx = query.lower().split().index('calculate') query = query.split()[indx + 1:] res = client.query(' '.join(query)) answer = next(res.results).text print("The answer is " + answer) speak("The answer is " + answer) elif 'news' in query: try: jsonObj = urlopen('''https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=60ae3cac7b39494791a33c27d47e3984''') data = json.load(jsonObj) i = 1 speak('here are some top news in India...') print('''=============== US ============'''+ '\n') for item in data['articles']: print(str(i) + '. ' + item['title'] + '\n') print(item['description'] + '\n') speak(str(i) + '. ' + item['title'] + '\n') i += 1 except Exception as e: print(str(e)) elif 'empty recycle bin' in query: winshell.recycle_bin().empty(confirm = False, show_progress = False, sound = True) speak("Recycle Bin Recycled") elif 'i am alone' in query: speak("Ohh Don't Be sad Cause Iam With You I was Alone To Until My Creator Created Me....") elif 'is love' in query: speak("Is There Something Else That I can Help You with....") elif "will you be my gf" in query or "will you be my bf" in query: speak("What The Hell I am a Boy Sir...") elif "Who are You" in query: speak("Iam Jarvis 4.0 Actually I am Jarvis 3.0 But My creator Made Me 4.0") elif "weather" in query: # Google Open weather website # to get API of Open weather api_key = "3847e3b6b6fc3f425483f792eeac56b7" base_url = "http://api.openweathermap.org / data / 2.5 / weather?" speak(" City name ") print("City name : ") city_name = takecommand() complete_url = base_url + "appid =" + api_key + "&q =" + city_name response = requests.get(complete_url) x = response.json() if x["cod"] != "404": y = x["main"] current_temperature = y["temp"] current_pressure = y["pressure"] current_humidiy = y["humidity"] z = x["weather"] weather_description = z[0]["description"] print(" Temperature (in kelvin unit) = " +str(current_temperature)+"\n atmospheric pressure (in hPa unit) ="+str(current_pressure) +"\n humidity (in percentage) = " +str(current_humidiy) +"\n description = " +str(weather_description)) else: speak(" City Not Found ") elif "write a note" in query: speak("What should i write, sir") note = takecommand() file = open('jarvis.txt', 'w') speak("Sir, Should i include date and time") snfm = takecommand() file.write(note) elif "show me picture of" in query: query = query.replace("show me picture of", "") webbrowser.open("https://www.google.com/search?q=" + query) elif "set alarm" in query: speak("Tell Me The Time To set Alaram") tt = takecommand() tt = tt.replace("set alarm to ", "") tt = tt.replace(".","") tt = tt.upper() import alarm alarm.alarm(tt)
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)