import torch from photontts.text.tags import strip_tags from photontts.text.tokenizer import CTC_VOCAB, ByteTokenizer, ctc_targets def test_byte_tokenizer_roundtrip_with_tags(): tok = ByteTokenizer() text = "Hello world! 你好" ids = tok.encode(text) assert tok.id("") in ids assert tok.id("") == ids[0] assert tok.decode(ids) == text assert max(ids) < tok.vocab_size def test_unknown_angle_text_is_plain_bytes(): tok = ByteTokenizer() ids = tok.encode("a b") assert all(i < 256 for i in ids) def test_ctc_targets_strip_tags(): assert strip_tags("[S1] Hi there") == "Hi there" t = ctc_targets("[S1] Hi there") assert t == [b + 1 for b in b"Hi there"] assert max(ctc_targets("你好")) < CTC_VOCAB