Luigi commited on
Commit
a23b34d
·
verified ·
1 Parent(s): e9d7e0d

frontend: emit ㄭ for empty-rime syllables

Browse files
Files changed (1) hide show
  1. scripts/frontend_bopomofo.py +11 -1
scripts/frontend_bopomofo.py CHANGED
@@ -14,7 +14,11 @@ ARPABET = ['AA','AE','AH','AO','AW','AY','B','CH','D','DH','EH','ER','EY','F','G
14
  'UH','UW','V','W','Y','Z','ZH']
15
  PUNCT = [',', '.', '?', '!', '…', '-', "'"]
16
  SPECIAL = ['_blank', '_pad', 'UNK', 'SP'] # SP = inter-word/space pause
17
- SYMBOLS = SPECIAL + ZHUYIN + ARPABET + PUNCT
 
 
 
 
18
  SYM2ID = {s: i for i, s in enumerate(SYMBOLS)}
19
  LANG = {'ZH': 0, 'EN': 1} # per-phone language id
20
 
@@ -34,6 +38,12 @@ def _split_syllable(syl: str):
34
  if syl and syl[-1].isdigit():
35
  tone = int(syl[-1]); syl = syl[:-1]
36
  units = [c for c in syl if c in SYM2ID]
 
 
 
 
 
 
37
  return units, tone
38
 
39
  def text_to_phones(text: str):
 
14
  'UH','UW','V','W','Y','Z','ZH']
15
  PUNCT = [',', '.', '?', '!', '…', '-', "'"]
16
  SPECIAL = ['_blank', '_pad', 'UNK', 'SP'] # SP = inter-word/space pause
17
+ # = syllabic-vowel symbol for empty-rime syllables (是/十/日/司...). U+312D is outside the
18
+ # U+3105..U+3129 ZHUYIN range so it was missing. APPENDED AT END to preserve all existing phone ids
19
+ # (warm-start compatibility); new id, embedding row trained during the re-align retrain.
20
+ SYLLABIC = ['ㄭ']
21
+ SYMBOLS = SPECIAL + ZHUYIN + ARPABET + PUNCT + SYLLABIC
22
  SYM2ID = {s: i for i, s in enumerate(SYMBOLS)}
23
  LANG = {'ZH': 0, 'EN': 1} # per-phone language id
24
 
 
38
  if syl and syl[-1].isdigit():
39
  tone = int(syl[-1]); syl = syl[:-1]
40
  units = [c for c in syl if c in SYM2ID]
41
+ # Empty-rime syllables (zhi/chi/shi/ri/zi/ci/si: 是/十/日/司/思/資...) are written in bopomofo as
42
+ # the bare retroflex/dental sibilant with an IMPLICIT syllabic vowel. Without an explicit vowel
43
+ # phone the model renders a clipped fricative that merges into the next syllable. Append the
44
+ # syllabic-vowel symbol ㄭ so these carry a proper rime. (Requires training data with ㄭ.)
45
+ if len(units) == 1 and units[0] in "ㄓㄔㄕㄖㄗㄘㄙ" and "ㄭ" in SYM2ID:
46
+ units = [units[0], "ㄭ"]
47
  return units, tone
48
 
49
  def text_to_phones(text: str):