From 8b308e2913ee5a8feb8ae86eb429eaf5d31ba2ae Mon Sep 17 00:00:00 2001 From: b84330808 Date: Mon, 2 Nov 2026 19:00:55 +0900 Subject: [PATCH] Fix the end time of a time range being read as half past MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit replace_time checked the start time's minutes when deciding whether to read the end time as "半", so "8:30-12:15" became "八点半至十二点半" (the end time is spoken as 12:30) and "9:00-9:30" became "九点至九点三十分". Check minute_2 for the end time. Co-Authored-By: Claude Opus 5.5 --- .../text/zh_normalization/chronology.py | 2 +- test_zh_normalization.py | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test_zh_normalization.py diff --git a/GPT_SoVITS/text/zh_normalization/chronology.py b/GPT_SoVITS/text/zh_normalization/chronology.py index 2a6f66c2..74084c2a 100644 --- a/GPT_SoVITS/text/zh_normalization/chronology.py +++ b/GPT_SoVITS/text/zh_normalization/chronology.py @@ -78,7 +78,7 @@ def replace_time(match) -> str: result += "至" result += f"{num2str(hour_2)}点" if minute_2.lstrip("0"): - if int(minute) == 30: + if int(minute_2) == 30: result += "半" else: result += f"{_time_num2str(minute_2)}分" diff --git a/test_zh_normalization.py b/test_zh_normalization.py new file mode 100644 index 00000000..b8194016 --- /dev/null +++ b/test_zh_normalization.py @@ -0,0 +1,25 @@ +"""Regressions for 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.chronology import RE_TIME_RANGE, replace_time # noqa: E402 + + +def verbalize_time_range(text): + return RE_TIME_RANGE.sub(replace_time, text) + + +class TimeRangeTests(unittest.TestCase): + def test_end_time_minutes_are_read_from_end_time(self): + self.assertEqual(verbalize_time_range("8:30-12:15"), "八点半至十二点十五分") + self.assertEqual(verbalize_time_range("9:00-9:30"), "九点至九点半") + + def test_half_hour_on_both_ends(self): + self.assertEqual(verbalize_time_range("8:30~9:30"), "八点半至九点半") + + +if __name__ == "__main__": + unittest.main()