"""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 = { "": 0, "": 1, "": 2, "": 3, "": 4, "": 5, # reserved vocabulary ID "": 6, "": 7, "": 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[""] START_OF_TEXT_TOKEN_ID = SPECIAL_TOKENS[""] END_OF_TEXT_TOKEN_ID = SPECIAL_TOKENS[""] START_OF_SPEECH_TOKEN_ID = SPECIAL_TOKENS[""] END_OF_SPEECH_TOKEN_ID = SPECIAL_TOKENS[""] SPK_0_TOKEN_ID = SPECIAL_TOKENS[""] SPK_1_TOKEN_ID = SPECIAL_TOKENS[""] # ── 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