Skip to content

Commit

Permalink
fix: homophones replacer (#386)
Browse files Browse the repository at this point in the history
and improve output clarity

- 原代码在应用字符映射后错误地使用了变量t而不是text[i],会导致前一步 apply_character_map 的结果被覆盖。现已更正此问题。
- 同音字替换的输出已改进为仅显示替换的字符,使结果更简洁。
  • Loading branch information
6drf21e authored Jun 21, 2024
1 parent ace4d0c commit 56227f4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
7 changes: 4 additions & 3 deletions ChatTTS/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ def _infer(
self.logger.log(logging.WARNING, f'Invalid characters found! : {invalid_characters}')
text[i] = apply_character_map(t)
if do_homophone_replacement and self.init_homophones_replacer():
text[i] = self.homophones_replacer.replace(t)
if t != text[i]:
self.logger.log(logging.INFO, f'Homophones replace: {t} -> {text[i]}')
text[i], replaced_words = self.homophones_replacer.replace(text[i])
if replaced_words:
repl_res = ', '.join([f'{_[0]}->{_[1]}' for _ in replaced_words])
self.logger.log(logging.INFO, f'Homophones replace: {repl_res}')

if not skip_refine_text:
text_tokens = refine_text(
Expand Down
7 changes: 5 additions & 2 deletions ChatTTS/utils/infer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ def load_homophones_map(self, map_file_path):

def replace(self, text):
result = []
replaced_words = []
for char in text:
if char in self.homophones_map:
result.append(self.homophones_map[char])
repl_char = self.homophones_map[char]
result.append(repl_char)
replaced_words.append((char, repl_char))
else:
result.append(char)
return ''.join(result)
return ''.join(result), replaced_words

def count_invalid_characters(s):

Expand Down

0 comments on commit 56227f4

Please sign in to comment.