Skip to content

Instantly share code, notes, and snippets.

@KaushikShresth07
Created May 25, 2021 05:29
Show Gist options
  • Save KaushikShresth07/94017b4ec8aff0d5cf59bf0a5c535a41 to your computer and use it in GitHub Desktop.
Save KaushikShresth07/94017b4ec8aff0d5cf59bf0a5c535a41 to your computer and use it in GitHub Desktop.
import pyttsx3
import speech_recognition as sr
import webbrowser
import pywhatkit
import wikipedia
import os
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 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 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')
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 '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
TaskExe()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment