AI ASSISTANCE (BASIC)

 


import pyttsx3
import speech_recognition as sr
import webbrowser
import pywhatkit
import os
import wikipedia
import pyautogui
import keyboard
import pyjokes
from PyDictionary import PyDictionary as Diction
import datetime
from playsound import playsound
from tkinter import Label
from tkinter import Entry
from tkinter import Button
from tkinter import Tk
from tkinter import StringVar
from pytube import YouTube
from googletrans import Translator
import requests
from bs4 import BeautifulSoup
import PyPDF2
from gtts import gTTS
from pywikihow import search_wikihow


Assistance = pyttsx3.init("sapi5")
voices = Assistance.getProperty("voices")
print(voices)
Assistance.setProperty("voices", voices[0].id)
Assistance.setProperty('rate', 170) # Speed of Jarvis Speaking, defalt is 200

def Speak(audio):
print(" ")
Assistance.say(audio)
print(f": {audio}")
print(" ")
Assistance.runAndWait()

def Dict():
Speak("Dictionary Activated")
Speak("tell me the Word!")
word = TakeCommand()

if 'meaning' in word:
word = word.replace("what is the","")
word = word.replace("meaning","")
word = word.replace("of","")
word = word.replace("jarvis","")
result = Diction.meaning(word)
Speak(f"The Meaning of {word} is : {result}")
elif 'synonym' in word:
word = word.replace("what is the", "")
word = word.replace("synonym", "")
word = word.replace("of", "")
word = word.replace("jarvis", "")
result = Diction.synonym(word)
Speak(f"The Synonym of {word} is : {result}")
elif 'antonym' in word:
word = word.replace("what is the", "")
word = word.replace("antonym", "")
word = word.replace("of", "")
word = word.replace("jarvis", "")
result = Diction.antonym(word)
Speak(f"The Antonym of {word} is : {result}")
else:
word = word.replace("what is", "")
word = word.replace("jarvis", "")
result = Diction.meaning(word)
Speak(f"The Meaning of {word} is : {result}")
Speak("Done Sir")

def TakeCommand():
command = sr.Recognizer()
with sr.Microphone() as source:
print("Listenig......")
command.pause_threshold = 1
audio = command.listen(source)

try:
print("Recognizing....")
query = command.recognize_google(audio, language='en-in')
print(f"You Said : {query}")
except:
return "none"

return query.lower()

def TaskExe():

def PlayMusic():
Speak("Tell the name of the music")
musicname = TakeCommand()

if 'akeli' in musicname:
os.startfile('C:\\Users\\Welcome\\Music\\akeli')
else:
pywhatkit.playonyt(musicname)

Speak("Your song has been start")

def Whatsup():
Speak("Tell me the name of the Person")
name = TakeCommand()
if 'rituparna' in name:
Speak("Tell me the message")
msg = TakeCommand()
Speak("Tell me the time sir")
Speak("Time in Hour")
hour = int(TakeCommand())
Speak("Time in Minutes")
mint = int(TakeCommand())
pywhatkit.sendwhatmsg("+917003795364",msg,hour,mint,20)
Speak()
Speak("ok sir, Sending watsup message")
else:
Speak("Tell me the Number")
number = (TakeCommand())
ph = '+91' + number
Speak("Tell me the message")
msg = TakeCommand()
Speak("Tell me the time sir")
Speak("Time in Hour")
hour = int(TakeCommand())
Speak("Time in Minutes")
mint = int(TakeCommand())
pywhatkit.sendwhatmsg(ph,msg,hour,mint,20)
Speak("ok sir, Sending watsup message")

def screenshort():
Speak("Ok Boss: What Should I name That File")
path = TakeCommand()
pathname = path + ".png"
path1 = "C:\\Users\\Welcome\\Pictures\\Saved Pictures" + pathname
kk = pyautogui.screenshot()
kk.save(path1)
os.startfile("C:\\Users\\Welcome\\Pictures\\Saved Pictures")
Speak("Here Is Your Screenshot")

def OpenApps(command):
Speak("Ok sir. wait a second")
# apps = TakeCommand()
if 'code' in command:
os.startfile("C:\\Program Files\\JetBrains\\PyCharm Community Edition 2020.2.4\\bin\\pycharm64.exe")
elif 'vlc' in command:
os.startfile("C:\\Program Files (x86)\\VideoLAN\\VLC\\vlc.exe")
elif 'chrome' in command:
os.startfile("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Google Chrome")
elif 'edge' in command:
os.startfile("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe")
elif 'excel' in command:
os.startfile("C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Microsoft Office\\Microsoft Excel 2010")
elif 'facebook' in command:
webbrowser.open('https://www.facebook.com/')
elif 'youtube' in command:
webbrowser.open('https://www.youtube.com/')
elif 'maps' in command:
webbrowser.open("https://www.google.co.in//maps//@22.6399085,88.2749033,9.75z?hl=en")

