"""
Practice: evaluating text-to-speech output.

Fill in the four TODOs, then run the tests:
    pytest test_tts_practice.py        (locally)
or press "Run tests" on the chapter page.
"""

DIGIT_WORDS = {"zero": "0", "oh": "0", "one": "1", "two": "2", "three": "3", "four": "4",
               "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}


def blame(errors_rec1: set[str], errors_rec2: set[str]) -> dict[str, set[str]]:
    """Round-trip WER with two recognizers. Each set holds the words a recognizer got wrong.

    Return {"voice": ..., "recognizer": ...}:
      - an error BOTH recognizers make was probably in the audio      -> "voice"
      - an error only ONE makes was probably that recognizer's         -> "recognizer"

    TODO 1
    """
    return {"voice": set(), "recognizer": set()}


def reading_ok(heard: str, accepted: list[str]) -> bool:
    """Did the voice say what the text meant? `heard` is a transcript of the audio; `accepted`
    lists the readings a listener would accept.

    Compare after lowercasing, turning hyphens into spaces, and deleting other punctuation
    ("p.m." -> "pm"). Recognizers write some
    readings back in written form, so a run of digits in `heard` ("4471") must also match a
    spelled-out accepted reading ("four four seven one"): convert spelled digits to digits on
    both sides before comparing.

    TODO 2
    """
    return False


def leading_silence(samples: list[float], sample_rate: int, threshold: float = 0.02) -> float:
    """Seconds of silence before the first sample louder than `threshold` (absolute value).
    If nothing is louder, the whole clip is silence.

    TODO 3
    """
    return 0.0


def time_to_first_speech(ttfb_s: float, samples: list[float], sample_rate: int) -> float:
    """What the listener actually waits for: time to first byte + leading silence in the audio.

    TODO 4
    """
    return 0.0
