Skip to content
Home » JARVIS In Python #2 | Ironman’s JARVIS Using Python

JARVIS In Python #2 | Ironman’s JARVIS Using Python

JARVIS Thumbnail 2

Hey Python Programmers, In this We will Be Just Adding Advanced Features to our Previous Jarvis Program, This will add the Following Functions to JARVIS:

  • Opening of Apps
  • Jarvis Sleep & Wake Function
  • Basic & Silly Questions & Answer like Google Assistant
  • Adding Temperature & Weather API

Read Also:

JARVIS In Python | Ironman’s JARVIS Using Python

So Let’s Get Started with Our Blog, And If you Have Not Read the Previous Program Then you can Read This Jarvis Program.

1. Adding Function to Execute Opening Of Apps

This Function will Open Apps Like Notepad, Chrome, Spotify, Play Songs, Vs Code, And More When User Says Jarvis Open This or that.

elif 'open vs code' in query:
   VsCodePath = "C:\\Users\\Tanmay Sinha\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
   speak("Opening Visual Studio Code")
   os.startfile(VsCodePath)

  elif 'open spotify' in query:
   Spotify = "spotify.exe"
   speak("Opening Spotify Music")
   os.startfile(Spotify)
   
  elif 'open mister programmer website' in query:
    speak('Opening mister programmer website')
    webbrowser.open("mrprogrammer.in")

  elif 'open github' in query:
    speak('Opening github')
    webbrowser.open("github.com")

  elif 'play music' in query:
   music_directory = "C:\\Music for Jarvis Program"
   speak("Playing Music")
   print("Playing Music")
   songs = os.listdir(music_directory)
   print(songs)
   os.startfile(os.path.join(music_directory, songs[0]))

2. Jarvis Sleep & Wake Function

Jarvis Sleep & Wake Function Allows User to Put Jarvis Either to Sleep By Saying ‘Jarvis You Need a Break’ or Wake Up Jarvis By Saying ‘Wake Up Jarvis’ Using the HotBar Detection

Step 1: Create a New File Called HotBar.py in the Same Folder Where Jarvis is Present

Step 2: Create a New Function Called TaskExe in the Jarvis.py File

TaskExe Function:

def TaskExe():
  speak('Hello Sir, I am Jarvis How can i help you')
# Call the Function
TaskExe()

Step 3: Import the Required Modules

import os
import pyttsx3
import datetime
import speech_recognition as sr

Step 4: Copy the Following Code:

import os
import pyttsx3
import datetime
import speech_recognition as sr

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 wish():
    hour  = int(datetime.datetime.now().hour)
    if hour >=0 and hour<12:
        speak("Good Morning Sir!, i am jarvis, how may i help you?")

    elif hour >=12 and hour<18:
        speak("Good Afternoon Sir!, i am jarvis, how may i help you?")

    else:
        speak("Good Evening Sir!, i am jarvis, how may i help you?")


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

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

    except Exception as e:
    #    print(e)
       print("Say that Again")
       return "None"
    return query

while True:

    wake_up = takeCommand()

    if 'wake up' in wake_up:
        os.startfile('C:\\Users\\Tanmay Sinha\\Desktop\\Voice Assitant PTTSX3\\assitant.py')
    else:
        print('Something Went Wrong...')

3. Basic & Silly Questions & Answer like Google Assistant

In this Part We Will Adding The Feature of Answering Basic & Some Silly Questions to Jarvis:

elif 'great work jarvis' in query:
     speak("Thank you Sir, I Love You")

  elif 'you need a break' in query:
     speak("Ok Sir, You can Wake me up later")
     break

  elif 'how are you' in query:
     speak("I'm Fine, How are you?")

  elif 'who created you' in query:
     speak("I was created by tanmay sinha in 2022 august")

  elif 'are you better than google assistant' in query:
     speak("can't say i am just a normal artificail intellignece and google is suprerior")

  elif 'are you better than siri' in query:
     speak("Not Sure, Siri is one of my best friend")

  elif 'are you better than alexa' in query:
     speak("I Love My Dear Alexa")

  elif 'who are you' in query:
     speak("i am jarvis, a voice assistant created by mister programmer")
     
  elif 'i am fine' in query:
     speak("great! keep using me")

  elif 'i am fine' in query:
     speak("great! keep using me")

  elif 'will you marry me' in query:
     speak("probably Not, I am a Artificial Intelligence Not a Human you should marry a human being")

  elif 'you are bad' in query:
     speak("sad to hear but, i will try my best to improve")

  elif 'sing a song' in query:
    speak("Yes I can sing. I like to help you, even if it's strange. So I sing.")
  
  elif "tell me a joke" in query:
    speak("Why shouldn't you write with a broken pencil? Because it's pointless")
   
  elif "lame" in query:
    speak("Ok I Will try My Best")

4. Adding Temperature & Weather API

Adding the Temperature Function to Jarvis, So that It Can Tell the Current Temperature When Asked by the User:

# temperature
  elif "temperature" in query:
    search = "temperature in city name"
    url = f"https://www.google.com/search?q={search}"
    r = requests.get(url)
    data = BeautifulSoup(r.text,"html.parser")
    temp = data.find("div", class_ = "BNeawe").text
    speak(f"current {search} is {temp}")
    print(f"Current Temperature In city name {search} is {temp}")

So Programmers This was it For this Blog See you in the Next One Till Then Keep Coding Keep Exploring!

DOWNLOAD SOURCE CODE

Leave a Reply

Your email address will not be published. Required fields are marked *

You cannot copy content of this page

Top 10 Programming Languages to Learn In 2023! 9 Best Extensions For Web Developers! | Chrome Extensions For Web Developers Web Development Roadmap Best Resources to Learn PYTHON FREE! Web Vs App Development- Which one is Better?