Back to Repositories

Testing Text Normalization Functions in Coqui-AI TTS

This test suite validates text cleaning functionality in the Coqui-AI TTS library, focusing on time, currency, and number format conversions. The tests ensure proper text normalization for speech synthesis applications.

Test Coverage Overview

The test suite provides comprehensive coverage of text cleaning operations essential for text-to-speech processing.

Key areas tested include:
  • Time format conversion (12/24 hour formats)
  • Currency expression handling (USD, GBP, JPY)
  • Numerical expression expansion
Edge cases covered include AM/PM handling, decimal points in currency, and negative numbers.

Implementation Analysis

The testing approach employs pytest’s assertion-based validation to verify text normalization functions. The implementation uses two main cleaner functions – english_cleaners and phoneme_cleaners – to process different text formats.

Each test function focuses on a specific transformation category, using multiple assertions to validate various input patterns.

Technical Details

Testing Tools & Configuration:
  • Python unittest framework
  • TTS.tts.utils.text.cleaners module
  • Custom cleaner functions: english_cleaners, phoneme_cleaners
  • Type hints for function signatures

Best Practices Demonstrated

The test suite exemplifies clean test design through focused test functions and clear naming conventions. Each test function handles a specific transformation category with multiple test cases.

Notable practices include:
  • Explicit type annotations
  • Isolated test cases
  • Comprehensive edge case coverage
  • Clear test function naming

coqui-ai/tts

tests/text_tests/test_text_cleaners.py

            
#!/usr/bin/env python3

from TTS.tts.utils.text.cleaners import english_cleaners, phoneme_cleaners


def test_time() -> None:
    assert english_cleaners("It's 11:00") == "it's eleven a m"
    assert english_cleaners("It's 9:01") == "it's nine oh one a m"
    assert english_cleaners("It's 16:00") == "it's four p m"
    assert english_cleaners("It's 00:00 am") == "it's twelve a m"


def test_currency() -> None:
    assert phoneme_cleaners("It's $10.50") == "It's ten dollars fifty cents"
    assert phoneme_cleaners("£1.1") == "one pound sterling one penny"
    assert phoneme_cleaners("¥1") == "one yen"


def test_expand_numbers() -> None:
    assert phoneme_cleaners("-1") == "minus one"
    assert phoneme_cleaners("1") == "one"