File size: 536 Bytes
0c723b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Chinese pinyin character-level symbol set."""

_pad = "_"

# All possible pinyin characters (a-z) plus tone digits (1-5)
_pinyin_chars = "abcdefghijklmnopqrstuvwxyz12345 "

# Chinese punctuation
_punct = ",。!?;:、…—""''()《》·"

symbols = [_pad] + list(_pinyin_chars) + list(_punct)

_symbol_to_id = {s: i for i, s in enumerate(symbols)}

PAD_ID = 0
SPACE_ID = _symbol_to_id.get(" ", len(symbols))


def get_phoneme_ids(phonemes: str) -> list[int]:
    return [_symbol_to_id.get(p, PAD_ID) for p in phonemes]