Fix the end time of a time range being read as half past

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 <noreply@anthropic.com>
This commit is contained in:
b84330808 2026-11-02 19:00:55 +09:00
parent 04a44eb977
commit 8b308e2913
2 changed files with 26 additions and 1 deletions

View File

@ -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)}分"

25
test_zh_normalization.py Normal file
View File

@ -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()