import re

from mon_nlp import abbreviation, emoji, g2p, num2words, punctuation


def preprocess_for_tts(text: str) -> str:
    """Normalize text for TTS synthesis."""
    # Step 1: Expand abbreviations
    text = abbreviation.expand(text)

    # Step 2: Convert emojis to words
    text = emoji.emoji_to_words(text)

    # Step 3: Normalize punctuation
    text = punctuation.normalize(text)

    norm_text = []
    for word in text.split():
        if bool(re.fullmatch(r"-?\d*\.?\d+", word)):
            number = float(word) if "." in word else int(word)
            norm_text.append(num2words(number))
        else:
            norm_text.append(word)

    # Step 4: Generate phonemes
    phonemes = g2p.convert(" ".join(norm_text))

    return phonemes


# Example usage
raw = "МУ 2026 оны төлөвлөгөө"
result = preprocess_for_tts(raw)
print(result)
