diff --git a/ChatTTS/norm.py b/ChatTTS/norm.py index 08e710e03..f47cb1238 100644 --- a/ChatTTS/norm.py +++ b/ChatTTS/norm.py @@ -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 diff --git a/examples/ipynb/colab.ipynb b/examples/ipynb/colab.ipynb index 6e604c5b8..0ef9f581c 100644 --- a/examples/ipynb/colab.ipynb +++ b/examples/ipynb/colab.ipynb @@ -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", diff --git a/examples/ipynb/example.ipynb b/examples/ipynb/example.ipynb index 6eb3cd172..e4075d070 100644 --- a/examples/ipynb/example.ipynb +++ b/examples/ipynb/example.ipynb @@ -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", diff --git a/examples/web/funcs.py b/examples/web/funcs.py index 5d00761db..922835aa5 100644 --- a/examples/web/funcs.py +++ b/examples/web/funcs.py @@ -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(