IRON MAN JARVIS 'AI' CODE
please read the following instruction before using jarvis code.
Requirements to run the following code.
now jarvis is not only part of the movie it becomes the real truth
of our life. now let's begin with the jarvis.
Hello guys here the jarvis the virtual artificial intelligent.it
perform
varitive task.
required software:- pycharm or visual code
required downloads:- download the python with latest version in
your system
how to download python?
:-just go to link given below and download the python with latest
version
https://www.python.org/downloads/windows/
now you can prepared with the tools
required set up in python :-before using the code you need to
download the modules in python.
how to download module in python?
go to terminal in your IDE or go to command prompt type the
following
"pip install 'your module name'" ex. pip install pyttsx3.
and then import your module on the top of IDE is shown in below
code you can just copy this code and paste it in your IDE and
if you want to make changes you can.
Note:-
(if unfortunately this code will not run in you computer or laptop
it showing some error on the screen please comment below at this
article. I will definitely give you the solution.)
with this preparation now you can able to use the jarvis like
iron man.
import pyttsx3
import speech_recognition as sr
import datetime
import os
import cv2
import random
import requests
from requests import get
import wikipedia
import webbrowser
import pywhatkit as kit
import sys
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices[0].id)
engine.setProperty('voices',voices[0].id)
#text to speech
def speak(audio):
engine.say(audio)
print(audio)
engine.runAndWait()
#convert voice to text
def takecommand():
r = sr.Recognizer()
with sr.Microphone() as source:
print("listning...")
r.pause_threshold = 1
audio = r.listen(source,timeout=1,phrase_time_limit=5)
try:
print("recognizing...")
query = r.recognize_google(audio,language='en-in')
print(f"user said:{query}")
except Exception as e :
speak("say that again please...")
return "home"
return query
def wish():
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 how may i help you")
def TaskExecution():
wish()
while True:
#if 1:
query = takecommand().lower()
#logic building for task
if 'open notepad' in query:
#use your notepad location then it work and use double cote(\\)
speak("opening notepad")
npath = "C:\\windows\\system32\\notepad.exe"
os.startfile(npath)
elif 'open command prompt' in query:
speak("opening command prompt")
os.system("start cmd")
elif 'open camera'in query:
speak("opening camera")
cap = cv2.VideoCapture(0)
while True:
ret ,img = cap.read()
cv2.imshow('webcam',img)
k = cv2.waitKey(50)
if k==27:
break;
cap.release()
cv2.distroyAllWindows()
elif 'play music' in query:
music_dir = "F:\\music"
songs = os.listdir(music_dir)
rd = random.choice(songs)
os.startfile(os.path.join(music_dir, rd))
elif 'ip address' in query:
ip = get('https://api.ipify.org').text
speak(f"your ip address is {ip}")
elif 'wikipedia' in query:
query = query.replace("wikipedia"," ")
result = wikipedia.summery(query,sentences=2)
speak("according to wikipedia")
speak(result)
elif 'open youtube' in query:
speak("opening youtube")
webbrowser.open("youtube.com")
elif 'open facebook' in query:
speak("opening facebook")
webbrowser.open("facebook.com")
elif 'open my website' in query:
speak("opening computer gyan")
webbrowser.open("computer7gyan.blogspot.com")
elif 'open google' in query:
speak("sir,what should i search on google")
cm = takecommand().lower()
webbrowser.open(f"{cm}")
elif 'send message' in query:
kit.sendwhatmsg("type your friends no",
"this is a testing protocol from jarvis",11,37)
elif 'play song on youtube' in query:
speak("which song would you like to play?")
cm = takecommand().lower()
kit.playonyt(f"{cm}")
elif 'hello' in query:
speak("hello sir,may i help you with something.")
elif 'how are you jarvis' in query:
speak("i am fine sir, what about you.")
elif 'also good' in query:
speak("thats great here from you")
elif 'i am not good' in query:
speak("what happen sir? may i help you something")
elif 'no you cant help me about that' in query:
speak("opps, ok sir if anything that i do for you please call me.")
elif 'no thanks' in query:
speak("thanks for using me sir,have a good day!")
sys.exit()
speak("is the any other work for me sir?")
if __name__== "__main__":
while True:
TaskExecution()
0 Comments