Download code/tests/test_text.py from hello-test1/PhotonTTS: direct link, hf CLI and curl.
- Browser
- Download file 839 Bytes
-
https://huggingface.co/hello-test1/PhotonTTS/resolve/main/code/tests/test_text.py
- Command line
-
hf download hf://hello-test1/PhotonTTS/code/tests/test_text.py
-
curl -L -o test_text.py https://huggingface.co/hello-test1/PhotonTTS/resolve/main/code/tests/test_text.py
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 | |