From f5baf394e3778f20f7fccf7fff8549d7043a3fa8 Mon Sep 17 00:00:00 2001 From: Prateek Chaplot Date: Fri, 20 Nov 2026 18:11:07 +0530 Subject: [PATCH 1/2] feat(timing): reconcile phoneme alignments into word timings Map each sentence's per-phoneme sample counts to word-level timings with difflib matching, honest unaligned entries, and a 60% sentence collapse threshold. --- src/tts/timing/__init__.py | 1 + src/tts/timing/reconcile.py | 220 ++++++++++++++++ tests/unit/test_timing_reconcile.py | 386 ++++++++++++++++++++++++++++ 3 files changed, 607 insertions(+) create mode 100644 src/tts/timing/__init__.py create mode 100644 src/tts/timing/reconcile.py create mode 100644 tests/unit/test_timing_reconcile.py diff --git a/src/tts/timing/__init__.py b/src/tts/timing/__init__.py new file mode 100644 index 0000000..fe1ba11 --- /dev/null +++ b/src/tts/timing/__init__.py @@ -0,0 +1 @@ +"""Timing: phoneme alignments to honest word-level timings.""" diff --git a/src/tts/timing/reconcile.py b/src/tts/timing/reconcile.py new file mode 100644 index 0000000..71b0f60 --- /dev/null +++ b/src/tts/timing/reconcile.py @@ -0,0 +1,220 @@ +"""Convert per-phoneme sample counts into honest word-level timings.""" + +from __future__ import annotations + +import difflib +import logging +import math +import re +from typing import TYPE_CHECKING + +from tts.types import SentenceAudio, SynthesisResult, WordTiming + +if TYPE_CHECKING: + from tts.voices.store import LoadedVoice + +logger = logging.getLogger(__name__) + +# A word token is a run of non-whitespace; punctuation and emoji stay attached +# to the tokens they belong to so subtitle text matches the input exactly. +_WORD_PATTERN = re.compile(r"\S+") + +# Piper's BOS/EOS/pad markers and espeak's word separator never correspond to +# spoken text; dropping the separator keeps number expansions ("42" becomes two +# espeak words) matchable as one contiguous run. +_SKIPPED_PHONEMES = frozenset({"^", "$", "_", " "}) + +# A sentence whose words cannot be mapped below this share of its tokens is +# collapsed to one unaligned entry instead of showing a drifting highlight. +MIN_SENTENCE_ALIGNMENT_RATIO = 0.6 + +# Share of a word's phonemes that must match the sentence's alignment run +# before the word counts as aligned. +MIN_WORD_MATCH_RATIO = 0.6 + + +def split_words(text: str) -> list[str]: + """Split text into word tokens using the same rule as the reconciler.""" + return _WORD_PATTERN.findall(text) + + +def derive_word_timings( + voice: LoadedVoice, result: SynthesisResult +) -> tuple[list[WordTiming], float]: + """Map phoneme sample counts to word timings in milliseconds. + + Returned timings are ordered, monotonic, and confined to their sentence's + audio span. Words that cannot be placed honestly are emitted with + ``aligned=False`` and a zero-width span after the previous word; a sentence + whose words cannot be mapped below ``MIN_SENTENCE_ALIGNMENT_RATIO`` + collapses to one unaligned entry spanning that sentence. The second value + is the aligned word ratio in ``[0, 1]``, or ``-1.0`` when the whole + synthesis ran without alignments. + """ + if not result.sentences: + return [], -1.0 + + timings: list[WordTiming] = [] + aligned_words = 0 + total_words = 0 + previous_end_ms = 0 + elapsed_ms = 0.0 + + for sentence in result.sentences: + words = split_words(sentence.text) + total_words += len(words) + + duration_ms = _duration_ms(sentence) + sentence_start_ms = _round_ms(elapsed_ms) + elapsed_ms += duration_ms + sentence_end_ms = _round_ms(elapsed_ms) + + sentence_timings: list[WordTiming] + sentence_aligned: int + if result.supports_alignments: + sentence_timings, sentence_aligned = _sentence_timings( + voice, sentence, sentence_start_ms, sentence_end_ms, words + ) + else: + # The engine reported degraded output: never fabricate placements. + sentence_timings, sentence_aligned = [], 0 + ratio = sentence_aligned / len(words) if words else 1.0 + if not words or ratio < MIN_SENTENCE_ALIGNMENT_RATIO: + sentence_timings = [ + _collapsed_sentence_timing(sentence, sentence_start_ms, sentence_end_ms) + ] + sentence_aligned = 0 + + for timing in sentence_timings: + start_ms = max(timing.start_ms, previous_end_ms) + end_ms = max(timing.end_ms, start_ms) + timings.append( + WordTiming( + text=timing.text, + start_ms=start_ms, + end_ms=end_ms, + aligned=timing.aligned, + ) + ) + previous_end_ms = end_ms + aligned_words += sentence_aligned + + if not result.supports_alignments: + aligned_ratio = -1.0 + elif total_words == 0: + aligned_ratio = 0.0 + else: + aligned_ratio = aligned_words / total_words + + logger.debug( + "Reconciled %d/%d words across %d sentences (ratio %.3f)", + aligned_words, + total_words, + len(result.sentences), + aligned_ratio, + ) + return timings, aligned_ratio + + +def _duration_ms(sentence: SentenceAudio) -> float: + if sentence.sample_rate <= 0: + return 0.0 + return len(sentence.samples) * 1000.0 / sentence.sample_rate + + +def _round_ms(value: float) -> int: + return math.floor(value + 0.5) + + +def _samples_to_ms(samples: int, sample_rate: int) -> int: + return _round_ms(samples * 1000.0 / sample_rate) + + +def _collapsed_sentence_timing(sentence: SentenceAudio, start_ms: int, end_ms: int) -> WordTiming: + text = sentence.text.strip() or sentence.text + return WordTiming(text=text, start_ms=start_ms, end_ms=end_ms, aligned=False) + + +def _sentence_timings( + voice: LoadedVoice, + sentence: SentenceAudio, + sentence_start_ms: int, + sentence_end_ms: int, + words: list[str], +) -> tuple[list[WordTiming], int]: + """Place each word of one sentence; return its timings and aligned count.""" + if not words or not _has_usable_alignments(sentence): + return [], 0 + + phoneme_texts: list[str] = [] + phoneme_starts: list[int] = [] + phoneme_ends: list[int] = [] + cursor_samples = 0 + for phoneme, sample_count in sentence.phoneme_alignments: + count = max(0, sample_count) + if phoneme not in _SKIPPED_PHONEMES: + phoneme_texts.append(phoneme) + phoneme_starts.append(cursor_samples) + phoneme_ends.append(cursor_samples + count) + cursor_samples += count + if cursor_samples <= 0: + return [], 0 + + timings: list[WordTiming] = [] + aligned_count = 0 + cursor = 0 + previous_end_ms = sentence_start_ms + + for word in words: + word_phonemes = _phonemize_word(voice, word) + matched = False + start_ms = previous_end_ms + end_ms = previous_end_ms + + if word_phonemes and cursor < len(phoneme_texts): + matcher = difflib.SequenceMatcher( + None, phoneme_texts[cursor:], word_phonemes, autojunk=False + ) + match = matcher.find_longest_match( + 0, len(phoneme_texts) - cursor, 0, len(word_phonemes) + ) + required = max(1, math.ceil(len(word_phonemes) * MIN_WORD_MATCH_RATIO)) + if match.size >= required: + first = cursor + match.a + last = first + match.size - 1 + start_ms = sentence_start_ms + _samples_to_ms( + phoneme_starts[first], sentence.sample_rate + ) + end_ms = sentence_start_ms + _samples_to_ms( + phoneme_ends[last], sentence.sample_rate + ) + cursor = first + match.size + matched = True + + start_ms = max(start_ms, previous_end_ms) + end_ms = min(max(end_ms, start_ms), max(sentence_end_ms, start_ms)) + timings.append(WordTiming(text=word, start_ms=start_ms, end_ms=end_ms, aligned=matched)) + if matched: + aligned_count += 1 + previous_end_ms = end_ms + + return timings, aligned_count + + +def _has_usable_alignments(sentence: SentenceAudio) -> bool: + return ( + sentence.supports_alignments + and bool(sentence.phoneme_alignments) + and len(sentence.samples) > 0 + and sentence.sample_rate > 0 + ) + + +def _phonemize_word(voice: LoadedVoice, word: str) -> list[str]: + """Re-phonemize one word in isolation, using the voice's own G2P.""" + try: + groups = voice.voice.phonemize(word) + except Exception: # noqa: BLE001 - a failed word degrades instead of aborting + logger.debug("Word skipped because phonemization failed") + return [] + return [phoneme for group in groups for phoneme in group if phoneme not in _SKIPPED_PHONEMES] diff --git a/tests/unit/test_timing_reconcile.py b/tests/unit/test_timing_reconcile.py new file mode 100644 index 0000000..2141448 --- /dev/null +++ b/tests/unit/test_timing_reconcile.py @@ -0,0 +1,386 @@ +"""Unit tests for phoneme-alignment reconciliation into word timings.""" + +from __future__ import annotations + +import itertools + +import numpy as np +import pytest + +from tts.timing.reconcile import derive_word_timings, split_words +from tts.types import SentenceAudio, SynthesisResult +from tts.voices.store import LoadedVoice + +SAMPLE_RATE = 1000 # one sample is one millisecond, keeping the arithmetic readable + +HELLO = ["h", "ə", "l", "ˈoʊ"] +WORLD = ["w", "ɜː", "l", "d", "."] + + +class FakeVoice: + """Re-phonemize words from a fixed table; unknown words yield no phonemes.""" + + def __init__(self, phonemes_by_word: dict[str, list[str]]) -> None: + self.phonemes_by_word = phonemes_by_word + self.calls: list[str] = [] + + def phonemize(self, text: str) -> list[list[str]]: + self.calls.append(text) + return [list(self.phonemes_by_word.get(text, []))] + + +def _loaded(voice: FakeVoice) -> LoadedVoice: + return LoadedVoice(voice=voice, supports_alignments=True) # type: ignore[arg-type] + + +def _sentence( + text: str, + alignments: list[tuple[str, int]], + *, + sample_count: int | None = None, + sample_rate: int = SAMPLE_RATE, + supports_alignments: bool = True, + char_start: int = 0, +) -> SentenceAudio: + if sample_count is None: + sample_count = sum(count for _, count in alignments) + return SentenceAudio( + text=text, + char_start=char_start, + char_end=char_start + len(text), + samples=np.zeros(sample_count, dtype=np.float32), + sample_rate=sample_rate, + phoneme_alignments=alignments, + supports_alignments=supports_alignments, + ) + + +def _result(sentences: list[SentenceAudio], *, supports_alignments: bool = True) -> SynthesisResult: + return SynthesisResult( + sentences=sentences, + total_samples=sum(len(sentence.samples) for sentence in sentences), + sample_rate=SAMPLE_RATE, + supports_alignments=supports_alignments, + ) + + +def _hello_world_alignments(scale: int = 100) -> list[tuple[str, int]]: + return [ + ("h", scale), + ("ə", scale), + ("l", scale), + ("ˈoʊ", scale), + (" ", scale), + ("w", scale), + ("ɜː", scale), + ("l", scale), + ("d", scale), + (".", scale), + ] + + +def test_maps_words_to_their_phoneme_spans() -> None: + voice = FakeVoice({"Hello": HELLO, "world.": WORLD}) + sentence = _sentence("Hello world.", _hello_world_alignments()) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + assert [(word.text, word.start_ms, word.end_ms, word.aligned) for word in timings] == [ + ("Hello", 0, 400, True), + ("world.", 500, 1000, True), + ] + assert ratio == pytest.approx(1.0) + assert voice.calls == ["Hello", "world."] + + +def test_timings_stay_monotonic_across_sentences() -> None: + voice = FakeVoice({"Hello": HELLO, "world.": WORLD}) + first = _sentence("Hello world.", _hello_world_alignments()) + second = _sentence("Hello world.", _hello_world_alignments(50), char_start=13) + + timings, ratio = derive_word_timings(_loaded(voice), _result([first, second])) + + assert [(word.start_ms, word.end_ms) for word in timings] == [ + (0, 400), + (500, 1000), + (1000, 1200), + (1250, 1500), + ] + assert ratio == pytest.approx(1.0) + assert all(word.aligned for word in timings) + assert all(earlier.end_ms <= later.start_ms for earlier, later in itertools.pairwise(timings)) + + +def test_expanded_number_matches_as_one_word() -> None: + voice = FakeVoice( + { + "Call": ["k", "ɔː", "l"], + "42.": ["fˈɔːɹti", "tˈuː", "."], + } + ) + sentence = _sentence( + "Call 42.", + [ + ("k", 100), + ("ɔː", 100), + ("l", 100), + (" ", 100), + ("fˈɔːɹti", 100), + (" ", 100), + ("tˈuː", 100), + (".", 100), + ], + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + assert [(word.text, word.start_ms, word.end_ms, word.aligned) for word in timings] == [ + ("Call", 0, 300, True), + ("42.", 400, 800, True), + ] + assert ratio == pytest.approx(1.0) + + +def test_punctuation_only_token_is_zero_width_after_the_previous_word() -> None: + voice = FakeVoice({"Hi": ["h", "aɪ"], "—": [], "there.": ["ð", "ɛː", "ɹ", "."]}) + sentence = _sentence( + "Hi — there.", + [ + ("h", 100), + ("aɪ", 100), + (" ", 100), + ("ð", 100), + ("ɛː", 100), + ("ɹ", 100), + (".", 100), + ], + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + assert [(word.text, word.start_ms, word.end_ms, word.aligned) for word in timings] == [ + ("Hi", 0, 200, True), + ("—", 200, 200, False), + ("there.", 300, 700, True), + ] + assert ratio == pytest.approx(2 / 3) + + +def test_emoji_token_is_unaligned_without_inventing_time() -> None: + voice = FakeVoice({"Party": ["p", "ɑː", "ɾ", "i"], "🎉": [], "time": ["t", "aɪ", "m"]}) + sentence = _sentence( + "Party 🎉 time", + [ + ("p", 100), + ("ɑː", 100), + ("ɾ", 100), + ("i", 100), + (" ", 100), + ("t", 100), + ("aɪ", 100), + ("m", 100), + ], + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + emoji = timings[1] + assert (emoji.text, emoji.start_ms, emoji.end_ms, emoji.aligned) == ("🎉", 400, 400, False) + assert [word.aligned for word in timings] == [True, False, True] + assert ratio == pytest.approx(2 / 3) + + +def test_mismatched_case_degrades_only_the_unmappable_word() -> None: + voice = FakeVoice( + { + "HELLO": ["ʒ", "ʒ", "ʒ"], + "brave": ["b", "ɹ", "eɪ", "v"], + "new": ["n", "uː"], + "world": ["w", "ɜː", "l", "d"], + "today": ["t", "uː", "d", "eɪ"], + } + ) + sentence = _sentence( + "HELLO brave new world today", + [ + ("h", 100), + ("ə", 100), + ("l", 100), + ("oʊ", 100), + (" ", 100), + ("b", 100), + ("ɹ", 100), + ("eɪ", 100), + ("v", 100), + (" ", 100), + ("n", 100), + ("uː", 100), + (" ", 100), + ("w", 100), + ("ɜː", 100), + ("l", 100), + ("d", 100), + (" ", 100), + ("t", 100), + ("uː", 100), + ("d", 100), + ("eɪ", 100), + ], + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + assert [word.aligned for word in timings] == [False, True, True, True, True] + assert (timings[0].start_ms, timings[0].end_ms) == (0, 0) + assert ratio == pytest.approx(0.8) + + +def test_corrupted_alignments_collapse_the_sentence() -> None: + voice = FakeVoice({"Hello": HELLO, "world.": WORLD}) + sentence = _sentence( + "Hello world.", + [("k", 100), ("k", 100), (" ", 100), ("k", 100)], + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + assert [(word.text, word.start_ms, word.end_ms, word.aligned) for word in timings] == [ + ("Hello world.", 0, 400, False) + ] + assert ratio == pytest.approx(0.0) + + +def test_threshold_is_inclusive_at_sixty_percent() -> None: + voice = FakeVoice( + {"a": ["a"], "b": ["b"], "c": ["c"], "d": ["x"], "e": ["y"]}, + ) + sentence = _sentence( + "a b c d e", + [ + ("a", 100), + (" ", 100), + ("b", 100), + (" ", 100), + ("c", 100), + (" ", 100), + ("d", 100), + (" ", 100), + ("e", 100), + ], + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + assert len(timings) == 5 + assert [word.aligned for word in timings] == [True, True, True, False, False] + assert ratio == pytest.approx(0.6) + + +def test_below_threshold_collapses_and_ratio_counts_every_token() -> None: + voice = FakeVoice( + { + "Hello": HELLO, + "world.": WORLD, + "Bad": ["x"], + "words": ["y"], + } + ) + good = _sentence("Hello world.", _hello_world_alignments()) + bad = _sentence( + "Bad words", + [("k", 100), (" ", 100), ("k", 100)], + char_start=13, + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([good, bad])) + + assert [(word.text, word.start_ms, word.end_ms, word.aligned) for word in timings] == [ + ("Hello", 0, 400, True), + ("world.", 500, 1000, True), + ("Bad words", 1000, 1300, False), + ] + assert ratio == pytest.approx(0.5) + + +def test_whole_synthesis_without_alignments_returns_minus_one() -> None: + voice = FakeVoice({}) + first = _sentence("Hello world.", [], sample_count=500, supports_alignments=False) + second = _sentence( + "Hello world.", [], sample_count=250, supports_alignments=False, char_start=13 + ) + + timings, ratio = derive_word_timings( + _loaded(voice), _result([first, second], supports_alignments=False) + ) + + assert [(word.text, word.start_ms, word.end_ms, word.aligned) for word in timings] == [ + ("Hello world.", 0, 500, False), + ("Hello world.", 500, 750, False), + ] + assert ratio == -1.0 + assert voice.calls == [] + + +def test_empty_synthesis_returns_no_timings() -> None: + timings, ratio = derive_word_timings(_loaded(FakeVoice({})), _result([])) + + assert timings == [] + assert ratio == -1.0 + + +def test_phonemizer_failure_degrades_only_that_word() -> None: + class FailingVoice(FakeVoice): + def phonemize(self, text: str) -> list[list[str]]: + if text == "bad": + raise RuntimeError("g2p exploded") + return super().phonemize(text) + + def __init__(self) -> None: + super().__init__({"good": ["g", "ʊ", "d"], "bad": [], "word": ["w", "ɜː", "d"]}) + + voice = FailingVoice() + sentence = _sentence( + "good bad word", + [ + ("g", 100), + ("ʊ", 100), + ("d", 100), + (" ", 100), + ("w", 100), + ("ɜː", 100), + ("d", 100), + ], + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([sentence])) + + assert [(word.text, word.aligned) for word in timings] == [ + ("good", True), + ("bad", False), + ("word", True), + ] + assert (timings[1].start_ms, timings[1].end_ms) == (300, 300) + assert ratio == pytest.approx(2 / 3) + + +def test_rounding_keeps_timings_monotonic_with_non_integral_sample_rates() -> None: + voice = FakeVoice({"aaa": ["a", "a", "a"]}) + first = _sentence("aaa", [("a", 1), ("a", 1), ("a", 1)], sample_count=3, sample_rate=3) + second = _sentence( + "aaa", + [("a", 1), ("a", 1), ("a", 1)], + sample_count=3, + sample_rate=7, + char_start=4, + ) + + timings, ratio = derive_word_timings(_loaded(voice), _result([first, second])) + + assert ratio == pytest.approx(1.0) + assert all(word.start_ms <= word.end_ms for word in timings) + assert all(earlier.end_ms <= later.start_ms for earlier, later in itertools.pairwise(timings)) + + +def test_split_words_preserves_input_tokens() -> None: + assert split_words("Hello, world! 🎉 42") == ["Hello,", "world!", "🎉", "42"] + assert split_words(" ") == [] From 0c4d8ea904fa33b936730549aa28d366e3442e73 Mon Sep 17 00:00:00 2001 From: Prateek Chaplot Date: Fri, 20 Nov 2026 18:11:07 +0530 Subject: [PATCH 2/2] chore(tasks): track t1.3 progress --- docs/TASKS.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docs/TASKS.md b/docs/TASKS.md index 56a0053..c87a28a 100644 --- a/docs/TASKS.md +++ b/docs/TASKS.md @@ -24,7 +24,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining | ID | Task | Branch | Verification | Status | |---|---|---|---|---| -| _(empty — next up: T1.3 on branch `arch/tts/t1.3`, pending review)_ | | | | | +| T1.3 | Timing reconcile | `arch/tts/t1.3` | 66 unit tests (14 new); Ruff check/format; strict mypy; 6 integration tests; real-voice manual check (`en_US-lessac-medium`, ratio 0.909, monotonic) | branch open, pending review | ## Remaining @@ -36,8 +36,6 @@ _All P0 tasks done._ | ID | Task | Files | Deps | Acceptance criteria (summary) | |---|---|---|---|---| -| T1.1 | Voice store | `src/tts/voices/store.py` | T0.2 | Sorted voice metadata, alignment support, valid short preview WAV | -| T1.3 | Timing reconcile | `src/tts/timing/reconcile.py` | T0.3 | Monotonic timings, honest degraded alignment, zero-phoneme handling | | T1.4 | Subtitles | `src/tts/subtitles/` | T0.3 | Cue boundary rules and byte-exact SRT/VTT fixtures | | T1.5 | History DAL completion | `src/tts/history/dal.py` | T0.4 | Consistent transactional deletion, eviction ordering, settings seeding | | T1.6 | Jobs manager | `src/tts/jobs/` | T1.2, T1.3, T1.4, T1.5 | Progress/success, atomic failure cleanup, cancellation, sequential jobs | @@ -92,3 +90,6 @@ _All P0 tasks done._ - T1.2 deviation (measurement): piper 1.8's stochastic duration predictor is sublinear at `length_scale=2` — rate 0.5 measures ~1.73x the rate 1.0 duration on `en_US-lessac-medium`, outside the AC's 10% band, so the strict duration-ratio check uses rate 1.25 (nominal 0.8x, measured ~0.82x) averaged over 3 runs; the rate→`length_scale=1/rate` mapping itself is unit-tested and slower rates still produce measurably longer audio. T5.3 should measure real rate/duration scaling before documenting it. - T1.2 environment note: a bare `pytest` run fails collection because `tests/unit/test_voices_store.py` and `tests/integration/test_voices_store.py` share a basename and neither directory is a package; CI passes because it runs each directory separately. New test files use unique names. - T1.2 local integration voice: `en_US-lessac-medium` was downloaded to the gitignored `.venv/tts-data/voices` and integration tests ran with `TTS_DATA_DIR=.venv/tts-data`. +- T1.3 decisions: `timing/` also ships an `__init__.py` (a package needs one; §6 lists only `reconcile.py`). `split_words` is exported so callers group text with the same whitespace tokenizer; because a sentence below threshold collapses to exactly one entry, T1.6 should take per-sentence entry counts by deriving on a single-sentence `SynthesisResult` rather than assuming one entry per token. Matching removes piper's `^`/`$`/`_` and espeak's `" "` from both sequences — the space removal is required because espeak expands numbers into several words (`42` → `fˈɔːɹti tˈuː`) while punctuation-only tokens such as `—` phonemize to nothing. A word counts as aligned when the longest contiguous `difflib` match covers ≥ 60% of its phonemes; the sentence collapse threshold is the same 60% and is inclusive (`3/5` stays, `2/5` collapses). `aligned_word_ratio` counts every token, so a collapsed sentence contributes its token count as unaligned; `-1.0` is returned only when `SynthesisResult.supports_alignments` is false or there are no sentences, and in that case no phonemization is attempted. Timing is accumulated in exact milliseconds across sentences and rounded half-up per word, then clamped into `[previous_end, sentence_end]`, so integer rounding cannot break monotonicity. +- T1.3 real-voice check: manual run on `en_US-lessac-medium` with "Emoji 🙂 stays honest. Yes — indeed, the 42 dogs rest!" reconciled 10/11 tokens (ratio 0.909), monotonic; `—` produced the expected zero-width unaligned entry, and espeak expands 🙂 into "slightly smiling face", which reconciles honestly. The emoji unit fixture uses a synthetic zero-phoneme voice because real espeak speaks emoji names. +- T1.3 environment note: `.venv/pytest-tmp` became undeletable (`WinError 5`) on this machine, so verification used fresh `--basetemp .venv/ptmp-*` directories; the default system temp directory remains inaccessible (see T0.2).