Skip to content

fix(timing): keep boundary phoneme samples so word starts match audio - #24

Merged
prateekchaplot merged 2 commits into
mainfrom
fix/timing-boundaries
Nov 24, 2026
Merged

prateekchaplot merged 2 commits into
mainfrom
fix/timing-boundaries

Conversation

@prateekchaplot

Copy link
Copy Markdown
Owner

Problem

engine/piper_engine.py dropped piper's BOS/EOS/pad (^, $, _) alignments, which
discarded the sample counts for a sentence's leading and trailing silence. timing/reconcile.py
already skips those phonemes for word matching but still advances its sample cursor by their
durations, so every word was placed early by the leading silence and the last word ended before
the trailing silence.

Measured on the two test voices while preparing T5.3: reported first-word starts ran 60-320 ms
ahead of the acoustic onset (240-320 ms on en_US-amy-medium), so AC7's +/-100 ms target could not
hold. Keeping the boundary entries brings the same sentences to roughly +/-25 ms.

Change

  • _chunk_alignments now returns every entry, boundary markers included; the now-unused
    _BOUNDARY_PHONEMES constant is removed.
  • SentenceAudio.phoneme_alignments in ARCHITECTURE section 7.2 is documented as including
    boundary markers, with counts that sum to len(samples) (shared-file protocol, section 14.4).
    This also makes section 14.5 point 1's assertion true.
  • Unit tests assert the retained boundary entries and add a reconcile regression test proving the
    leading silence offsets word starts. The integration test now asserts the counts sum exactly to
    the sentence sample count.
  • docs/TASKS.md records the finding and the dependent tasks.

Dependent tasks: T1.2, T1.3, T5.1 (AC7 tolerance), T5.3.

Verification

  • 202 pytest unit (1 new), 16 integration against en_US-lessac-medium with
    TTS_DATA_DIR=.venv/tts-data
  • Ruff check + format, strict mypy, git diff --check
  • Manual signal check: first-word deviation dropped from +60..+320 ms to about -25..+7 ms across
    seven sentences on both voices (two outliers remain where the first token is unaligned and the
    next word is measured; T5.3 will report those honestly)

The engine dropped piper's BOS/EOS/pad alignments, discarding the sample counts that represent a sentence's leading and trailing silence. Reconcile then placed every word early by the leading silence and ended the last word before the trailing silence, so highlights led the voice by 60-320 ms and AC7's 100 ms target failed.

Keep every alignment entry. reconcile already skips boundary phonemes when matching words while still advancing its sample cursor by their durations, and alignment counts now sum exactly to len(samples).

T5.3 measured the defect. Dependent tasks: T1.2, T1.3, T5.1, T5.3.
Corrected word timings now begin at the first audible word instead of zero, so the first SRT/VTT cue starts inside piper's leading silence. Assert the cue begins at or after the file start and within 1 s, keeping the monotonic and in-audio checks. Verified with the full local suite (15/15).
@prateekchaplot
prateekchaplot merged commit c5023a8 into main Nov 24, 2026
5 checks passed
@prateekchaplot
prateekchaplot deleted the fix/timing-boundaries branch November 24, 2026 04:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant