yum-slop/TaSTT

Free self-hosted STT for VRChat.

git clone https://git.yummers.dev/yum-slop/TaSTT

yumSupport as few as 1 char per sync in custom chatboxc27d3fd

v0.21.0
4.4 KiB134 linesraw
1from math import ceil
2from math import floor
3
4def replaceMacros(lines, macro_defs):
5    for k,v in macro_defs.items():
6        lines = lines.replace("%" + k + "%", v)
7    return lines
8
9class Config():
10    def __init__(self):
11        self.BOARD_ROWS=4
12        self.BOARD_COLS=48
13        self.CHARS_PER_CELL=256
14        self.BYTES_PER_CHAR=2
15        self.CHARS_PER_SYNC=10
16
17    def numRegions(self, which_layer):
18        num_cells = self.BOARD_ROWS * self.BOARD_COLS
19        layers_in_last_region = num_cells % self.CHARS_PER_SYNC
20        float_result = num_cells / self.CHARS_PER_SYNC
21        if which_layer >= layers_in_last_region:
22            return floor(float_result)
23        else:
24            return ceil(float_result)
25
26    def layerNeedsParity(self, which_layer):
27        num_cells = self.BOARD_ROWS * self.BOARD_COLS
28        layers_in_last_region = num_cells % self.CHARS_PER_SYNC
29        if layers_in_last_region > 0 and which_layer >= layers_in_last_region:
30            return True
31        else:
32            return False
33
34config = Config()
35
36# Implementation detail. We use this parameter to return from the terminal
37# state of the FX layer to the starting state.
38def getDummyParam():
39    return "TaSTT_Dummy"
40
41def getToggleParam():
42    return "TaSTT_Toggle"
43
44def getScaleParam():
45    return "TaSTT_Scale"
46
47def getEnablePhonemeParam():
48    return "TaSTT_Enable_Phoneme"
49
50# When this is set to true, the board clears.
51def getClearBoardParam():
52    return "TaSTT_Clear_Board"
53
54def getLockWorldParam():
55    return "TaSTT_Lock_World"
56
57# Each layer controls a group of cells. There's only one letter per layer, thus
58# this is also the name of the parameter which sets the letter for a layer.
59def getLayerParam(which_layer: int, byte: int) -> str:
60    return "TaSTT_L%02dB%01d" % (which_layer, byte)
61
62def getLayerName(which_layer: int, byte: int) -> str:
63    return getLayerParam(which_layer, byte)
64
65def getBlendParam(which_layer: int, byte: int) -> str:
66    return "TaSTT_L%02dB%01d_Blend" % (which_layer, byte)
67
68def getDefaultStateName(which_layer:int , byte: int):
69    return "TaSTT_L%02dB%01d_Do_Nothing" % (which_layer, byte)
70
71def getActiveStateName(which_layer: int, byte: int):
72    return "TaSTT_L%02dB%01d_Active" % (which_layer, byte)
73
74def getSelectStateName(which_layer, select):
75    return "TaSTT_L%02d_S%02d_B%01d" % (which_layer, select, byte)
76
77def getBlendStateName(which_layer, select, byte):
78    return "TaSTT_L%02d_S%02d_B%01d_Blend" % (which_layer, select, byte)
79
80def getLetterStateName(which_layer, select, letter, byte):
81    return "TaSTT_L%02d_S%02d_L%03d_B%01d" % (which_layer, select, letter, byte)
82
83def getSelectParam() -> str:
84    return "TaSTT_Select"
85
86def getEnableParam():
87    return "TaSTT_Enable"
88
89def getSoundParam(i: int):
90    return f"TaSTT_Sound{str(i)}"
91
92def getEllipsisParam():
93    return "TaSTT_Ellipsis"
94
95def getBoardIndex(which_layer, select):
96    # Because we divide the board into a multiple of 8 cells, some cells may
97    # describe animations which don't exist, depending on the size of the board.
98    # We work around this by simply wrapping those animations back to the top
99    # of the board, and rely on the OSC controller to simply not reference
100    # those cells.
101    return (select * config.CHARS_PER_SYNC + which_layer) % (config.BOARD_ROWS * config.BOARD_COLS)
102
103def getShaderParamByRowColByte(row, col, byte):
104    return "_Letter_Row%02d_Col%02d_Byte%01d" % (row, col, byte)
105
106# Mapping from layer to shader param.
107def getShaderParam(which_layer, select, byte):
108    index = getBoardIndex(which_layer, select)
109
110    col = index % config.BOARD_COLS
111    row = floor(index / config.BOARD_COLS)
112
113    return getShaderParamByRowCol(row, col, byte)
114
115# The name of the animation which writes `letter` at a specific position in the
116# display.
117def getLetterAnimationName(row, col, letter, nth_byte):
118    return "R%02dC%02dL%02dB%01d" % (row, col, letter, nth_byte)
119
120# The name of the animation which clears the entire board.
121def getClearAnimationName():
122    return "TaSTT_Clear_Board"
123
124def getAnimationNameByLayerAndIndex(which_layer, select, letter, nth_byte):
125    index = getBoardIndex(which_layer, select)
126
127    col = index % config.BOARD_COLS
128    row = floor(index / config.BOARD_COLS)
129
130    return "R%02dC%02dL%02dB%01d" % (row, col, letter, nth_byte)
131
132# Returns the path to the animation for the given shader parameter + letter.
133def getAnimationPath(shader_param, letter):
134    return "generated/animations/%s_Letter%02d.anim" % (shader_param, letter)