-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeechThings.py
More file actions
124 lines (105 loc) · 4.49 KB
/
speechThings.py
File metadata and controls
124 lines (105 loc) · 4.49 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
from initGame import *
def say(s):
try:
engine = pyttsx3.init()
engine.say(s)
engine.runAndWait() # blocks
except:
return 0
def callback(recognizer, audio):
global scanYesOrNo
try:
global alliedShipList
topCommand = "top"
downCommand = "down"
rightCommand = "right"
leftCommand = "left"
forwardCommand = "forward"
stopCommand = "stop"
retreatCommand = "retreat"
scanCommand = "scan"
scanEnemyCommand = "enemy"
wingCommand = "wing"
oneCommand = "one"
oneoneCommand = "1"
stringKomendy = recognizer.recognize_google(audio)
stringKomendy = stringKomendy.lower()
print("Google Speech Recognition thinks you said " + recognizer.recognize_google(audio))
if stringKomendy.find(topCommand) != -1:
if mainShip.speedVector[1] == 2:
say("Horizontal movement stop.")
mainShip.speedVector[1] = 0
mainShip.speedVector[0] = 0
else:
say("Ship moving ahead.")
mainShip.speedVector[0] = -2
mainShip.speedVector[1] = 0
if stringKomendy.find(downCommand) != -1:
if mainShip.speedVector[0] == -2:
say("Horizontal movement stop.")
mainShip.speedVector[0] = 0
mainShip.speedVector[1] = 0
else:
say("Ship moving back.")
mainShip.speedVector[0] = 0
mainShip.speedVector[1] = 2
if stringKomendy.find(rightCommand) != -1:
if mainShip.speedVector[2] == -2:
say("Vertical movement stop.")
mainShip.speedVector[3] = 0
mainShip.speedVector[2] = 0
else:
say("Ship moving right.")
mainShip.speedVector[3] = 2
mainShip.speedVector[2] = 0
if stringKomendy.find(leftCommand) != -1:
if mainShip.speedVector[3] == 2:
say("Vertical movement stop.")
mainShip.speedVector[2] = 0
mainShip.speedVector[3] = 0
else:
say("Ship moving left.")
mainShip.speedVector[2] = -2
mainShip.speedVector[3] = 0
if stringKomendy.find(forwardCommand) != -1:
say("All power to the engines. Ship moving at full speed ahead.")
mainShip.speedVector[0] = -2
mainShip.speedVector[1] = 0
if stringKomendy.find(retreatCommand) != -1:
say("All power to the engines. Ship moving backward at full speed.")
mainShip.speedVector[0] = 0
mainShip.speedVector[1] = 2
if stringKomendy.find(stopCommand) != -1:
say("Engines stop. Ship not moving")
mainShip.speedVector[0] = 0
mainShip.speedVector[1] = 0
mainShip.speedVector[2] = 0
mainShip.speedVector[3] = 0
if stringKomendy.find(scanCommand) != -1:
say("Scanning nearby space for enemies.")
scanYesOrNo = 1
if stringKomendy.find(wingCommand) != -1:
print("test" + str(alliedShipList[1].speedVector[3]))
tempNumber = 1
if stringKomendy.find(oneCommand) != -1 or stringKomendy.find(oneoneCommand):
whatShipControll = 1
######### LEFT
if stringKomendy.find(leftCommand) != -1:
if alliedShipList[tempNumber].speedVector[3] == 1:
say("Wing" + str(whatShipControll) + "Vertical movement stop.")
for i in range(len(alliedShipList)):
if alliedShipList[i].wing == whatShipControll:
alliedShipList[i].speedVector[2] = 0
alliedShipList[i].speedVector[3] = 0
else:
say("Wing" + str(whatShipControll) + " moving left.")
for i in range(len(alliedShipList)):
if alliedShipList[i].wing == whatShipControll:
alliedShipList[i].speedVector[2] = -1
alliedShipList[i].speedVector[3] = 0
except sr.UnknownValueError:
print("Google Speech Recognition could not understand audio")
except sr.RequestError as e:
print("Could not request results from Google Speech Recognition service; {0}".format(e))
def similar(a, b):
return SequenceMatcher(None, a, b).ratio()