Files
abogen/tests/test_text_normalization.py
T
JB be37f03109 Add number normalization and enhance UI for voice preview
- Implemented number conversion to words for grouped numbers in text normalization.
- Added configuration options for number conversion in ApostropheConfig.
- Updated the normalize_apostrophes function to include number normalization.
- Enhanced the dashboard UI with new sections for manuscript and narrator defaults.
- Improved voice preview functionality with better handling of audio playback and status updates.
- Refactored HTML templates for cleaner structure and added new fields for speaker settings.
- Updated CSS styles for improved layout and responsiveness.
- Added tests to ensure correct spelling of grouped numbers in the normalization process.
- Included num2words as a new dependency in pyproject.toml.
2025-10-10 16:12:51 -07:00

71 lines
2.5 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from __future__ import annotations
from abogen.kokoro_text_normalization import normalize_roman_numeral_titles
from abogen.web.conversion_runner import _normalize_for_pipeline
def test_title_abbreviations_are_expanded():
text = "Dr. Watson met Mr. Holmes and Ms. Hudson."
normalized = _normalize_for_pipeline(text)
assert "Doctor" in normalized
assert "Mister" in normalized
assert "Miz" in normalized
def test_suffix_abbreviations_are_expanded_with_case_preserved():
text = "John Doe Jr. spoke to JANE DOE SR. about the estate."
normalized = _normalize_for_pipeline(text)
assert "John Doe Junior" in normalized
assert "JANE DOE SENIOR" in normalized
def test_missing_terminal_punctuation_is_added():
normalized = _normalize_for_pipeline("Chapter 1")
assert normalized.endswith(".")
def test_terminal_punctuation_respects_closing_quotes():
normalized = _normalize_for_pipeline('"Chapter 1"')
compact = normalized.replace(" ", "")
assert compact.endswith('."')
def test_normalization_preserves_spacing_around_quotes_and_hyphen():
sample = "“Still,” said Château-Renaud, “Dr. dAvrigny, who attends my mother, declares he is in despair about it."
normalized = _normalize_for_pipeline(sample)
assert normalized.startswith(
"“Still,” said Château-Renaud, “Doctor d'Avrigny, who attends my mother, declares he is in despair about it."
)
assert " " not in normalized
assert "Château-Renaud" in normalized
assert "Doctor d'Avrigny" in normalized
def test_normalize_roman_titles_converts_when_majority() -> None:
titles = ["I: Opening", "II: Rising Action", "III: Climax"]
normalized = normalize_roman_numeral_titles(titles)
assert normalized == ["1: Opening", "2: Rising Action", "3: Climax"]
def test_normalize_roman_titles_skips_when_not_majority() -> None:
titles = ["Preface", "I: Opening", "Acknowledgements"]
normalized = normalize_roman_numeral_titles(titles)
assert normalized == titles
def test_normalize_roman_titles_preserves_separators() -> None:
titles = [" IV. The Trial", "V - The Verdict", "VI\nAftermath"]
normalized = normalize_roman_numeral_titles(titles)
assert normalized[0] == " 4. The Trial"
assert normalized[1] == "5 - The Verdict"
assert normalized[2].startswith("6\nAftermath")
def test_grouped_numbers_are_spelled_out() -> None:
normalized = _normalize_for_pipeline("The vault holds 35,000 credits")
assert "thirty-five thousand" in normalized.lower()