Ad Code

Ticker

6/recent/ticker-posts

Iron Man Jarvis AI part-2 Desktop Voice Assistant | Python Tutorial | Jarvis Basic Complete

 

[youtube https://www.youtube.com/watch?v=TxArVD_VP-c]


Jarvis Code (Python):-

import pyttsx3
import datetime
import time
import speech_recognition as sr
import wikipedia
import webbrowser
import pywhatkit as kit
import pyautogui
import requests
import os
import random
import smtplib
import sys
# You need to download this modules

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

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

def WishMe():
    hour = int(datetime.datetime.now().hour)
    strTime = datetime.datetime.now().strftime("%H:%M:%S")
    if hour>=0 and hour<12:
        speak(f"Good Morning Sir! Its {strTime}")
        print(f'Good morning sir! Its {strTime}')

    elif hour>=2 and hour<18:
        speak(f"Good Afternoon sir! Its {strTime}")
        print(f"Good afternoon sir! Its {strTime}")

    else:
        speak(f"Good evening sir! Its {strTime}")
        print(f"Good evening sir! Its {strTime}")

    print("I am Jarvis sir! Please tell me how may i help you.")
    speak("I am Jarvis sir! Please tell me how may i help you.")

def takeCommand():
    #It will take the voice input of the user from mic
    r = sr.Recognizer()
    with sr.Microphone() as source:
        print('Listening...')
        r.pause_threshold = 1
        r.adjust_for_ambient_noise(source)
        audio = r.listen(source)

    try:
        print('Recognizing...')
        query = r.recognize_google(audiolauguage='en-in')
        print(f'user said: {query}/n')

    except Exception as e:
        print(e)
        print('Say that again please...')

        return "None"

    return query

def sendEmail(tocontent):
    server = smtplib.SMTP('smtp.gmail.com'587)
    server.starttls()
    server.ehlo()
    server.login('yourgmail@gmail.com''your_password')
    server.sendmail('youremail@gmail.com'tocontent)
    server.close()



def TaskExecution():
    if __name__ == "__main__":
        WishMe()
    while True:
       # if 1:
       query = takeCommand().lower()

       #Logic for executing tasks based on query
       if 'hello' in query:
           speak('Hi sir! how are you?')

       elif 'fine' in query or 'i am fine' in query:
           speak('Good to hear from you sir. How can i help you?')
     
       elif 'wikipedia' in query:
           speak('Searching Wkikpedia')
           query = query.replace("Wikipedia""")
           results = wikipedia.summary(querysentances=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 song on youtube' in query or 'song youtube' in query:
           speak('What should i play on youtube?')
           answer = takeCommand()
           kit.playonyt(answer)
           speak(f'Playing {answer}')

       elif 'you are great' in query or 'you are awesome' in query:
           print('Thats a playsure for me! Thank you sir!')
           speak('Thats a playsure for me! Thank you sir!')

       elif 'devoloped' in query or 'discovered' in query or 'found' in query:
           print('I was developed by Abhinav Mishra sir at 2021 at Orisha, India')
           speak('I was developed by Abhinav Mishra sir at 2021 at Orisha, India')

       elif 'who are you' in query:
           speak('I am Jarvis sir. Your prosnal assistent.')

       elif 'hello' in query or 'hi' in query:
           speak('Hello sir! how can i help you?')

       elif 'volume up' in query:
           pyautogui.press("volumeup")

       elif 'volume down' in query:
           pyautogui.press("volumedown")

       elif 'volume mute' in query or 'mute' in query:
           pyautogui.press("volumemute")

       elif 'command prompt' in query:
           os.system('start cmd')
           print('Openning Command Prompt')
           speak('Openning Command Prompt')

       elif 'play music' in query:
           speak('Sure, Playing music... please wait')
           music_dir = 'Your Music Folder location here..'
           songs = os.listdir(music_dir)
           rd = random.choice(songs)
           os.startfile(os.path.join(music_dirrd))

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

       elif 'Do for me' in query:
           speak('I can play music, send Email, take screenshor etc. Just ask. I do the same work as Alexa and Siri, But at free of cost')
 
        #To send email
       elif 'send mail' in query or 'send email' in query or 'send gmail' in query:
           try:
               speak("What should I say?")
               content = takeCommand()
               to = 'yourgmail@gmail.com'
               sendEmail(tocontent)
               speak('Email has been sent!')
           except Exception as e:
               print(e)
               speak("Sorry sir. I am not able to send this email")

       elif 'goodbye' in query or 'bye' in query:
            speak('Thanks for using me sir, have a good day! Jarvis is signing out of duty.')
            sys.exit()
            #Than the jarvis will terminate/stop!




(adsbygoogle = window.adsbygoogle || []).push({});

Post a Comment

7 Comments

  1. followed all videos, but the Jarvis was only a python file and being that I am less than a beginner, i couldn't run it as an application. i did some research and converted it to an .exe file. however, i still can't run it as a program or application how do i go about this?I know its a lot of work, and i'd have to get familiar with coding and learn a lot before doing all that, but i don't actually want to code or be a programmer i just want me a custom voice assistant for my disabled little girl to have a friend to talk to when friends are few.

    ReplyDelete
  2. Hello sir! I can understand your problem. Sir you can just install python programming language compiler from this site:-https://www.python.org/downloads/You can also see tutorials on YouTube like how to install Python. When it's done you can just search on the Windows/Mac Search box "Python IDE". Then you can just create a file named "Main.py" or "Jarvis.py". Then copy the code given above, and just run it! That's it sir. But sir this not that easy to create without any programming knowledge, You need to have some coding skills to make it work.there is one more thing left to install, that is PyAudio!!If you fines this much. you can say me here only. I will then tell you then next steps! Thank you very much from visiting my website!!

    ReplyDelete
  3. I did all that, copied the coding and pasted on visual studio code. created Jarvis.py and when i open it, it doesn't run as a program at all. it opens up a command prompt window for 5 secs and closes. i don't have extensive knowledge in coding, but i know enough to be able to read it (at least some of the languages)

    ReplyDelete
  4. I attempted to create the Jarvis using visual studio code. copied your code and pasted it and also downloaded all modules including PyAudio. when i try to run the code the code it attempts to execute but comes back with HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0 and repeats the same thing over again. I converted the Jarvis.py file to .exe and same thing happens. I keep trying to see how I went wrong by looking over your videos and i can't seem to figure it out.

    ReplyDelete
  5. Please Watch This Video and Download & Install PyAudio Correctly..https://youtu.be/w0r39vJUnuUHave You Installed Python??

    ReplyDelete
  6. Have You Installed This Modulespyttsx3 wikipediaospyautoguietc?

    ReplyDelete
  7. Sir to make Your work easy!! I have converted the Jarvis into a Proffesnal .exe file! here is the Google Drive link:-https://drive.google.com/file/d/1tj9eIA2e3GILpOYjdlk1Qj_Fzx3E9Oqy/view?usp=sharing You can Download this App and It will Work on any Laptop or Desktop!Hope it will help you! The link is secure..Any Problem then please feel free to ask me!Thank you!

    ReplyDelete

Ad Code