File size: 839 Bytes
7e2301f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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