Merge ad0e0e758fb4b8418c6bd2792eb37ae5c4cb2e73 into 6d51ffceafbf240145619af4c92408a6e54b7924

This commit is contained in:
Wei-Lun Li 2026-11-16 17:06:39 +00:00 committed by GitHub
commit 592adc8cfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -75,7 +75,8 @@ def replace_percentage(match) -> str:
# 整数表达式
# 带负号的整数 -10
RE_INTEGER = re.compile(r"(-)" r"(\d+)")
# 不匹配负小数(如 -1.5)的整数部分
RE_INTEGER = re.compile(r"(-)" r"(\d+)" r"(?!\.?\d)")
def replace_negative_num(match) -> str:

View File

@ -0,0 +1,26 @@
"""Regressions for reading numbers in Chinese text normalization, without loading any model."""
import sys
import unittest
from pathlib import Path
sys.path[:0] = [str(Path(__file__).resolve().parent / "GPT_SoVITS")]
from text.zh_normalization.text_normlization import TextNormalizer # noqa: E402
class NegativeNumberTests(unittest.TestCase):
def setUp(self):
self.normalizer = TextNormalizer()
def test_negative_decimals(self):
self.assertEqual(self.normalizer.normalize_sentence("-1.5"), "负一点五")
self.assertEqual(self.normalizer.normalize_sentence("-0.5"), "负零点五")
self.assertEqual(self.normalizer.normalize_sentence("余额为-3.75元"), "余额为负三点七五元")
def test_negative_integers(self):
self.assertEqual(self.normalizer.normalize_sentence("-10"), "负十")
self.assertEqual(self.normalizer.normalize_sentence("温度是-1。"), "温度是负一。")
if __name__ == "__main__":
unittest.main()