forked from pladisdev/VTS-AI-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
65 lines (45 loc) · 1.98 KB
/
main.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
import asyncio
import time
from vtube_studio.vts import VTS_API
from modules.gui import GUI
from modules.vtuber_movement import Vtube_Control
#Make sure to create a Vtube Studio plugin first
URL = "ws://localhost:8001/" #Verify this is the right port
async def main():
movement = Vtube_Control()
async with VTS_API(URL) as vtube_studio:
########################################### Model Expressions ###########################################
#Wait for connection to vtube studio and get expressions
#TODO probably should have a flag to wait till vtube is connected, and expressions are set
expressions = []
timeout = time.time()+10
while expressions == [] and time.time() < timeout:
await asyncio.sleep(.1)
expressions = await vtube_studio.return_expressions()
print(f"Expressions in model: {expressions}")
# load GUI with expression found in vtube studio
gui = GUI(expressions)
#Sets eye and head movement to 0
await vtube_studio.ai_movement(movement.head, movement.eyes, movement.eye_lids)
expression = ""
#Main loop
while True:
if gui.exit:
break
elif gui.new_expression:
expression = gui.expression
await vtube_studio.toggle_expression(expression)
gui.new_expression = False
elif gui.value_change:
movement.gui_update(gui)
gui.value_change = False
current_time = time.time()
movement.head_movement(current_time)
movement.eye_movement(current_time)
movement.eye_lid_movement(current_time)
await vtube_studio.ai_movement(movement.head, movement.eyes, movement.eye_lids)
#Frame rate of controlling vtube studio, set to 10 FPS
await asyncio.sleep(.1)
await gui.end()
if(__name__ == '__main__'):
asyncio.run(main())