Created
May 25, 2021 05:50
-
-
Save KaushikShresth07/37feb9cc87373aef1dba4a600fc9e6a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pyttsx3 | |
import speech_recognition as sr | |
import webbrowser | |
from pywikihow import search_wikihow | |
from bs4 import BeautifulSoup | |
import pywhatkit | |
import wikipedia | |
from googletrans import Translator | |
import os | |
import pyautogui | |
from tkinter import Label | |
from tkinter import Entry | |
from tkinter import Button | |
import requests | |
from tkinter import Tk | |
from gtts import gTTS | |
from tkinter import StringVar | |
import PyPDF2 | |
from pytube import YouTube | |
import datetime | |
from playsound import playsound | |
import keyboard | |
import pyjokes | |
engine = pyttsx3.init('sapi5') | |
voices = engine.getProperty('voices') | |
engine.setProperty('voice', voices[7].id) | |
engine.setProperty('rate',170) | |
def Speak(Audio): | |
print(" ") | |
print(f": {Audio}") | |
engine.say(Audio) | |
print(" ") | |
engine.runAndWait() | |
def takecommand(): | |
r = sr.Recognizer() | |
with sr.Microphone() as source: | |
print(" ") | |
print("Listening...") | |
r.pause_threshold = 1 | |
audio = r.listen(source) | |
try: | |
print("Recognizing...") | |
query = r.recognize_google(audio, language='en-in') | |
print(f"Your Command : {query}\n") | |
except: | |
return "None" | |
return query.lower() | |
def TaskExe(): | |
def Music(): | |
Speak("Tell Me The NamE oF The Song!") | |
musicName = takecommand() | |
if 'akeli' in musicName: | |
os.startfile('E:\\Songs\\akeli.mp3') | |
elif 'blanko' in musicName: | |
os.startfile('E:\\Songs\\blanko.mp3') | |
else: | |
pywhatkit.playonyt(musicName) | |
Speak("Your Song Has Been Started! , Enjoy Sir!") | |
def OpenApps(): | |
Speak("Ok Sir , Wait A Second!") | |
if 'code' in query: | |
os.startfile("E:\\Applications\\Microsoft VS Code\\Microsoft VS Code\\Code.exe") | |
elif 'telegram' in query: | |
os.startfile("E:\\Applications\\Telegram Desktop\\Telegram Desktop\\Telegram.exe") | |
elif 'chrome' in query: | |
os.startfile("C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe") | |
elif 'facebook' in query: | |
webbrowser.open('https://www.facebook.com/') | |
elif 'instagram' in query: | |
webbrowser.open('https://www.instagram.com/') | |
elif 'maps' in query: | |
webbrowser.open('https://www.google.com/maps/@28.7091225,77.2749958,15z') | |
elif 'youtube' in query: | |
webbrowser.open('https://www.youtube.com') | |
Speak("Your Command Has Been Completed Sir!") | |
def Temp(): | |
search = "temperature in delhi" | |
url = f"https://www.google.com/search?q={search}" | |
r = requests.get(url) | |
data = BeautifulSoup(r.text,"html.parser") | |
temperature = data.find("div",class_ = "BNeawe").text | |
Speak(f"The Temperature Outside Is {temperature} celcius") | |
Speak("Do I Have To Tell You Another Place Temperature ?") | |
next = takecommand() | |
if 'yes' in next: | |
Speak("Tell Me The Name Of tHE Place ") | |
name = takecommand() | |
search = f"temperature in {name}" | |
url = f"https://www.google.com/search?q={search}" | |
r = requests.get(url) | |
data = BeautifulSoup(r.text,"html.parser") | |
temperature = data.find("div",class_ = "BNeawe").text | |
Speak(f"The Temperature in {name} is {temperature} celcius") | |
else: | |
Speak("no problem sir") | |
def Reader(): | |
Speak("Tell Me The Name Of The Book!") | |
name = takecommand() | |
if 'india' in name: | |
os.startfile('E:\\Kaushik Shresth\\Books\\Social Science\\History\\ch 1.pdf') | |
book = open('E:\\Kaushik Shresth\\Books\\Social Science\\History\\ch 1.pdf','rb') | |
pdfreader = PyPDF2.PdfFileReader(book) | |
pages = pdfreader.getNumPages() | |
Speak(f"Number Of Pages In This Books Are {pages}") | |
Speak("From Which Page I Have To Start Reading ?") | |
numPage = int(input("Enter The Page Number :")) | |
page = pdfreader.getPage(numPage) | |
text = page.extractText() | |
Speak("In Which Language , I Have To Read ?") | |
lang = takecommand() | |
if 'hindi' in lang: | |
transl = Translator() | |
textHin = transl.translate(text,'hi') | |
textm = textHin.text | |
speech = gTTS(text = textm ) | |
try: | |
speech.save('book.mp3') | |
playsound('book.mp3') | |
except: | |
playsound('book.mp3') | |
else: | |
Speak(text) | |
elif 'europe' in name: | |
os.startfile('E:\\Kaushik Shresth\\Books\\Social Science\\History\\ch 3.pdf') | |
book = open('E:\\Kaushik Shresth\\Books\\Social Science\\History\\ch 3.pdf','rb') | |
pdfreader = PyPDF2.PdfFileReader(book) | |
pages = pdfreader.getNumPages() | |
Speak(f"Number Of Pages In This Books Are {pages}") | |
Speak("From Which Page I Have To Start Reading ?") | |
numPage = int(input()) | |
page = pdfreader.getPage(numPage) | |
text = page.extractText() | |
Speak("In Which Language , I Have To Read ?") | |
lang = takecommand() | |
if 'hindi' in lang: | |
transl = Translator() | |
textHin = transl.translate(text,'hi') | |
textm = textHin.text | |
speech = gTTS(text = textm ) | |
try: | |
speech.save('book.mp3') | |
playsound('book.mp3') | |
except: | |
playsound('book.mp3') | |
else: | |
Speak(text) | |
def CloseAPPS(): | |
Speak("Ok Sir , Wait A second!") | |
if 'youtube' in query: | |
os.system("TASKKILL /F /im Chrome.exe") | |
elif 'chrome' in query: | |
os.system("TASKKILL /f /im Chrome.exe") | |
elif 'telegram' in query: | |
os.system("TASKKILL /F /im Telegram.exe") | |
elif 'code' in query: | |
os.system("TASKKILL /F /im code.exe") | |
elif 'instagram' in query: | |
os.system("TASKKILL /F /im chrome.exe") | |
Speak("Your Command Has Been Succesfully Completed!") | |
def YoutubeAuto(): | |
Speak("Whats Your Command ?") | |
comm = takecommand() | |
if 'pause' in comm: | |
keyboard.press('space bar') | |
elif 'restart' in comm: | |
keyboard.press('0') | |
elif 'mute' in comm: | |
keyboard.press('m') | |
elif 'skip' in comm: | |
keyboard.press('l') | |
elif 'back' in comm: | |
keyboard.press('j') | |
elif 'full screen' in comm: | |
keyboard.press('f') | |
elif 'film mode' in comm: | |
keyboard.press('t') | |
Speak("Done Sir") | |
def TakeHindi(): | |
command = sr.Recognizer() | |
with sr.Microphone() as source: | |
print("Listening......") | |
command.pause_threshold = 1 | |
audio = command.listen(source) | |
try: | |
print("Recognizing.....") | |
query = command.recognize_google(audio,language='hi') | |
print(f"You Said : {query}") | |
except: | |
return "none" | |
return query.lower() | |
def Tran(): | |
Speak("Tell Me The Line!") | |
line = TakeHindi() | |
traslate = Translator() | |
result = traslate.translate(line) | |
Text = result.text | |
Speak(Text) | |
def ChromeAuto(): | |
Speak("Chrome Automation started!") | |
command = takecommand() | |
if 'close this tab' in command: | |
keyboard.press_and_release('ctrl + w') | |
elif 'open new tab' in command: | |
keyboard.press_and_release('ctrl + t') | |
elif 'open new window' in command: | |
keyboard.press_and_release('ctrl + n') | |
elif 'history' in command: | |
keyboard.press_and_release('ctrl +h') | |
def screenshot(): | |
Speak("Ok Boss , What Should I Name That File ?") | |
path = takecommand() | |
path1name = path + ".png" | |
path1 = "E:\\Kaushik Shresth\\Screenshots\\"+ path1name | |
kk = pyautogui.screenshot() | |
kk.save(path1) | |
os.startfile("E:\\Kaushik Shresth\\Screenshots") | |
Speak("Here Is Your ScreenShot") | |
while True: | |
query = takecommand() | |
if 'hello' in query: | |
Speak("Hello Sir , I Am Jarvis .") | |
Speak("Your Personal AI Assistant!") | |
Speak("How May I Help You?") | |
elif 'how are you' in query: | |
Speak("I Am Fine Sir!") | |
Speak("Whats About YOU?") | |
elif 'you need a break' in query: | |
Speak("Ok Sir , You Can Call Me Anytime !") | |
Speak("Just Say Wake Up Jarvis!") | |
break | |
elif 'youtube search' in query: | |
Speak("OK sIR , This Is What I found For Your Search!") | |
query = query.replace("jarvis","") | |
query = query.replace("youtube search","") | |
web = 'https://www.youtube.com/results?search_query=' + query | |
webbrowser.open(web) | |
Speak("Done Sir!") | |
elif 'website' in query: | |
Speak("Ok Sir , Launching.....") | |
query = query.replace("jarvis","") | |
query = query.replace("website","") | |
query = query.replace(" ","") | |
web1 = query.replace("open","") | |
web2 = 'https://www.' + web1 + '.com' | |
webbrowser.open(web2) | |
Speak("Launched!") | |
elif 'launch' in query: | |
Speak("Tell Me The Name Of The Website!") | |
name = takecommand() | |
web = 'https://www.' + name + '.com' | |
webbrowser.open(web) | |
Speak("Done Sir!") | |
elif 'wikipedia' in query: | |
Speak("Searching Wikipedia.....") | |
query = query.replace("jarvis","") | |
query = query.replace("wikipedia","") | |
wiki = wikipedia.summary(query,2) | |
Speak(f"According To Wikipedia : {wiki}") | |
elif 'screenshot' in query: | |
screenshot() | |
elif 'open facebook' in query: | |
OpenApps() | |
elif 'open instagram' in query: | |
OpenApps() | |
elif 'open maps' in query: | |
OpenApps() | |
elif 'open code' in query: | |
OpenApps() | |
elif 'open youtube' in query: | |
OpenApps() | |
elif 'open telegram' in query: | |
OpenApps() | |
elif 'open chrome' in query: | |
OpenApps() | |
elif 'close chrome' in query: | |
CloseAPPS() | |
elif 'music' in query: | |
Music() | |
elif 'close telegram' in query: | |
CloseAPPS() | |
elif 'close instagram' in query: | |
CloseAPPS() | |
elif 'close facebook' in query: | |
CloseAPPS() | |
elif 'pause' in query: | |
keyboard.press('space bar') | |
elif 'restart' in query: | |
keyboard.press('0') | |
elif 'mute' in query: | |
keyboard.press('m') | |
elif 'skip' in query: | |
keyboard.press('l') | |
elif 'back' in query: | |
keyboard.press('j') | |
elif 'full screen' in query: | |
keyboard.press('f') | |
elif 'film mode' in query: | |
keyboard.press('t') | |
elif 'youtube tool' in query: | |
YoutubeAuto() | |
elif 'close the tab' in query: | |
keyboard.press_and_release('ctrl + w') | |
elif 'open new tab' in query: | |
keyboard.press_and_release('ctrl + t') | |
elif 'open new window' in query: | |
keyboard.press_and_release('ctrl + n') | |
elif 'history' in query: | |
keyboard.press_and_release('ctrl +h') | |
elif 'chrome automation' in query: | |
ChromeAuto() | |
elif 'joke' in query: | |
get = pyjokes.get_joke() | |
Speak(get) | |
elif 'repeat my word' in query: | |
Speak("Speak Sir!") | |
jj = takecommand() | |
Speak(f"You Said : {jj}") | |
elif 'my location' in query: | |
Speak("Ok Sir , Wait A Second!") | |
webbrowser.open('https://www.google.com/maps/@28.7091225,77.2749958,15z') | |
elif 'alarm' in query: | |
Speak("Enter The Time !") | |
time = input(": Enter The Time :") | |
while True: | |
Time_Ac = datetime.datetime.now() | |
now = Time_Ac.strftime("%H:%M:%S") | |
if now == time: | |
Speak("Time To Wake Up Sir!") | |
playsound('iron.mp3') | |
Speak("Alarm Closed!") | |
elif now>time: | |
break | |
elif 'video downloader' in query: | |
root = Tk() | |
root.geometry('500x300') | |
root.resizable(0,0) | |
root.title("Youtube Video Downloader") | |
Speak("Enter Video Url Here !") | |
Label(root,text = "Youtube Video Downloader",font = 'arial 15 bold').pack() | |
link = StringVar() | |
Label(root,text = "Paste Yt Video URL Here",font = 'arial 15 bold').place(x=160,y=60) | |
Entry(root,width = 70,textvariable = link).place(x=32,y=90) | |
def VideoDownloader(): | |
url = YouTube(str(link.get())) | |
video = url.streams.first() | |
video.download() | |
Label(root,text = "Downloaded",font = 'arial 15').place(x= 180,y=210) | |
Button(root,text = "Download",font = 'arial 15 bold',bg = 'pale violet red',padx = 2 , command = VideoDownloader).place(x=180,y=150) | |
root.mainloop() | |
Speak("Video Downloaded") | |
elif 'translator' in query: | |
Tran() | |
elif 'remember that' in query: | |
remeberMsg = query.replace("remember that","") | |
remeberMsg = remeberMsg.replace("jarvis","") | |
Speak("You Tell Me To Remind You That :"+remeberMsg) | |
remeber = open('data.txt','w') | |
remeber.write(remeberMsg) | |
remeber.close() | |
elif 'what do you remember' in query: | |
remeber = open('data.txt','r') | |
Speak("You Tell Me That" + remeber.read()) | |
elif 'google search' in query: | |
import wikipedia as googleScrap | |
query = query.replace("jarvis","") | |
query = query.replace("google search","") | |
query = query.replace("google","") | |
Speak("This Is What I Found On The Web!") | |
pywhatkit.search(query) | |
try: | |
result = googleScrap.summary(query,2) | |
Speak(result) | |
except: | |
Speak("No Speakable Data Available!") | |
elif 'temperature' in query: | |
Temp() | |
elif 'read book' in query: | |
Reader() | |
TaskExe() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment