Skip to content

Commit

Permalink
fix(norm): wrong type check to function (fix #423) (#428)
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama authored Jun 24, 2024
1 parent f412184 commit 25b6023
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions ChatTTS/norm.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,13 @@ def register(self, name: str, normalizer: Callable[[str], str]) -> bool:
if name in self.normalizers:
self.logger.warning(f"name {name} has been registered")
return False
if not isinstance(normalizer, Callable[[str], str]):
self.logger.warning("normalizer must have caller type (str) -> str")
try:
val = normalizer("test string 测试字符串")
if not isinstance(val, str):
self.logger.warning("normalizer must have caller type (str) -> str")
return False
except Exception as e:
self.logger.warning(e)
return False
self.normalizers[name] = normalizer
return True
Expand Down
8 changes: 6 additions & 2 deletions examples/ipynb/colab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,23 @@
},
"outputs": [],
"source": [
"logger = get_logger(\"ChatTTS\")\n",
"chat = ChatTTS.Chat(logger, remove_exist=True)\n",
"logger = get_logger(\"ChatTTS\", remove_exist=True)\n",
"chat = ChatTTS.Chat(logger)\n",
"\n",
"# try to load normalizer\n",
"try:\n",
" chat.normalizer.register(\"en\", normalizer_en_nemo_text())\n",
"except ValueError as e:\n",
" logger.error(e)\n",
"except:\n",
" logger.warning('Package nemo_text_processing not found!')\n",
" logger.warning(\n",
" 'Run: conda install -c conda-forge pynini=2.1.5 && pip install nemo_text_processing',\n",
" )\n",
"try:\n",
" chat.normalizer.register(\"zh\", normalizer_zh_tn())\n",
"except ValueError as e:\n",
" logger.error(e)\n",
"except:\n",
" logger.warning('Package WeTextProcessing not found!')\n",
" logger.warning(\n",
Expand Down
4 changes: 4 additions & 0 deletions examples/ipynb/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,17 @@
"# try to load normalizer\n",
"try:\n",
" chat.normalizer.register(\"en\", normalizer_en_nemo_text())\n",
"except ValueError as e:\n",
" logger.error(e)\n",
"except:\n",
" logger.warning('Package nemo_text_processing not found!')\n",
" logger.warning(\n",
" 'Run: conda install -c conda-forge pynini=2.1.5 && pip install nemo_text_processing',\n",
" )\n",
"try:\n",
" chat.normalizer.register(\"zh\", normalizer_zh_tn())\n",
"except ValueError as e:\n",
" logger.error(e)\n",
"except:\n",
" logger.warning('Package WeTextProcessing not found!')\n",
" logger.warning(\n",
Expand Down
4 changes: 4 additions & 0 deletions examples/web/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,17 @@ def load_chat(cust_path: Optional[str], coef: Optional[str]) -> bool:
if ret:
try:
chat.normalizer.register("en", normalizer_en_nemo_text())
except ValueError as e:
logger.error(e)
except:
logger.warning('Package nemo_text_processing not found!')
logger.warning(
'Run: conda install -c conda-forge pynini=2.1.5 && pip install nemo_text_processing',
)
try:
chat.normalizer.register("zh", normalizer_zh_tn())
except ValueError as e:
logger.error(e)
except:
logger.warning('Package WeTextProcessing not found!')
logger.warning(
Expand Down

0 comments on commit 25b6023

Please sign in to comment.