-
Notifications
You must be signed in to change notification settings - Fork 1
/
video_osc.py
58 lines (45 loc) · 1.83 KB
/
video_osc.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
# FaceOSC -> Wekinator
from pythonosc.dispatcher import Dispatcher
from pythonosc import osc_server
from pythonosc import udp_client
if __name__ == '__main__':
IP_ADDRESS = "127.0.0.1"
SENDING_TO = 6448
RECEIVING_FROM = 8338
WEK_INPUT = "/wek/inputs"
client = udp_client.SimpleUDPClient(IP_ADDRESS, SENDING_TO)
print(f"OSC Video client, sending to --> {IP_ADDRESS}:{SENDING_TO}")
new_message = {
"/gesture/mouth/width": 0.0,
"/gesture/mouth/height": 0.0,
"/gesture/eyebrow/left": 0.0,
"/gesture/eyebrow/right": 0.0,
"/gesture/eye/left": 0.0,
"/gesture/eye/right": 0.0,
"/gesture/jaw": 0.0,
"/gesture/nostrils": 0.0,
}
def package_gesture(address, data):
new_message[address] = data
message = list(new_message.values())
client.send_message(WEK_INPUT, message)
def raw_handler(unused_addr, *args):
'''we don't use raw messages but they can be handled here'''
pass
dispatcher = Dispatcher()
dispatcher.map('/gesture/mouth/width', package_gesture)
dispatcher.map('/gesture/mouth/height', package_gesture)
dispatcher.map('/gesture/eyebrow/left', package_gesture)
dispatcher.map('/gesture/eyebrow/right', package_gesture)
dispatcher.map('/gesture/eye/left', package_gesture)
dispatcher.map('/gesture/eye/right', package_gesture)
dispatcher.map('/gesture/jaw', package_gesture)
dispatcher.map('/gesture/nostrils', package_gesture)
dispatcher.map("/raw", raw_handler)
try:
server = osc_server.ThreadingOSCUDPServer((IP_ADDRESS, RECEIVING_FROM), dispatcher)
print("Serving on {}".format(server.server_address))
server.serve_forever()
except KeyboardInterrupt:
print("\nServer has been stopped by the user.")
server.server_close()