- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
Latest commit
109 lines (102 loc) · 3.39 KB
/
Copy pathmain.py
File metadata and controls
109 lines (102 loc) · 3.39 KB
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
importspeech_recognitionassr
importos
importsys
importpyautogui
#import speech
r=sr.Recognizer()
#r.energy_threshold = 500
deflisten():
withsr.Microphone(device_index=0) assource:
r.adjust_for_ambient_noise(source, duration=1)
#speech.say('SEARCHING KEYWORD')
print('listening')
audio=r.listen(source)
print(audio)
#r.recognize_google(audio)
#listen()
try:
command=r.recognize_google(audio)
print("Predictions: "+command)
if"volume up"incommand:
#speech.say('volume up')
l=command.split()
foriinrange(20):
pyautogui.hotkey('volumeup')
listen()
if"volume down"incommand:
l=command.split()
foriinrange(10):
pyautogui.hotkey('volumedown')
#pyautogui.hotkey('fn', 'pause')
listen()
if"close tab"incommand:
#speech.say('closing tab')
pyautogui.hotkey('ctrl', 'w')
listen()
#listen()
if"close"incommand:
l=command.split()
i=l.index('close')
kill="taskkill /f /im "+command.split()[i+1] +".exe"
#speech.say('closing ' + command.split()[i+1])
os.system(kill)
listen()
if"exit"incommand:
#speech.say('closing program')
sys.exit()
if"type"incommand:
l=command.split()
i=l.index('type')
s=len(l)
e=""
forjinrange(i+1, s):
e+= (l[j]) +" "
pyautogui.write(e)
listen()
if"open"incommand:
l=command.split()
i=l.index('open')
ifl[i+1] !="chrome"or"firefox":
os.system("start "+l[i+1])
ifl[i+1] !="chrome"or"firefox":
os.system("start "+l[i+1] +":")
#speech.say('starting' + l[i + 1])
if"press enter"incommand:
pyautogui.press("enter")
ifcommand=="new tab":
pyautogui.hotkey('ctrl', 't')
listen()
if"new tab"incommand:
pyautogui.hotkey('ctrl', 't')
listen()
if"tab"incommand:
l=command.split()
i=l.index('tab')
pyautogui.hotkey('ctrl', l[i+1])
listen()
if"switch window"incommand:
pyautogui.hotkey('alt', 'tab')
listen()
if".com"incommand:
l=command.split()
i=l.index('start')
os.system("start "+"www."+l[i+1])
print("start "+"www."+l[i+1])
listen()
if"scroll down"incommand:
#l = command.split()
#i = l.index('down')
#for i in range(int(l[i+1])):
pyautogui.scroll(-50)
listen()
#if '.com' is after browser check, program doesn't run .com check suspecting "or" statement interference
else:
listen()
listen()
#else: what does : mean?
# os.system(command + ":")
#print(type(command))
exceptException:
print("Something went wrong")
listen()
listen()