Speak("Your command has successfully completed")

def CloseApps(command):
Speak("ok Sir. Wait a Second")
# apps = TakeCommand()
if 'chrome' in command:
os.system("TASKKILL /F /im chrome.exe")
elif 'edge' in command:
os.system("TASKKILL /F /im msedge.exe")
elif 'vlc' in command:
os.system("TASKKILL /F /im vlc.exe")
elif 'code' in command:
os.system("TASKKILL /F /im pycharm64.exe")
elif 'excel' in command:
os.system("TASKKILL /F /im excel.exe")

Speak("Your command has successfully completed")

def YoutubeAuto(command):

if 'pause' in command:
keyboard.press('space bar')
elif 'restart' in command:
keyboard.press("0")
elif 'mute' in command:
keyboard.press("m")
elif 'skip' in command:
keyboard.press("l")
elif 'back' in command:
keyboard.press("j")
elif 'fullscrean' in command:
keyboard.press('f')
elif 'film mode' in command:
keyboard.press('t')

Speak("Done Sir")

def ChromeAuto(command):
# Speak("Chrome Automation started")
if 'close this tab' in command:
keyboard.press_and_release('ctrl + w')
if 'close the 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')

Speak("Done")

def TakeHindi():
command = sr.Recognizer()
with sr.Microphone() as source:
print("Listenig......")
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()
print(line)
traslate = Translator()
result = traslate.translate(line)
Text = result.text
Speak("The Translating For This line is" + Text)

def Temp(place):
if 'temperature' in place:
place = place.replace('temperature',"")
place = place.replace('of',"")
place = place.replace('in',"")
place = place.replace('jarvis',"")
place = place.replace('tell me',"")
place = place.replace('tell me the',"")
search = f'temperature in {place}'
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 is {temperature}")

def Reader():
Speak("Tell Me the Name of the Book!")
name = TakeCommand()
if 'habit' in name:
os.startfile('F:\\PROGRAMING\\PROJECT\\AI ASSISTANTE\\the-power-of-habit.pdf')
book = open('F:\\PROGRAMING\\PROJECT\\AI ASSISTANTE\\the-power-of-habit.pdf', 'rb')
pdfreader = PyPDF2.PdfFileReader(book)
pages = pdfreader.getNumPages()
Speak(f"Number of pages In this book are {pages}")
Speak("From which page I have To Start Reading")
try:
numPage = int(TakeCommand())
except:
numPage = int(input("Enter the page number"))
page = pdfreader.getPage(numPage)
text = page.extractText()
text1 = text.encode('utf-8')
Speak("In Which language, I have to read")
lang = TakeCommand()

if 'hindi' in lang:
transl = Translator()
textHin = transl.translate(text1,dest='hi')
textm = textHin.text1
speech = gTTS(text = textm)
try:
speech.save('book.mp3')
playsound('book.mp3')
except:
playsound('book.mp3')
else:
print(text1)
Speak(text1)

def SpeedTest():
import speedtest
Speak("Checking speed....")
speed = speedtest.Speedtest()
downloading = speed.download()
correctDown = int(downloading/800000)
uploading = speed.upload()
correctUpload = int(uploading/800000)

if 'downloading' in query:
Speak(f"The Downloading Speed is {correctDown}")
elif 'uploading' in query:
Speak(f"The Uploading Speed is {correctUpload}")
else:
Speak(f"The Downloading Speed is {correctDown}")
Speak(f"The Uploading Speed is {correctUpload}")


while True:
query = TakeCommand()

if 'hello' in query:
Speak("Hello Sir, I am Jarvis.")
Speak("Your Personal AI Assistance")
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 ")
break

elif 'kya hal hai' in query:
Speak("Main Badiya hoon App ka hal ke Hai")

elif "bye" in query:
Speak("Ok Sir, Bye")

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 "google search" in query:
# Speak("Ok Sir, This is what I found for your search")
# query = query.replace("jarvis", "")
# query = query.replace("google search", "")
# pywhatkit.search(query)
# Speak("Done Sir")

elif "website" in query:
query = query.replace("jarvis","")
query = query.replace("website","")
query = query.replace(" ","")
web1 = query.replace("open", "")
web2 = 'https://www.'+web1+'.com'
webbrowser.open(web2)
Speak("Your website Launch Sir")

elif "open website" in query:
Speak("tell the name of the website")
name = TakeCommand()
name = name.replace(" ", "")
web = 'https://www.'+name+'.com'
webbrowser.open(web)
Speak("Done Sie")

elif "music" in query:
PlayMusic()

