Tuesday, July 14, 2020

Project J.A.R.V.I.S | AI (artificial Intelligence) Desktop Assitant by using Python

             Project J.A.R.V.I.S  





Copy from Here:::
                         
import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib

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


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


def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning!")

    elif hour>=12 and hour<18:
        speak("Good Afternoon!")   

    else:
        speak("Good Evening!")  

    speak("I am Jarvis Sir. Please tell me how may I help you")       

def takeCommand():
    #It takes microphone input from the user and returns string output

    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 1
        audio = r.listen(source)

    try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in')
        print(f"User said: {query}\n")

    except Exception as e:
        # print(e)    
        print("Say that again please...")  
        return "None"
    return query


if __name__ == "__main__":
    wishMe()
    while True:
  
        query = takeCommand().lower()

        # Logic for executing tasks based on query
        if 'wikipedia' in query:
            speak('Searching Wikipedia...')
            query = query.replace("wikipedia", "")
            results = wikipedia.summary(query, sentences=2)
            speak("According to Wikipedia")
            print(results)
            speak(results)

        elif 'open youtube' in query:
            webbrowser.open("youtube.com")

        elif 'open google' in query:
            webbrowser.open("google.com")

        elif 'open stackoverflow' in query:
            webbrowser.open("stackoverflow.com")   


        elif 'play music' in query:
            music_dir = 'G:\\kishan all.co\\d\\songs'
            songs = os.listdir(music_dir)
            print(songs)    
            os.startfile(os.path.join(music_dir, songs[0]))

        elif 'the time' in query:
            strTime = datetime.datetime.now().strftime("%H:%M:%S")    
            speak(f"Sir, the time is {strTime}")

        elif 'open code' in query:
            codePath = "C:\\Users\\kishancjx\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
            os.startfile(codePath)
            #you should enter your path here

        elif 'email to ' in query:
            try:
                speak("What should I say?")
                content = takeCommand()
                to = "YourfriendEmail@gmail.com"    
                sendEmail(to, content)
                speak("Email has been sent!")
            except Exception as e:
                print(e)
                speak("Sorry my friend. I am not able to send this email")


    

ThankU...

34 comments:

  1. What we write that only it said it not recognize automatically

    ReplyDelete
    Replies
    1. To install pyaudio type in the terminal as pip install pipwin and click enjoying enter and after that type in the terminal pipwin install pyaudio

      Delete
  2. Thank you so much for your great explanation for each line of code

    ReplyDelete
  3. i want spiderman's edith smart glass ai assistant

    ReplyDelete
  4. bro i cannot use pyaudio it is saying error what should i do

    ReplyDelete
    Replies
    1. try to install pipwin
      next pipwin install pyaudio

      Delete
    2. Hay bro I like your you tube channel vedios and you created me now I am a learner of life I learned Manny think about computer science I am inspired about you you said was that write bro .see bro in future in will be a gratest person like black you and Elon musk and I am santhosh

      Delete
  5. bro pyaudio error it shows pyaudio is not installed when running the program i can get the commands like good morning sir how can i help you after that it is not executing and shows the above error pls reply anna

    ReplyDelete
    Replies
    1. Type in the terminal pip install pipwin and click enter and now type in the terminal pipwin install pyaudio. Hope It helps you

      Delete
  6. its keep on listening..... and not recognising pls help me out...

    ReplyDelete
  7. Bro in program it shows no voice
    How to get voice bro

    ReplyDelete
    Replies
    1. You should install pyaudio but this might not help installing pyaudio to get voice you should type in the terminal as pip install pyttsx3

      Delete
  8. Bro yanaku from _ctypes import COMError

    ReplyDelete
  9. bro how to install pytts3 in visual studio 2019 bro ... plz help me out

    ReplyDelete
    Replies
    1. Pip install pyttsx3
      Or open unofficial binaries of python and download pyttsx3 from there these are the two remedies for your problem

      Delete
    2. First you have to save the file so press ctrl+s and save it as jarvis.py and after that type in the terminal as pip install pyttsx3.Hope it helps

      Delete
  10. how to reduce the time of jarvis to recognize because in mine it takes too much

    ReplyDelete
  11. R.pause threshold = 1.Put it to one so it takes only a little time to recognize

    ReplyDelete
  12. bro pls say how to install pyaudio

    ReplyDelete
  13. I want to communicate with you i tried many ways please give me as instagram id

    ReplyDelete
  14. Hay bro I like your you tube channel vedios and you created me now I am a learner of life I learned Manny think about computer science I am inspired about you you said was that write bro .see bro in future in will be a gratest person like black you and Elon musk and I am iron Man

    ReplyDelete
  15. Bro enaku No module error pyttsx3
    Veruthu solution solluga

    ReplyDelete
  16. bro what was the front end, backend and software details , pls share bro

    ReplyDelete