-
Notifications
You must be signed in to change notification settings - Fork 2
/
temp_jarvis.py
177 lines (126 loc) · 4.32 KB
/
temp_jarvis.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import datetime
import os
import random
import webbrowser
import requests
import speech_recognition as sr
import pyttsx3
import wikipedia
import json
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voices', voices[0].id)
def speak(something):
engine.say(something)
engine.runAndWait()
def printWithSpeek(msg):
print(msg)
speak(msg)
def cmd(str):
os.system(str)
def greet():
hour = int(datetime.datetime.now().hour)
if hour >= 0 and hour <= 12:
speak(f"Good Morning {user_name}")
elif hour <= 12 and hour >= 18:
speak(f"Good Afternoon {user_name}")
else:
speak(f"Good Evening {username}")
printWithSpeek("Iam Jarvis, Tell me how can i help you?")
def speekInput():
rec = sr.Recognizer()
with sr.Microphone() as mic:
printWithSpeek('\rListening... ')
rec.pause_threshold = 1
listen = rec.listen(mic)
try:
print("\rRecognizing... ")
query = rec.recognize_google(listen, language='en-US')
print(f"Query: {query}")
except Exception as e:
printWithSpeek("I was unable to recognize, please say again! ")
return 'None'
return query.lower()
def playSong(dir=music_dir):
music_files = os.listdir(dir)
total_files = len(music_files) - 1
index = 0
os.startfile(dir + music_files[random.randint(index, total_files)])
def exitCheck(output):
if 'and' in output.split():
if 'exit' in output.split():
exit(0)
return True
def SelectSomething():
speak('Enter file path to search....')
file_path = input("Enter: ")
return file_path
def check_code(url):
req = requests.get(url)
if req.status_code == 200:
return True
else:
return False
def showFiles(path):
files = os.listdir(path)
for i, file in enumerate(files):
speak("I found the Following files")
print(f"[{i}] \t {file}")
choose = speekInput()
if choose < len(files):
os.startfile(files[int(choose)])
else:
speak('Index Out Of range, i was unable to start file')
sits_names = ['google', 'github', 'youtube', 'tryhackme', 'instagram', 'spotify', 'facebook', 'duckduckgo'
, 'amazon', 'ebay', 'stackoverflow']
query_list = ['/results?search_query=', '/search?q=', '/?t=ffab&q=', '/?=']
windows_applications = ['']
c_drice = 'C:\\'
d_drive = 'D:\\'
def main():
global outputt
greet()
while True:
output = speekInput()
if 'wikipedia' in output:
printWithSpeek('Searching Wikipedia...')
outputt = output.replace('wikipedia', "")
outputt = outputt.replace('Wikipedia ', "")
results = wikipedia.summary(outputt, sentences=2)
printWithSpeek(results)
elif 'open ' in output:
outputt = outputt.replace('for', '')
outputt = outputt.split()
search_index = outputt.index('open') + 1
x = outputt[search_index]
if x in sits_names:
site = 'https://' + x + '.com'
if 'search' in outputt:
query = outputt.index('search') + 1
query = outputt[query:]
search = ''
for word in query:
search += word + '+'
printWithSpeek(f'Opening {x} and searching...')
for q in query_list:
if check_code(site + q + search[0:-1]):
webbrowser.open(site + q + search[0:-1])
else:
printWithSpeek(f'Opening {x}')
webbrowser.open(site)
exitCheck(output)
elif 'play music' in output:
playSong('C:\\Users\\shauk\\Downloads\\Music\\')
exitCheck(output)
exitCheck(output)
elif output == 'exit':
speak("GoodBye Saad")
exit()
elif 'show files' in output:
x = SelectSomething()
showFiles(x)
elif 'gpt' in output or 'gpt mode' in output:
try:
main()
except Exception as e:
printWithSpeek(e)