elif "wikipedia" in query:
Speak("Searching Wikipedia..")
query = query.replace("jarvis","")
query = query.replace("wikipedia","")
wiki = wikipedia.summary(query,2)
Speak(f"Acording To wikipedia: {wiki}")

elif 'whatsapp message' in query:
Whatsup()

elif 'screenshot' in query:
screenshort()
# Open A Application or site such as facebook
elif 'open code' in query:
OpenApps(query)

elif 'open vlc' in query:
OpenApps(query)

elif 'open chrome' in query:
OpenApps(query)

elif 'open edge' in query:
OpenApps(query)

elif 'open excel' in query:
OpenApps(query)

elif 'open facebook' in query:
OpenApps(query)

elif 'open youtube' in query:
OpenApps(query)

elif 'open maps' in query:
OpenApps(query)
# Close A App in windows
elif 'close chrome' in query:
CloseApps(query)

elif 'close edge' in query:
CloseApps(query)

elif 'close vlc' in query:
CloseApps(query)

elif 'close code' in query:
CloseApps(query)

elif 'close excel' in query:
CloseApps(query)
# Youtube Automation Start
elif 'pause' in query: # not working
YoutubeAuto(query)

elif 'restart' in query:
YoutubeAuto(query)

elif 'mute' in query: # not working
YoutubeAuto(query)

elif 'skip' in query: #not working
YoutubeAuto(query)

elif 'back' in query: #not working
YoutubeAuto(query)

elif 'full screen' in query: # not working
YoutubeAuto(query)

elif 'film mode' in query: # not working
YoutubeAuto(query)
# Chorom Automation Start
elif 'close the tab' in query:
ChromeAuto(query)

elif 'open new tab' in query:
ChromeAuto(query)

elif 'open new window' in query:
ChromeAuto(query)

elif 'open history' in query:
ChromeAuto(query)
# Tell me a jokes
elif 'jokes' in query:
get = pyjokes.get_joke()
Speak(get)
# Repeat my word
elif 'repeat my word' in query:
Speak("Speak Sir")
yousaid = TakeCommand()
Speak(f"You Said: {yousaid}")
# Open Location
elif 'my location' in query:
Speak("Ok Sir, wait a second!")
if 'home location' in query:
webbrowser.open('https://www.google.co.in//maps//place//Ramkrishna+Furniture//@22.581392,88.3989417,17z//data=!3m1!4b1!4m9!1m2!10m1!1e2!3m5!1s0x3a02767100000001:0xb102b2a28eac2a12!8m2!3d22.5814306!4d88.401113!16s%2Fg%2F1tg9r2yd?hl=en-GB')
elif 'work location' in query:
webbrowser.open('https://www.google.co.in//maps//place//73,89,94+%26+99,+Kamrangu,+Andul,+Howrah,+West+Bengal+711302//@22.5879549,88.2165163,17z//data=!3m1!4b1!4m9!1m2!10m1!1e2!3m5!1s0x3a027f6d17669fc9:0x6f771112268cfd8f!8m2!3d22.58795!4d88.218705!16s%2Fg%2F11csfglk08?hl=en-GB')
else:
webbrowser.open('https://www.google.co.in//maps//place//Howrah,+West+Bengal//@22.557191,87.8957438,10z//data=!3m1!4b1!4m5!3m4!1s0x39f88249be00ca5f:0x3f5496c42f4bd6e8!8m2!3d22.5957689!4d88.2636394?hl=en-GB')
# Open Dictionary
elif 'dictionary' in query:
Dict()

elif 'meaning of' in query:
Dict()

elif 'synonym of' in query:
Dict()

elif 'antonym of' in query:
Dict()
# alarm (need to modify)
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('alarm.mp3')
Speak("Alarm Closed")
elif now > time:
break
# YouTube Video Download(Showing Error)

elif "video download" 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 Link 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() # path of save
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()
#translator not working
elif 'translator' in query:
Tran()
# remember
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())
# Google Search and Speak
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 of your search")
pywhatkit.search(query)

try:
result = googleScrap.summary(query,2)
Speak(result)
except:
Speak("No Speakable data Available")
# Temperature
elif 'temperature' in query:
Temp(query)
# Read Book Not Working
elif 'read book' in query:
Reader()
# Internet Speed
elif 'downloading speed' in query:
SpeedTest()
elif 'uploading speed' in query:
SpeedTest()
elif 'internet speed' in query:
SpeedTest()
# Tell me anything to jarvis 'how to'
elif 'how to' in query:
Speak("Getting data from internet")
op = query.replace("jarvis","")
max_result = 1
how_to_func = search_wikihow(op,max_result)
assert len(how_to_func) == 1
how_to_func[0].print()
Speak(how_to_func[0].summary)


Speak("Hello Sir. I am your Jarvis")
TaskExe()

Comments

Popular posts from this blog

FACTORY DOCUMENTATION

Library System