-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvoipPlayer.py
187 lines (138 loc) · 3.73 KB
/
voipPlayer.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
178
179
180
181
182
183
184
185
186
187
import pygetwindow as pw
import pyautogui as pg
import time
import azure.cognitiveservices.speech as speechsdk
import dotenv
import os
dotenv.load_dotenv()
keymap = {
"forward": "w",
"backward": "s",
"left": "a",
"right": "d",
"jump": "space",
"sprint": "shift",
}
X_OFFSET = 100
game = "Minecraft"
## Game Commands:
def forward():
pg.keyDown(keymap["forward"])
def backward():
pg.keyDown(keymap["backward"])
def left():
pg.keyDown(keymap["left"])
def right():
pg.keyDown(keymap["right"])
def jump():
pg.keyDown(keymap["jump"])
time.sleep(0.05)
pg.keyUp(keymap["jump"])
def sprint():
pg.keyDown(keymap["sprint"])
def stop():
for key in keymap.values():
pg.keyUp(key)
def right():
for _ in range(2):
pg.moveRel(X_OFFSET, yOffset=0, duration=0.25)
pg.keyDown(keymap["forward"])
def left():
for _ in range(2):
pg.moveRel(-X_OFFSET, yOffset=0, duration=0.25)
pg.keyDown(keymap["forward"])
def creative():
pg.write("/gamemode creative", interval=0.1)
pg.press("enter")
def survival():
pg.write("/gamemode survival", interval=0.1)
pg.press("enter")
def look_back():
for _ in range(4):
pg.moveRel(X_OFFSET, yOffset=0, duration=0.25)
def day():
pg.write("/time set day", interval=0.1)
pg.press("enter")
def night():
pg.write("/time set night", interval=0.01)
pg.press("enter")
def attack():
pg.click()
def break_block():
pg.mouseDown()
def place_block():
pg.keyDown(keymap["jump"])
pg.keyUp(keymap["jump"])
pg.click(button="right")
def activate_window(title):
game = pw.getWindowsWithTitle(title)[0]
game.minimize()
game.restore()
screen_width, screen_height = pg.size()
pg.moveTo(screen_width // 2, screen_height // 2)
def quit_command(title):
quit = pw.getWindowsWithTitle(title)
if quit:
quit[0].close()
def start_speech_engine():
done = False
def stop_cb():
print("Stopping Recognition")
speech_recognizer.stop_continuous_recognition()
nonlocal done
done = True
speech_config = speechsdk.SpeechConfig(
subscription=os.environ.get("API_KEY"), region="centralindia"
)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
speech_recognizer.recognizing.connect(analyse)
speech_recognizer.session_started.connect(lambda _: print("Voice engine active!"))
speech_recognizer.canceled.connect(lambda _: print("API Failure"))
speech_recognizer.session_stopped.connect(stop_cb)
speech_recognizer.start_continuous_recognition()
while not done:
time.sleep(0.5)
def analyse(evt):
word = evt.result.text
print(word)
if "left" in word:
left()
if "right" in word:
right()
if "forward" in word or "straight" in word:
forward()
if "stop" in word:
stop()
if "jump" in word:
jump()
if "fly" in word:
for _ in range(2):
jump()
if "creative" in word or "immortal" in word:
creative()
if "survival" in word or "normal" in word:
survival()
if "backward`" in word:
look_back()
if "day" in word:
day()
if "night" in word:
night()
if "quit" in word:
print("Closing game")
time.sleep(1)
quit_command(game)
print("See you next time !")
if "attack" in word:
attack()
if "break" in word:
break_block()
if "place block" in word or "place" in word:
place_block()
if "sprint" in word or "run" in word:
sprint()
if __name__ == "__main__":
print("WELCOME PLAYER")
print("Type your game here to play:", game)
game = input()
start_speech_engine()