Download config.py from beleata74/BgTTS-40M-Engram-Loop: direct link, hf CLI and curl.
- Browser
- Download file 4.31 kB
-
https://huggingface.co/beleata74/BgTTS-40M-Engram-Loop/resolve/main/config.py
- Command line
-
hf download hf://beleata74/BgTTS-40M-Engram-Loop/config.py
-
curl -L -o config.py https://huggingface.co/beleata74/BgTTS-40M-Engram-Loop/resolve/main/config.py
4.31 kB
| """Vocabulary and tensor dimensions inherited from BgTTS V2.""" | |
| # โโ MioCodec 25Hz โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| CODEC_MODEL_NAME = "Aratako/MioCodec-25Hz-44.1kHz-v2" | |
| CODEC_SAMPLE_RATE = 44_100 | |
| CODEC_NUM_CODEBOOKS = 1 | |
| CODEC_CODEBOOK_SIZE = 12_800 | |
| CODEC_FRAME_RATE = 25.0 | |
| CODEC_TOKENS_PER_SEC = 25 # 25fps ร 1 codebook | |
| TOKENS_PER_FRAME = 1 | |
| SPEAKER_EMB_DIM = 128 # MioCodec global_embedding dimension | |
| # โโ Character set (same as V5) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| BG_LOWER = "ะฐะฑะฒะณะดะตะถะทะธะนะบะปะผะฝะพะฟัััััั ัััััััั" | |
| BG_UPPER = "ะะะะะะะะะะะะะะะะะ ะกะขะฃะคะฅะฆะงะจะฉะชะฌะฎะฏ" | |
| EN_LOWER = "abcdefghijklmnopqrstuvwxyz" | |
| EN_UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
| DIGITS = "0123456789" | |
| PUNCT = '.,!?;:-โโโฆ"\'()[]{}ยซยปโ"" ' | |
| EXTRA = "\n\t" | |
| _ALL_CHARS: list[str] = [] | |
| _seen: set[str] = set() | |
| for _src in [BG_LOWER, BG_UPPER, EN_LOWER, EN_UPPER, DIGITS, PUNCT, EXTRA]: | |
| for _ch in _src: | |
| if _ch not in _seen: | |
| _ALL_CHARS.append(_ch) | |
| _seen.add(_ch) | |
| # โโ Special tokens (indices 0..8) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| SPECIAL_TOKENS = { | |
| "<pad>": 0, | |
| "<start_of_text>": 1, | |
| "<end_of_text>": 2, | |
| "<start_of_speech>": 3, | |
| "<end_of_speech>": 4, | |
| "<spk_0>": 5, # reserved vocabulary ID | |
| "<spk_1>": 6, | |
| "<spk_2>": 7, | |
| "<spk_3>": 8, | |
| } | |
| NUM_SPECIAL_TOKENS = len(SPECIAL_TOKENS) # 9 | |
| # โโ Vocab offsets โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| TEXT_CHARS = _ALL_CHARS | |
| TEXT_VOCAB_SIZE = len(TEXT_CHARS) # ~146 | |
| TEXT_OFFSET = NUM_SPECIAL_TOKENS # 9 | |
| AUDIO_OFFSET = TEXT_OFFSET + TEXT_VOCAB_SIZE # 155 | |
| NUM_AUDIO_TOKENS = CODEC_CODEBOOK_SIZE # 12,800 | |
| TOTAL_VOCAB_SIZE = AUDIO_OFFSET + NUM_AUDIO_TOKENS # 12,955 | |
| # Encoder needs only text vocab; decoder needs full vocab | |
| ENCODER_VOCAB_SIZE = AUDIO_OFFSET # 155 (special + text) | |
| DECODER_VOCAB_SIZE = TOTAL_VOCAB_SIZE # 12,955 (full) | |
| # โโ Convenience IDs โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| PAD_TOKEN_ID = SPECIAL_TOKENS["<pad>"] | |
| START_OF_TEXT_TOKEN_ID = SPECIAL_TOKENS["<start_of_text>"] | |
| END_OF_TEXT_TOKEN_ID = SPECIAL_TOKENS["<end_of_text>"] | |
| START_OF_SPEECH_TOKEN_ID = SPECIAL_TOKENS["<start_of_speech>"] | |
| END_OF_SPEECH_TOKEN_ID = SPECIAL_TOKENS["<end_of_speech>"] | |
| SPK_0_TOKEN_ID = SPECIAL_TOKENS["<spk_0>"] | |
| SPK_1_TOKEN_ID = SPECIAL_TOKENS["<spk_1>"] | |
| # โโ Helper functions โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| def audio_token_id(code: int) -> int: | |
| """MioCodec code โ global token ID.""" | |
| return AUDIO_OFFSET + code | |
| def decode_audio_token(token_id: int) -> int: | |
| """Global token ID โ MioCodec code.""" | |
| return token_id - AUDIO_OFFSET | |
| def is_audio_token(token_id: int) -> bool: | |
| return AUDIO_OFFSET <= token_id < AUDIO_OFFSET + NUM_AUDIO_TOKENS | |
| def is_special_token(token_id: int) -> bool: | |
| return 0 <= token_id < NUM_SPECIAL_TOKENS | |
| def is_text_token(token_id: int) -> bool: | |
| return TEXT_OFFSET <= token_id < AUDIO_OFFSET | |
| # โโ V6 Model Config โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ | |
| # Encoder: 4 bidirectional layers | |
| ENC_D_MODEL = 384 | |
| ENC_N_HEADS = 6 | |
| ENC_N_LAYERS = 4 | |
| ENC_D_FF = 1536 | |
| # Decoder: 8 causal layers with cross-attention | |
| DEC_D_MODEL = 384 | |
| DEC_N_HEADS = 6 | |
| DEC_N_LAYERS = 8 | |
| DEC_D_FF = 1536 | |
| MAX_TEXT_LEN = 256 # Max text tokens (chars) โ covers ~17s speech | |
| MAX_AUDIO_LEN = 512 # Max audio tokens โ 512/25 = 20.5s | |
| DROPOUT = 0.0 | |