-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker.py
240 lines (177 loc) · 6.12 KB
/
docker.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import asyncio
from bleak import BleakScanner
from termcolor import cprint
import time
import datetime
from os import path, getcwd
from tactigon_gear import TSkin, TSkinConfig, Hand, GestureConfig, OneFingerGesture
from tactigon_speech import TSkin_Speech, TSkinConfig, Hand, VoiceConfig, OneFingerGesture, TSpeechObject, TSpeech, HotWord
TARGET_DEVICE_NAME = "TSKIN50"
TSKIN: TSkin = None
async def scan_devices():
tskin_devices: dict = dict()
index = 1
cprint('Scanning started...\n', 'light_magenta')
devices = await BleakScanner.discover()
for device in devices:
if device.name == TARGET_DEVICE_NAME:
tskin_devices[index] = device.address
index += 1
return tskin_devices
def get_selected_tskin(devices: dict) -> str:
while True:
cprint('Select a TSKIN device.', 'light_cyan')
for k,v in devices.items():
cprint(f' press {k} for {v}', 'blue')
print()
selected_tskin = int(input('Select: '))
if int(selected_tskin) not in devices.keys():
cprint('Ops.. Invalid number for tskin!\n', 'light_yellow')
continue
cprint(f'You selected {devices[selected_tskin]} tskin\n', 'light_green')
return devices[selected_tskin]
def get_selected_hand():
while True:
selected_hand= input('Select the hand (r=RIGHT, l=LEFT): ').lower().strip()
if selected_hand not in ['r','l']:
cprint('Ops.. Invalid value for hand!\n', 'light_yellow')
continue
tskin_hand = Hand.RIGHT if selected_hand == 'r' else Hand.LEFT
cprint(f"You selected {tskin_hand.value} hand\n", 'light_green')
return tskin_hand
def configure_tskin(tskin_mac: str, tskin_hand: Hand) -> TSkin:
model_folder = getcwd()
TSKIN_NAME = "TSKIN"
gesture_config = GestureConfig(
path.join(model_folder, "model.pickle"),
path.join(model_folder, "encoder.pickle"),
"demo",
datetime.datetime.now(),
["up","down","push","pull","twist","circle","swipe_r","swipe_l"]
)
tskin_cfg = TSkinConfig(tskin_mac, tskin_hand, TSKIN_NAME, gesture_config)
voice_cfg = VoiceConfig(
path.join(model_folder, "models.tflite"),
path.join(model_folder, "tos.scorer"),
)
global TSKIN
TSKIN = TSkin_Speech(tskin_cfg, voice_cfg)
return
def select_program():
programs = {
1: 'gear',
2: 'speech'
}
cprint('Select a program to execute.', 'light_cyan')
while True:
for k,v in programs.items():
cprint(f' press {k} for {v}', 'blue')
selected_program = int(input('\nSelect: '))
if int(selected_program) not in programs.keys():
cprint('Ops.. Invalid program!\n', 'light_yellow')
continue
return programs[selected_program]
def speech():
tspeech_obj = TSpeechObject(
[
TSpeech(
[HotWord("start"), HotWord("enter")],
TSpeechObject(
[
TSpeech(
[HotWord("application")]
)
]
)
)
]
)
i = 0
cprint("Tap to enable listening mode.", "light_cyan")
while True:
if not TSKIN.connected:
cprint("Reconnecting..", 'light_magenta')
time.sleep(0.5)
continue
if i > 2:
break
if TSKIN.is_listening:
cprint("Listening...", 'light_magenta')
time.sleep(0.5)
continue
touch = TSKIN.touch
transcription = TSKIN.transcription
if transcription:
if transcription.timeout:
if transcription.time == 0:
cprint("Silence timeout. No words found!", 'light_yellow')
else:
cprint("Voice timeout. Cannot process more than", 'light_yellow')
else:
print("Transcription found!")
cprint(transcription, 'green')
if touch:
if touch.one_finger == OneFingerGesture.TAP_AND_HOLD:
i += 1
elif touch.one_finger == OneFingerGesture.SINGLE_TAP:
if TSKIN.listen(tspeech_obj):
cprint("Waiting for voice commands...", 'light_magenta')
cprint("Try to say:\n - Start application\n - Enter applcaition\n", 'blue')
else:
i = 0
time.sleep(0.02)
def gear():
i = 0
while True:
if not TSKIN.connected:
cprint("Reconnecting..", 'light_magenta')
time.sleep(0.2)
continue
if i > 5:
break
t = TSKIN.touch
a = TSKIN.angle
g = TSKIN.gesture
cprint(a, 'light_grey')
if g or t:
cprint(g if g else t, 'green')
time.sleep(1)
if t and t.one_finger == OneFingerGesture.TAP_AND_HOLD:
i += 1
else:
i = 0
time.sleep(0.02)
def connect_tskin():
while not TSKIN.connected:
cprint("Connecting..", 'light_magenta')
time.sleep(0.5)
cprint("Connected!", 'green')
def disconnect_tskin():
if TSKIN and TSKIN.connected:
cprint("Disconnecting...", 'light_yellow')
TSKIN.terminate()
cprint("Disconnected!", 'red')
def main():
cprint('We are looking for your Tactigon Skin...', 'light_magenta')
while True:
devices = asyncio.run(scan_devices())
devices_count = len(devices)
if devices_count == 0:
cprint("We couldn't find any TSKIN devices! press enter to rescan..", 'light_yellow')
input()
continue
else:
mac_address = get_selected_tskin(devices)
hand = get_selected_hand()
program = select_program()
configure_tskin(mac_address, hand)
TSKIN.start()
connect_tskin()
globals()[program]()
disconnect_tskin()
return
if __name__ == '__main__':
try:
main()
except(KeyboardInterrupt):
disconnect_tskin()