-
Notifications
You must be signed in to change notification settings - Fork 0
/
J.A.R.V.I.S.2.py
153 lines (140 loc) · 5.15 KB
/
J.A.R.V.I.S.2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import getpass
from random import randint
import json
import requests
import pyautogui
import time
import pyttsx3
import speech_recognition as sr
import datetime
import wikipedia
import webbrowser
import os
import sys
import smtplib
#plz enter your chrome_path and don't forgot to write %s in the chrome_path end
chrome_path = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
engine = pyttsx3.init("sapi5")
voices = engine.getProperty("voices")
#i am using microsoft david for my jarvis you can also make friday with the help of ([1].id)
engine.setProperty("voice", voices[0].id)
password = "hello"
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 Sir")
elif hour>=12 and hour<18:
speak("Good Afternoon Sir")
else:
speak("Good Evening Sir")
speak("I am jarvis your assistant how may i help you")
def screenshot():
img = pyautogui.screenshot()
img.save("D:\\scr\\screenshot.png") #path where screenshot will be saved
def takeCommand():
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
def passWord():
n = getpass.getpass('>> ')
if n == password:
print("The password is ended with status (DONE)\n")
else:
print("The code is exited with status (NOT DONE)\nSorry you can't able to use jarvis")
time.sleep(5)
quit()
if __name__ == "__main__":
passWord()
wishMe()
while True:
query = takeCommand().lower()
print(query)
if "how are you" in query:
speak("I am fine and pray for your well being")
print("I am fine and pray for your well being")
elif "news" in query:
i
url="your newsapi key"
page=requests.get(url)
text=page.text
news=json.loads(text)
articles=news["articles"]
newsPoint=articles[randint(0,len(articles)-1)]['title']
print(newsPoint)
speak(newsPoint)
elif "who are you" in query:
speak("I am your assistant jarvis")
print("I am your assistant jarvis")
elif "take screenshot" in query:
speak("taking screenshot")
screenshot()
elif "open wikipedia" in query:
speak("here it is")
webbrowser.get(chrome_path).open("wikipedia.com")
elif "open my yt channel" in query:
speak("here it is")
webbrowser.get(chrome_path).open("https://www.youtube.com/channel/UC556qZbJolO8iLxh1n2u4vQ?view_as=subscriber")
elif "open twitter" in query:
speak("here it is")
webbrowser.get(chrome_path).open("twitter.com")
elif "wikipedia" in query:
speak("searching wikipedia....")
query = query.replace("wikipedia","")
results = wikipedia.summary(query, sentences=2)
print(results)
speak(results)
elif "open youtube" in query:
speak("here it is")
webbrowser.get(chrome_path).open("youtube.com")
elif "play music" in query:
speak("ok sir,here it is")
music_dir = "E:\\music2"
songs = os.listdir(music_dir)
print(songs)
os.startfile(os.path.join(music_dir, songs[0]))
elif "play song" in query:
speak("ok sir,here it is")
# plz write your place where the song you have placed
music_dir = "E:\\music2"
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}")
print(strTime)
elif "todays weather" in query:
speak("ok sir, here it is")
webbrowser.get(chrome_path).open("https://weather.com/en-IN/weather/today/l/c1147cf4cecd551f01f6bcfaa0393f60bb53387712d166cda2f6e2efa58328da")
elif "thanks" in query:
speak("my pleasure")
print("my pleasure")
elif "thanks jarvis" in query:
speak("welcome sir")
print("welcome sir")
elif "google search" in query:
speak("recognizing")
speak("sir, plz enter what do you want to search")
pc = input("Enter google search = ")
speak("searching google...")
webbrowser.get(chrome_path).open("https://google.com/?q="+pc)
elif "abort" in query:
speak("closing program thanks sir for giving me your precious time")
quit()
else:
print("sorry the command you entered is not satisfied")
speak("sorry the command you entered is not satisfied")