yum-slop/TaSTT
Free self-hosted STT for VRChat.
git clone https://git.yummers.dev/yum-slop/TaSTT
c27d3fd
v0.21.0
1from math import ceil 2from math import floor 3 4def replaceMacros ( lines , macro_defs ) : 5for k , v in macro_defs . items () : 6lines = lines . replace ( "%" + k + "%" , v ) 7return lines 8 9class Config () : 10def __init__ ( self ) : 11self . BOARD_ROWS = 4 12self . BOARD_COLS = 48 13self . CHARS_PER_CELL = 256 14self . BYTES_PER_CHAR = 2 15self . CHARS_PER_SYNC = 10 16 17def numRegions ( self , which_layer ) : 18num_cells = self . BOARD_ROWS * self . BOARD_COLS 19layers_in_last_region = num_cells % self . CHARS_PER_SYNC 20float_result = num_cells / self . CHARS_PER_SYNC 21if which_layer >= layers_in_last_region : 22return floor ( float_result ) 23else : 24return ceil ( float_result ) 25 26def layerNeedsParity ( self , which_layer ) : 27num_cells = self . BOARD_ROWS * self . BOARD_COLS 28layers_in_last_region = num_cells % self . CHARS_PER_SYNC 29if layers_in_last_region > 0 and which_layer >= layers_in_last_region : 30return True 31else : 32return 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 () : 39return "TaSTT_Dummy" 40 41def getToggleParam () : 42return "TaSTT_Toggle" 43 44def getScaleParam () : 45return "TaSTT_Scale" 46 47def getEnablePhonemeParam () : 48return "TaSTT_Enable_Phoneme" 49 50# When this is set to true, the board clears. 51def getClearBoardParam () : 52return "TaSTT_Clear_Board" 53 54def getLockWorldParam () : 55return "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 : 60return "TaSTT_L%02dB%01d" % ( which_layer , byte ) 61 62def getLayerName ( which_layer : int , byte : int ) -> str : 63return getLayerParam ( which_layer , byte ) 64 65def getBlendParam ( which_layer : int , byte : int ) -> str : 66return "TaSTT_L%02dB%01d_Blend" % ( which_layer , byte ) 67 68def getDefaultStateName ( which_layer : int , byte : int ) : 69return "TaSTT_L%02dB%01d_Do_Nothing" % ( which_layer , byte ) 70 71def getActiveStateName ( which_layer : int , byte : int ) : 72return "TaSTT_L%02dB%01d_Active" % ( which_layer , byte ) 73 74def getSelectStateName ( which_layer , select ) : 75return "TaSTT_L%02d_S%02d_B%01d" % ( which_layer , select , byte ) 76 77def getBlendStateName ( which_layer , select , byte ) : 78return "TaSTT_L%02d_S%02d_B%01d_Blend" % ( which_layer , select , byte ) 79 80def getLetterStateName ( which_layer , select , letter , byte ) : 81return "TaSTT_L%02d_S%02d_L%03d_B%01d" % ( which_layer , select , letter , byte ) 82 83def getSelectParam () -> str : 84return "TaSTT_Select" 85 86def getEnableParam () : 87return "TaSTT_Enable" 88 89def getSoundParam ( i : int ) : 90return f"TaSTT_Sound { str ( i ) } " 91 92def getEllipsisParam () : 93return "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. 101return ( select * config . CHARS_PER_SYNC + which_layer ) % ( config . BOARD_ROWS * config . BOARD_COLS ) 102 103def getShaderParamByRowColByte ( row , col , byte ) : 104return "_Letter_Row%02d_Col%02d_Byte%01d" % ( row , col , byte ) 105 106# Mapping from layer to shader param. 107def getShaderParam ( which_layer , select , byte ) : 108index = getBoardIndex ( which_layer , select ) 109 110col = index % config . BOARD_COLS 111row = floor ( index / config . BOARD_COLS ) 112 113return 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 ) : 118return "R%02dC%02dL%02dB%01d" % ( row , col , letter , nth_byte ) 119 120# The name of the animation which clears the entire board. 121def getClearAnimationName () : 122return "TaSTT_Clear_Board" 123 124def getAnimationNameByLayerAndIndex ( which_layer , select , letter , nth_byte ) : 125index = getBoardIndex ( which_layer , select ) 126 127col = index % config . BOARD_COLS 128row = floor ( index / config . BOARD_COLS ) 129 130return "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 ) : 134return "generated/animations/%s_Letter%02d.anim" % ( shader_param , letter )