how to make a ai. free ai code .

Anik
0

 making ai is not a easy task. but we made it easy for you. here is a python file just paste and run and enjoy before runing change the path name. 

code :

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
import psutil
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
from os import startfile
from keyboard import write
from time import sleep
import smtplib

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].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,0,5)

    try:
        print("Understanding...")    
        query = r.recognize_google(audio, language='en-us')
        print(f"Your Command :  {query}\n")

    except:  
        return "None"
       
    return query.lower()

def TaskExe():
   
    Speak("Hi . I am jarvis!")
   
   
    def Music():
        Speak("Tell Me The Name oF The Song!")
        musicName = takecommand()

        if 'darkside' in musicName:
            os.startfile('C:\\Users\\black\\Music\\Alan Walker - Darkside (feat. Au_Ra and Tomine Harket)(MP3_320K).mp3')

        elif 'blanko' in musicName:
            os.startfile('E:\\Songs\\blanko.mp3')

        else:
            pywhatkit.playonyt(musicName)

        Speak("Your Song Has Been Started! , Enjoy Sir!")
   
    def Whatsapp():
        Speak("Tell me the name of the person!")
        name = takecommand()

        if 'abrar' 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!")
            min =int(takecommand())
            pywhatkit.sendwhatmsg("+8801923755299",msg,hour,min,20)
            Speak("Your message was sent sir! ")
        elif 'rafit' 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!")
            min =int(takecommand())
            pywhatkit.sendwhatmsg("+8801705846370",msg,hour,min,20)
            Speak("Your message was sent sir! ")

        elif 'n' 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!")
            min =int(takecommand())
            pywhatkit.sendwhatmsg("+8801758506925",msg,hour,min,20)
            Speak("Your message was sent sir! ")    
       
        else:
            Speak("Tell me the phone number!")
            phone = int(takecommand())
            ph = "+880" + phone
            Speak("Tell me the Message!")
            msg = takecommand()
            Speak("Tell me the time sir!")
            Speak("Time in hour!")
            hour = int(takecommand())
            Speak("Time in minutes!")
            min =int(takecommand())
            pywhatkit.sendwhatmsg(ph,msg,hour,min,20)
            Speak("Your message was sent sir! ")    

    def wishme():
        hour = int(datetime.datetime.now().hour)
        if hour>=0 and hour<12:
            Speak("Good morning Sir!")
        elif hour>=12 and hour<18:
            Speak("Good afternoon Sir!")
        else:
            Speak("Good Evening Sir!")
        Speak("How may i help you ?")  

    def OpenApps():
        Speak("Ok Sir , Wait A Second!")
       
        if 'code' in query:
            os.startfile("C:\\Users\\black\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe")

        elif 'photoshop' in query:
            os.startfile("C:\\Program Files (x86)\Adobe\Photoshop 7.0\Photoshop.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 my area"
        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 'science' in name:
            os.startfile('C:\\Users\\black\\Downloads\\Blindsight.pdf')
            book = open('C:\\Users\\black\\Downloads\\Blindsight.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 'english' in lang:
                transl = Translator()
                textHin = transl.translate(text,'en')
                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('C:\\Users\\black\\Downloads\\Blindsight.pdf')
            book = open('C:\\Users\\black\\Downloads\\Blindsight.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 'bengali' in lang:
                transl = Translator()
                textHin = transl.translate(text,'bn')
                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 'photoshop' in query:
            os.system("TASKKILL /F /im Photoshop.exe")

        elif 'code' in query:
            os.system("TASKKILL /F /im code.exe")

        elif 'instagram' in query:
            os.system("TASKKILL /F /im chrome.exe")

        elif 'facebook' in query:
            os.system("TASKKILL /F /im chrome.exe")

        elif 'whatsapp' in query:
            os.system("TASKKILL /F /im chrome.exe")        
           
        Speak("Your Command Has Been Succesfully Completed!")

    def YoutubeAuto():
        Speak("Whats Your Command ?")
        command = takecommand()

        if 'pause' in command:
            keyboard.press('k')
       
        elif 'play' in command:
            keyboard.press('k')    

        elif 'restart' in command:
            keyboard.press('0')

        elif 'mute' in command:
            keyboard.press('m')

        elif 'unmute' in command:
            keyboard.press('m')    

        elif 'skip' in command:
            keyboard.press('l')

        elif 'back' in command:
            keyboard.press('j')

        elif 'full screen' in command:
            keyboard.press('f')

        elif 'film mode' in command:
            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='en')
                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 the tab' in command:
            keyboard.press_and_release('ctrl + w')

        elif 'open a new tab' in command:
            keyboard.press_and_release('ctrl + t')

        elif 'open a new window' in command:
            keyboard.press_and_release('ctrl + n')

        elif 'history' in command:
            keyboard.press_and_release('ctrl +h')

        elif 'show download' in command:
            keyboard.press_and_release('ctrl + j')

        elif 'open chrome menu' in command:
            keyboard.press_and_release('alt + f')

        elif 'show bookmark' in command:
            keyboard.press_and_release('ctrl + shift + b')

        elif 'hide bookmark' in command:
            keyboard.press_and_release('ctrl + shift + b')    

        elif 'open bookmark manager' in command:
            keyboard.press_and_release('ctrl + shift + o')

        elif 'open task manager' in command:
            keyboard.press_and_release('ctrl + esc')

        elif 'set focus' in command:
            keyboard.press_and_release('shift + alt + t')

        elif 'open find bar' in command:
            keyboard.press_and_release('ctrl + f')

        elif 'next finbar result' in command:
            keyboard.press_and_release('ctrl + g')

        elif 'old find bar result' in command:
            keyboard.press_and_release('ctrl + shift + g')

        elif 'browse as guest' in command:
            keyboard.press_and_release('ctrl + shift + m')

        elif 'web contents' in command:
            keyboard.press_and_release('ctrl + f6')

        elif 'focus off' in command:
            keyboard.press_and_release('alt + shift + a')

        elif 'go to adress bar' in command:
            keyboard.press_and_release('ctrl + f5')

        elif 'reload' in command:
            keyboard.press_and_release('ctrl + r')

        elif 'save' in command:
            keyboard.press_and_release('ctrl + s')

        elif 'stop' in command:
            keyboard.press_and_release('esc')

        elif 'move forward' in command:
            keyboard.press_and_release('tab')

        elif 'move back' in command:
            keyboard.press_and_release('shift + tab')

        elif 'open file' in command:
            keyboard.press_and_release('ctrl + o')

        elif 'source code' in command:
            keyboard.press_and_release('ctrl + u')

        elif 'save bookmark' in command:
            keyboard.press_and_release('ctrl + d')

        elif 'full screen on' in command:
            keyboard.press_and_release('f11')

        elif 'full screen off' in query:
            keyboard.press_and_release('f11')

        elif 'zoom in' in query:
            keyboard.press_and_release('ctrl + +')

        elif 'zoom out' in query:
            keyboard.press_and_release('ctrl + -')                                    

        elif 'normal mode' in query:
            keyboard.press_and_release('ctrl + 0')
       
        elif 'go top' in query:
            keyboard.press_and_release('home')

        elif 'go end' in query:
            keyboard.press_and_release('end')

        elif 'scroll' in query:
            keyboard.press_and_release('shift + space bar')

        elif 'home page' in query:
            keyboard.press_and_release('alt + home')



    def screenshot():
        Speak("Ok Boss , What Should I Name That File ?")
        path = takecommand()
        path1name = path + ".png"
        path1 = "C:\\Users\\black\\OneDrive\\Pictures\\Screenshots" + path1name
        kk = pyautogui.screenshot()
        kk.save(path1)
        os.startfile("C:\\Users\\black\\OneDrive\\Pictures\\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 'who made you' in query:
            Speak("Anik make me . He is my Boss!")

        elif 'what can you do' in query:
            Speak("I can do a lot of things for you . ")  
            Speak("Like translation, playing music, sarching, opening apps or website, tell you jokes, I can take screenshot!")
            Speak("And i can tell you location, tempreture, I also can send messages on whatsapp!")
       
        elif 'who can i do' in query:
            Speak("Just give me some task, i will be so happy to do your tasks!")

        elif 'you need a break' in query:
            Speak("Ok Sir , You Can Call Me Anytime !")
            Speak("Just Say Wake Up Jarvis!")
            break
       
        elif 'turn off' in query:
            Speak("Ok Bye Sir , You Can Call Me Anytime !")
            Speak("Just Say Wake Up Jarvis!")
            break
       
        elif 'bye' in query:
            Speak("Ok Bye Sir , You Can Call Me Anytime !")
            Speak("Just Say Wake Up Jarvis!")
            break
       
        elif 'what is your aim in life' in query:
            Speak("To Assist my boss and make him happy!")
            Speak("And make things easy for human!")

        elif 'real name' in query:
            Speak("My real name is Jarvis !")

        elif 'i am tired' in query:
            Speak("Ok Sir . You need some Rest .")
            Speak("Bye sir , You can call me anytime!")
            Speak("Just say wake up jarvis!")    
            break
       
        elif 'good night' in query:
            Speak("Good night Sir, Have a nice dream!")
            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 photoshop' in query:
            OpenApps()

        elif 'open chrome' in query:
            OpenApps()

        elif 'close chrome' in query:
            CloseAPPS()
       
        elif 'close youtube' in query:
            CloseAPPS()    

        elif 'music' in query:
            Music()

        elif 'close photoshop' in query:
            CloseAPPS()

        elif 'close instagram' in query:
            CloseAPPS()

        elif 'close facebook' in query:
            CloseAPPS()

        elif 'close whatsapp' in query:
            CloseAPPS()    

        elif 'pause' in query:
            keyboard.press('k')

        elif 'play' in query:
            keyboard.press('k')    

        elif 'restart' in query:
            keyboard.press('0')

        elif 'mute' in query:
            keyboard.press('m')

        elif 'unmute' 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 automation' in query:
            YoutubeAuto()

        elif 'close the tab' in query:
            keyboard.press_and_release('ctrl + w')

        elif 'open a new tab' in query:
            keyboard.press_and_release('ctrl + t')

        elif 'open a new window' in query:
            keyboard.press_and_release('ctrl + n')

        elif 'history' in query:
            keyboard.press_and_release('ctrl +h')

        elif 'show downloads' in query:
            keyboard.press_and_release('ctrl + j')

        elif 'open chrome menu' in query:
            keyboard.press_and_release('alt + f')

        elif 'show bookmark' in query:
            keyboard.press_and_release('ctrl + shift + b')

        elif 'hide bookmark' in query:
            keyboard.press_and_release('ctrl + shift + b')    

        elif 'open bookmark manager' in query:
            keyboard.press_and_release('ctrl + shift + o')

        elif 'open task manager' in query:
            keyboard.press_and_release('ctrl + esc')

        elif 'set focus' in query:
            keyboard.press_and_release('shift + alt + t')

        elif 'open find bar' in query:
            keyboard.press_and_release('ctrl + f')

        elif 'next finbar result' in query:
            keyboard.press_and_release('ctrl + g')

        elif 'old find bar result' in query:
            keyboard.press_and_release('ctrl + shift + g')

        elif 'browse as guest' in query:
            keyboard.press_and_release('ctrl + shift + m')

        elif 'web contents' in query:
            keyboard.press_and_release('ctrl + f6')

        elif 'focus off' in query:
            keyboard.press_and_release('alt + shift + a')

        elif 'go to adress bar' in query:
            keyboard.press_and_release('ctrl + f5')

        elif 'reload' in query:
            keyboard.press_and_release('ctrl + r')

        elif 'save' in query:
            keyboard.press_and_release('ctrl + s')

        elif 'stop' in query:
            keyboard.press_and_release('esc')

        elif 'move forward' in query:
            keyboard.press_and_release('tab')

        elif 'move back' in query:
            keyboard.press_and_release('shift + tab')

        elif 'open file' in query:
            keyboard.press_and_release('ctrl + o')

        elif 'source code' in query:
            keyboard.press_and_release('ctrl + u')

        elif 'save bookmark' in query:
            keyboard.press_and_release('ctrl + d')

        elif 'full screen on' in query:
            keyboard.press_and_release('f11')

        elif 'full screen off' in query:
            keyboard.press_and_release('f11')

        elif 'zoom in' in query:
            keyboard.press_and_release('ctrl + +')

        elif 'zoom out' in query:
            keyboard.press_and_release('ctrl + -')                                    

        elif 'normal mode' in query:
            keyboard.press_and_release('ctrl + 0')
       
        elif 'go top' in query:
            keyboard.press_and_release('home')

        elif 'go end' in query:
            keyboard.press_and_release('end')

        elif 'scroll' in query:
            keyboard.press_and_release('shift + space bar')

        elif 'home page' in query:
            keyboard.press_and_release('alt + home')
           

        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://goo.gl/maps/LufhYjyn4Eb5gjsm7')

        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('Jarvis Alarm.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 'how to' in query:
            Speak("Getting Data From The 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)
           
        elif 'temperature' in query:
            Temp()

        elif 'read book' in query:
            Reader()
       

        elif 'whatsapp' in query:
              Whatsapp()

        elif ('hi') in query:
            wishme()
       
        elif "bangla" in query:
            TakeHindi()
                       

TaskExe()

Post a Comment

0 Comments
Post a Comment (0)
To Top