[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({});