Skip to content

Commit 56227f4

Browse files
authored
fix: homophones replacer (#386)
and improve output clarity - 原代码在应用字符映射后错误地使用了变量t而不是text[i],会导致前一步 apply_character_map 的结果被覆盖。现已更正此问题。 - 同音字替换的输出已改进为仅显示替换的字符,使结果更简洁。
1 parent ace4d0c commit 56227f4

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

ChatTTS/core.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,10 @@ def _infer(
179179
self.logger.log(logging.WARNING, f'Invalid characters found! : {invalid_characters}')
180180
text[i] = apply_character_map(t)
181181
if do_homophone_replacement and self.init_homophones_replacer():
182-
text[i] = self.homophones_replacer.replace(t)
183-
if t != text[i]:
184-
self.logger.log(logging.INFO, f'Homophones replace: {t} -> {text[i]}')
182+
text[i], replaced_words = self.homophones_replacer.replace(text[i])
183+
if replaced_words:
184+
repl_res = ', '.join([f'{_[0]}->{_[1]}' for _ in replaced_words])
185+
self.logger.log(logging.INFO, f'Homophones replace: {repl_res}')
185186

186187
if not skip_refine_text:
187188
text_tokens = refine_text(

ChatTTS/utils/infer_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,15 @@ def load_homophones_map(self, map_file_path):
7676

7777
def replace(self, text):
7878
result = []
79+
replaced_words = []
7980
for char in text:
8081
if char in self.homophones_map:
81-
result.append(self.homophones_map[char])
82+
repl_char = self.homophones_map[char]
83+
result.append(repl_char)
84+
replaced_words.append((char, repl_char))
8285
else:
8386
result.append(char)
84-
return ''.join(result)
87+
return ''.join(result), replaced_words
8588

8689
def count_invalid_characters(s):
8790

0 commit comments

Comments
 (0)