Repository navigation
Commit ea63ac3
authored
Fixes #983.
## Problem
`MandarinErhua.merge` folded every syllable whose pinyin base is `er`
into the syllable before it. 二 / 而 / 耳 / 尔 share that pinyin with 儿, so
after another syllable they were swallowed, and 儿 meaning "child" (女儿,
他儿子) lost its `ér`. Digits were affected as well, because
`MandarinNumberNormalizer` turns `12` into `十二` before G2P.
## Fix
- `Segment.pinyin` carries the Hanzi it was read from (`word:` replaces
the unused `hanziCount:`).
- `MandarinPinyinNormalizer.Syllable` gains `isErhuaSuffix` (defaults to
`false`; the initializer stays source-compatible).
- `MandarinG2P` sets the flag on a word's last syllable when
`MandarinErhua.isSuffix(word:preceding:)` agrees, following misaki's
`_merge_erhua`:
- the character is 儿 or 兒;
- it ends its word, or the segmenter split it off as a one-character
word (这 | 儿 when 这儿 isn't a phrase), in which case it folds into the
Hanzi before it in the buffer;
- misaki's `not_erhua` / `must_erhua` word lists allow it (ported from
`ZHFrontend`).
- `MandarinErhua.merge` only folds flagged syllables.
Not ported: misaki's POS gate (`a` / `j` / `nr`), since this pipeline
has no POS tags.
One behavior change outside the bug: user-lexicon `.syllables` tokens
are taken literally, so an `er` written in a lexicon entry no longer
folds. Erhua can still be written there with `@` bopomofo.
## Before / after
Real `ANE-zh` assets, phonemes printed by `fluidaudiocli tts … --backend
kokoro-ane --variant zh` (debug build):
| Input | Before | After |
|---|---|---|
| 相隔二千里 | `ㄒ阳1ㄍㄜㄦ2ㄑ言1ㄌㄧ3` | `ㄒ阳1ㄍㄜ2ㄦ4ㄑ言1ㄌㄧ3` |
| 别了二十年 | `ㄅㄝ2ㄌㄜㄦ5ㄕ十2ㄋ言2` | `ㄅㄝ2ㄌㄜ5ㄦ4ㄕ十2ㄋ言2` |
| 第十二回 | `ㄉㄧ4ㄕ十ㄦ2ㄏ为2` | `ㄉㄧ4ㄕ十2ㄦ4ㄏ为2` |
| 第12回 | `ㄉㄧ4ㄕ十ㄦ2ㄏ为2` | `ㄉㄧ4ㄕ十2ㄦ4ㄏ为2` |
| 偶尔 | `ㄡㄦ3` | `ㄡ2ㄦ3` |
| 然而他 | `ㄖㄢㄦ2ㄊㄚ1` | `ㄖㄢ2ㄦ2ㄊㄚ1` |
| 木耳 | `ㄇㄨㄦ4` | `ㄇㄨ4ㄦ3` |
| 女儿 | `ㄋㄩㄦ3` | `ㄋㄩ3ㄦ2` |
| 他儿子 | `ㄊㄚㄦ1ㄗㄭ5` | `ㄊㄚ1ㄦ2ㄗㄭ5` |
| 这儿 | `ㄓㄜㄦ4` | `ㄓㄜㄦ4` (unchanged) |
| 小孩儿 | `ㄒ要3ㄏㄞㄦ2` | `ㄒ要3ㄏㄞㄦ2` (unchanged) |
| 一会儿 | `ㄧ2ㄏ为ㄦ4` | `ㄧ2ㄏ为ㄦ4` (unchanged) |
| 哪儿 | `ㄋㄚㄦ3` | `ㄋㄚㄦ3` (unchanged) |
| 玩儿 | `万ㄦ2` | `万ㄦ2` (unchanged) |
## Tests
- `MandarinErhuaTests`: the merge primitives now set `isErhuaSuffix`.
Added cases for unflagged `er` (十二), `isSuffix` (other `er` characters,
word-initial 儿, standalone 儿 with and without preceding Hanzi,
`not_erhua` / `must_erhua`, traditional 兒), and end-to-end runs through
`MandarinG2P` (十二, 相隔二千, 然而 / 偶尔 / 木耳, 女儿 as a phrase and split, 他儿子,
phrase-final 小孩儿).
- `swift test --filter
'MandarinErhuaTests|MandarinG2PTests|MandarinCustomLexiconTests|MandarinNumberNormalizerTests'`:
105 tests, 0 failures.
- `swift format lint` is clean on the changed files.
1 parent 04e363c commit ea63ac3
4 files changed
Lines changed: 233 additions & 38 deletions
File tree
- Sources/FluidAudio/TTS/KokoroAne/G2P/Mandarin
- Tests/FluidAudioTests/TTS/KokoroAne
Lines changed: 59 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
18 | 24 | | |
19 | 25 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
30 | | - | |
31 | | - | |
| 36 | + | |
| 37 | + | |
32 | 38 | | |
33 | 39 | | |
34 | 40 | | |
| |||
40 | 46 | | |
41 | 47 | | |
42 | 48 | | |
43 | | - | |
| 49 | + | |
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| |||
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
56 | 89 | | |
57 | 90 | | |
58 | 91 | | |
59 | 92 | | |
60 | 93 | | |
61 | 94 | | |
62 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
63 | 113 | | |
Lines changed: 33 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
118 | 119 | | |
119 | 120 | | |
120 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
121 | 125 | | |
122 | 126 | | |
| 127 | + | |
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
| |||
141 | 146 | | |
142 | 147 | | |
143 | 148 | | |
144 | | - | |
145 | | - | |
146 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
147 | 159 | | |
| 160 | + | |
| 161 | + | |
148 | 162 | | |
149 | 163 | | |
150 | 164 | | |
151 | 165 | | |
152 | 166 | | |
153 | | - | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
154 | 171 | | |
| 172 | + | |
155 | 173 | | |
156 | 174 | | |
157 | 175 | | |
| |||
204 | 222 | | |
205 | 223 | | |
206 | 224 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
213 | 231 | | |
214 | 232 | | |
215 | 233 | | |
| |||
271 | 289 | | |
272 | 290 | | |
273 | 291 | | |
274 | | - | |
| 292 | + | |
275 | 293 | | |
276 | 294 | | |
277 | 295 | | |
| |||
289 | 307 | | |
290 | 308 | | |
291 | 309 | | |
292 | | - | |
| 310 | + | |
293 | 311 | | |
294 | 312 | | |
295 | 313 | | |
| |||
342 | 360 | | |
343 | 361 | | |
344 | 362 | | |
345 | | - | |
| 363 | + | |
346 | 364 | | |
347 | 365 | | |
348 | 366 | | |
| |||
Lines changed: 8 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
25 | 31 | | |
26 | | - | |
| 32 | + | |
27 | 33 | | |
28 | 34 | | |
29 | 35 | | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
0 commit comments