Monday, September 7, 2020

Artificial Intelligence Using Python | Source Code | Full Details | Libraries to Install | Extra Info

Artificial Intelligence Using Python

Python is an Awesome Language Which can be Used to do Many Types of Work like Creating a Simple Calculator to Creating an Advance Artificial Intelligence

In this Post, I builded an Amazing Python Artificial Intelligence Program Which Can be Used for Playing Music, Playing Movies, Starting Programs and Games, Openign Website URL and Many Other Works.

How to Use :-

▶Make Sure you have Python Installed in your PC :)

First of All, Install the Packages Listed Below. After that, Make a File Anywhere and name it as "jarvis.py". After that,Copy the Code From Below and Open the jarvis.py Using Notepad, Now Paste the code there. After that Run it Using Python. You can use the App.

Important :- Make Sure to Edit the Codes Which starts from # or you will face error.

For Better Understanding You Should Watch the Full Video [Explained In Hindi Language] By Clicking the Video Button Given Below

Python Libararies To Install Before Copying Codes

Simply Open Your Terminal [You can Use 'Command Prompt' Or 'Windows Powershell' also. And Run These Commands there to Install These Packages.

pip install wheel

pip install speechrecognition

pip install wikipedia

pip install webbrowser

pip install pyaudio

pip install os

pip install pyttsx3


Souce Code Here :-


import pyttsx3
import datetime
import speech_recognition as sr
import wikipedia
import webbrowser
import os
import random


engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)


def speak(audio):
    engine.say(audio)
    engine.runAndWait()

def search():
    r = sr.Recognizer()
    with sr.Microphone() as pipe:
        print("Say Sentence or Word to Search On Google Sir...")
        speak("Say Sentence or Word to Search On Google Sir...")
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(pipe, duration=5)
        audio = r.listen(pipe)
    try:
        print("Searching Your Sentence Sir.....")
        speak("Searching Your Sentence Sir.....")
        pipo = r.recognize_google(audio, language='en-in')
        print("You had Said Sir : ", pipo)
        webbrowser.open("https://google.com/?#q=" + pipo)

    except Exception as e:
        print("Say that Again Please Sir....")
        speak("Say that Again Please Sir....")
        return "None"
    return pipo
    

def wishme():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning Kunal Sir!")
    elif hour>=12 and hour<18:
        speak("Good Afternoon Kunal Sir!")
    else:
        speak("Good Evening Kunal Sir")
    speak("Kunal Sir, Syphen Is Online, Please Tell Me What you Want to do")

def takeCommand():
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening Your Command Sir ....")
        speak("Listening Your Command Sir ....")
        r.pause_threshold = 1
        r.energy_threshold = 1
        r.adjust_for_ambient_noise(source, duration=2)
        audio = r.listen(source)

    try:
        speak("Recognizing Your Command Sir ....")
        print("Recognizing Your Command Sir ....")
        query = r.recognize_google(audio, language='en-in')
        print("You had Said Sir : ", query)

    except Exception as e:
        speak("Say that Again Please Sir ...")
        print("Say that Again Please Sir ...")
        return "None"
    return query


if __name__ == '__main__':
  wishme()
  while True:
    query = takeCommand().lower()

    if 'wikipedia' in query:
       speak("Searching For Wikipedia Sir .....")
       query = query.replace("wikipedia", "")
       results = wikipedia.summary(query, sentences=20)
       speak("According to Wikipedia")
       print(results)
       speak(results)
#WebSites Starting [You Can Add More]
    elif 'google' in query:
          print("Opening Google For You Sir ....")
          speak("Opening Google For You Sir ....")
          webbrowser.open("https://google.com/")
    elif 'search google' in query:
          print("Preparing Search Command, Wait a Second Sir...")
          speak("Preparing Search Command, Wait a Second Sir...")
          search()
    elif 'open youtube' in query:
          print("Opening Youtube For You Sir ....")
          speak("Opening Youtube For You Sir ....")
          webbrowser.open("https://youtube.com/")
#Application Sarting [You Must Add Command to It to Make It Operable]   
    elif '#The command you want to give to Syphen to open a Program' in query:
          print("#What you want to print When Syphen open the program.....")
          speak("#What you want to print When Syphen open the program.....")
          path = "#Program Full Path With Double Backslashes[//]"
          os.startfile(path)
     elif '#The command you want to give to Syphen to open a Program' in query:
          print("#What you want to print When Syphen open the program.....")
          speak("#What you want to listen When Syphen open the program.....")
          pop = "#Program Full Path With Double Backslashes[//]"
          os.startfile(pop)
          

You Can Add More Codes To Make It More Amazing

You can Edit these Codes to Make it Your Personal AI

MacStock Official

Author & Editor

Python Programmer and a Simple Web Developer. Owns a Youtube Channel Named MacStock Tech & Gaming and This Website also Refers to him

0 Comments:

Post a Comment