diff --git a/GPT_SoVITS/text/en_normalization/expend.py b/GPT_SoVITS/text/en_normalization/expend.py index 9f7c1d21..6bc87640 100644 --- a/GPT_SoVITS/text/en_normalization/expend.py +++ b/GPT_SoVITS/text/en_normalization/expend.py @@ -86,7 +86,10 @@ def _expand_time(m): """ hours, minutes = map(int, m.group(1, 2)) period = "a.m." if hours < 12 else "p.m." - if hours > 12: + # 00:00 is midnight. On a 12-hour clock that hour is twelve, not zero. + if hours == 0: + hours = 12 + elif hours > 12: hours -= 12 hour_word = _inflect.number_to_words(hours) diff --git a/GPT_SoVITS/text/en_normalization/test_expend.py b/GPT_SoVITS/text/en_normalization/test_expend.py new file mode 100644 index 00000000..299d7dd5 --- /dev/null +++ b/GPT_SoVITS/text/en_normalization/test_expend.py @@ -0,0 +1,22 @@ +import os +import sys +import unittest + +sys.path.insert(0, os.path.dirname(__file__)) +from expend import normalize + + +class TimeTests(unittest.TestCase): + def test_midnight_is_twelve_am(self): + self.assertEqual(normalize("0:00"), "twelve o'clock a.m.") + self.assertEqual(normalize("00:30"), "twelve thirty a.m.") + + def test_noon_and_afternoon_stay(self): + self.assertEqual(normalize("12:00"), "twelve o'clock p.m.") + self.assertEqual(normalize("4:00"), "four o'clock a.m.") + self.assertEqual(normalize("13:00"), "one o'clock p.m.") + self.assertEqual(normalize("13:30"), "one thirty p.m.") + + +if __name__ == "__main__": + unittest.main()