From 49fa9b9c58a839e044700493a6ad4fb5bc2c3f46 Mon Sep 17 00:00:00 2001 From: Andrew Lowe Date: Mon, 6 Jan 2025 05:04:55 -0800 Subject: [PATCH] fix: convert >35 digit English numbers digit-by-digit (#240) --- TTS/tts/utils/text/english/number_norm.py | 6 +++++- tests/text_tests/test_text_cleaners.py | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/TTS/tts/utils/text/english/number_norm.py b/TTS/tts/utils/text/english/number_norm.py index e8377ede87..c912e285e4 100644 --- a/TTS/tts/utils/text/english/number_norm.py +++ b/TTS/tts/utils/text/english/number_norm.py @@ -85,7 +85,11 @@ def _expand_number(m): if num % 100 == 0: return _inflect.number_to_words(num // 100) + " hundred" return _inflect.number_to_words(num, andword="", zero="oh", group=2).replace(", ", " ") - return _inflect.number_to_words(num, andword="") + try: + text = _inflect.number_to_words(num, andword="") + except inflect.NumOutOfRangeError: + text = _inflect.number_to_words(num, group=1).replace(", ", " ") + return text def normalize_numbers(text): diff --git a/tests/text_tests/test_text_cleaners.py b/tests/text_tests/test_text_cleaners.py index 9be1f0bf41..25c169eddd 100644 --- a/tests/text_tests/test_text_cleaners.py +++ b/tests/text_tests/test_text_cleaners.py @@ -24,6 +24,8 @@ def test_currency() -> None: def test_expand_numbers() -> None: assert phoneme_cleaners("-1") == "minus one" assert phoneme_cleaners("1") == "one" + assert phoneme_cleaners("1" + "0" * 35) == "one hundred decillion" + assert phoneme_cleaners("1" + "0" * 36) == "one" + " zero" * 36 def test_multilingual_phoneme_cleaners() -> None: