fix(norm): wrong type check to function (fix #423) (#428)

This commit is contained in:
源文雨
2024-06-24 22:24:50 +09:00
committed by GitHub
parent f4121844e6
commit 25b6023493
4 changed files with 21 additions and 4 deletions
+7 -2
View File
@@ -155,8 +155,13 @@ class Normalizer:
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
+6 -2
View File
@@ -72,12 +72,14 @@
},
"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",
@@ -85,6 +87,8 @@
" )\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",
+4
View File
@@ -59,6 +59,8 @@
"# 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",
@@ -66,6 +68,8 @@
" )\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",
+4
View File
@@ -49,6 +49,8 @@ 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(
@@ -56,6 +58,8 @@ def load_chat(cust_path: Optional[str], coef: Optional[str]) -> bool:
)
try:
chat.normalizer.register("zh", normalizer_zh_tn())
except ValueError as e:
logger.error(e)
except:
logger.warning('Package WeTextProcessing not found!')
logger.warning(