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