PhotonTTS / code /tests /test_text.py
hello-test1's picture
sync code
7e2301f verified
Raw History Blame Contribute Delete
839 Bytes
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 = "<mode:speech><lang:en>Hello <laugh> world! 你好"
ids = tok.encode(text)
assert tok.id("<laugh>") in ids
assert tok.id("<mode:speech>") == 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 <notatag> b")
assert all(i < 256 for i in ids)
def test_ctc_targets_strip_tags():
assert strip_tags("[S1] Hi <breath> there") == "Hi there"
t = ctc_targets("[S1] Hi <breath> there")
assert t == [b + 1 for b in b"Hi there"]
assert max(ctc_targets("你好")) < CTC_VOCAB