From b1453b8c874a57f6a6a464116dd59b464f683a02 Mon Sep 17 00:00:00 2001 From: Prateek Chaplot Date: Tue, 24 Nov 2026 10:27:39 +0530 Subject: [PATCH] test(measure): record T5.3 latency and word-start accuracy tests/measure.py starts the real app on an ephemeral port against an isolated data directory and drives generations through the public HTTP API, timing submit, first progress, first sentence, every SSE progress interval, and the completed audio download. It then decodes the WAV and compares each measurable word's reported start with its acoustic onset, counting every excluded or unaligned word instead of dropping it. docs/MEASUREMENTS.md holds the recorded run: 3 texts x 2 voices with the 2,000-character text repeated 3 times, hardware note, raw per-run latency table, NFR-02 and A-3 verdicts, and the manual AC7 listening checklist (pending human review). Results: time-to-first-audio 2,960 ms (lessac) / 3,210 ms (amy) for 1,999 characters; per-sentence SSE p95 191 ms (target < 250 ms); word-start |deviation| p95 15 ms, max 32 ms over 160 measurable onsets, so A-3's +/-100 ms is confirmed and WORD_START_TOLERANCE_MS stays 100. --- docs/MEASUREMENTS.md | 109 +++++ docs/TASKS.md | 10 +- tests/measure.py | 1029 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1145 insertions(+), 3 deletions(-) create mode 100644 docs/MEASUREMENTS.md create mode 100644 tests/measure.py diff --git a/docs/MEASUREMENTS.md b/docs/MEASUREMENTS.md new file mode 100644 index 0000000..a5e9b71 --- /dev/null +++ b/docs/MEASUREMENTS.md @@ -0,0 +1,109 @@ +# Measurements + +Generated by `tests/measure.py` (ARCHITECTURE.md T5.3) on 2026-11-24 04:57 UTC at revision `c5023a8`. + +## Environment + +| Item | Value | +|---|---| +| OS | Windows-11-10.0.26300-SP0 | +| CPU | Intel64 Family 6 Model 154 Stepping 3, GenuineIntel | +| Logical cores | 16 | +| RAM | 15.8 GiB | +| Python | 3.12.2 | +| piper-tts | 1.8.0 | +| onnxruntime | 1.32.0 | +| numpy | 2.5.5 | +| Server | uvicorn on 127.0.0.1 (ephemeral port), one process, CPU inference | +| Data directory | `C:\Prateek\GitHub\tts\.venv\measure-data` (isolated from the user library) | +| Voice `en_US-lessac-medium` | 60.3 MB, sha256 5efe09e699021878 | +| Voice `en_US-amy-medium` | 60.3 MB, sha256 cf9ccdec59f05ade | + +## Method + +- The real application (`create_app`) runs in a background uvicorn thread with `TTS_FAULT=none`, rate 1.0, and volume 1.0. +- A generation is driven entirely through the HTTP API. Timestamps use `time.perf_counter()`: submit = POST send to the 202 response; started = the first `progress` event; first sentence = the first `progress` event with `sentenceIndex >= 1`; total = POST send to the `succeeded` event; audio ready = POST send to the completed audio download (the point where the UI can play). +- Per-sentence latency is the gap between consecutive completion events; the first sentence is reported separately because it includes queueing and model work. +- One warm-up generation per voice loads the model and is excluded. +- Each voice runs the short text once, the target text 3 times, and the long text once. +- Word-start deviation: the WAV is split into RMS frames of 10 ms rounded to whole samples (220 samples, 9.977 ms, at 22,050 Hz) and the speech threshold is 4% of the clip's 99th-percentile frame RMS (floor 0.002). Frame positions are converted with the exact frame duration, not a nominal 10 ms, so a long file cannot accumulate a scale error. A word is measurable when it is aligned, at least 100 ms have passed since the previous word, and the 100 ms before its reported start is silent. The first frame above the threshold between 60 ms before and 350 ms after the reported start is the acoustic onset. Deviation = onset minus reported start (positive means the highlight leads the voice). +- Connected speech rarely leaves a silent gap between neighbouring words, so most measurable words start a sentence or follow a pause. Sentence-initial words (the previous token ends a sentence) are also reported separately. Words without a silence gap are counted as excluded, never silently dropped. +- This is a signal-based proxy for audibility; the manual listening checklist below is the AC7 human spot-check. + +## Generation latency (one row per run) + +| Voice | Text | Chars | Sentences | Audio s | Submit ms | Started ms | First sentence ms | Total ms | Audio ready ms | WAV MB | Aligned % | +|---|---|---|---|---|---|---|---|---|---|---|---| +| `en_US-lessac-medium` | short | 139 | 2 | 7.69 | 6 | 9 | 100 | 412 | 423 | 0.32 | 95.8 | +| `en_US-lessac-medium` | target | 1999 | 22 | 115.22 | 6 | 9 | 76 | 2928 | 2960 | 4.85 | 89.1 | +| `en_US-lessac-medium` | target | 1999 | 22 | 115.94 | 7 | 11 | 84 | 2924 | 2952 | 4.88 | 89.1 | +| `en_US-lessac-medium` | target | 1999 | 22 | 115.86 | 7 | 10 | 73 | 2944 | 2972 | 4.87 | 89.1 | +| `en_US-lessac-medium` | long | 4975 | 54 | 286.41 | 6 | 10 | 70 | 6938 | 6982 | 12.05 | 88.7 | +| `en_US-amy-medium` | short | 139 | 2 | 9.54 | 32 | 36 | 114 | 269 | 282 | 0.40 | 91.7 | +| `en_US-amy-medium` | target | 1999 | 22 | 134.70 | 5 | 8 | 80 | 3269 | 3308 | 5.67 | 84.2 | +| `en_US-amy-medium` | target | 1999 | 22 | 134.84 | 7 | 10 | 87 | 3177 | 3210 | 5.67 | 84.2 | +| `en_US-amy-medium` | target | 1999 | 22 | 134.75 | 7 | 10 | 92 | 3170 | 3199 | 5.67 | 84.2 | +| `en_US-amy-medium` | long | 4975 | 54 | 334.82 | 7 | 9 | 81 | 7815 | 7881 | 14.08 | 83.8 | + +## NFR-02 targets + +Target text: 1999 characters, generated 3 times per voice. The first run of each voice includes any remaining model warm-up, so medians are reported. + +| Voice | Runs | Audio ready median ms | Total median ms | First sentence median ms | Per-sentence median ms | Per-sentence p95 ms | +|---|---|---|---|---|---|---| +| `en_US-lessac-medium` | 3 | 2960 | 2928 | 76 | 118 | 187 | +| `en_US-amy-medium` | 3 | 3210 | 3177 | 87 | 134 | 198 | + +### NFR-02 verdict + +- SSE progress latency: pooled p95 191 ms over 234 sentence intervals (median 129 ms); ARCHITECTURE.md section 11 asks for under 250 ms per sentence. +- Time-to-first-audio for the 1999-character text: `en_US-lessac-medium` 2960 ms, `en_US-amy-medium` 3210 ms. The app serves the finished WAV, so this is also the total synthesis time; the `First sentence ms` column shows when the first progress event arrives, which is what the UI displays while the job runs. +- Long text (4975 characters, one run per voice): `en_US-lessac-medium` 6938 ms, `en_US-amy-medium` 7815 ms. + +The main thread is never blocked by synthesis: the work runs in the server process and the highlight loop is a requestAnimationFrame binary search. T5.1's AC8 and AC15 specs exercise that in Chromium. + +## Word-start accuracy + +| Voice | Words | Aligned | Measured | Excluded | Unaligned | Mean signed ms | Median abs ms | p95 abs ms | Max abs ms | +|---|---|---|---|---|---|---|---|---|---| +| `en_US-lessac-medium` | 1828 | 1627 | 99 | 1528 | 201 | 3 | 5 | 27 | 32 | +| `en_US-amy-medium` | 1828 | 1538 | 61 | 1477 | 290 | 4 | 4 | 9 | 11 | +| **Pooled** | | | 160 | | | | 5 | 15 | 32 | + +### A-3 tolerance verdict + +A-3's +-100 ms word-start tolerance is confirmed: the pooled p95 absolute deviation is 15 ms over 160 measurable words (sentence-initial p95 19 ms). + +## Manual listening checklist (AC7) + +Status: **pending human review**. Play the target text in the app, open the subtitle word list, and check the words below. The automated table above measures the same property from the WAV; a large disagreement between the two is worth investigating. + +| Voice | Word | Start ms | End ms | Within 100 ms? | +|---|---|---|---|---| +| `en_US-lessac-medium` | keeps | 1416 | 1637 | [ ] | +| `en_US-lessac-medium` | the | 28561 | 28607 | [ ] | +| `en_US-lessac-medium` | reader | 56970 | 57179 | [ ] | +| `en_US-lessac-medium` | keeps | 87284 | 87528 | [ ] | +| `en_US-amy-medium` | keeps | 1625 | 1939 | [ ] | +| `en_US-amy-medium` | the | 33681 | 33762 | [ ] | +| `en_US-amy-medium` | the | 66549 | 66630 | [ ] | +| `en_US-amy-medium` | keeps | 101622 | 101936 | [ ] | + +## Reproduction + +``` +set TTS_DATA_DIR=.venv\measure-data +python -m tts add-voice en_US-lessac-medium +python -m tts add-voice en_US-amy-medium +python tests/measure.py --out docs/MEASUREMENTS.md +``` + +On this Windows checkout the command runs from the repository root with `.venv\Scripts\python.exe`. The script seeds the measurement data directory from `.venv/tts-data/voices` when it is empty and never touches the user's `%LOCALAPPDATA%\tts` library. + +## Notes and caveats + +- Piper's duration predictor is stochastic (T1.2 measured about 1.73x instead of the nominal 2x at rate 0.5), so latency and duration vary run to run; medians are reported, not single samples. +- The onset detector needs a silent gap, so it measures words that start a sentence or follow a pause far more often than words inside a clause. Excluded words are counted in the table rather than hidden. +- Words whose phonemes do not reconcile are `aligned=false` with a zero-width span and are counted as unaligned, not as a measurement. +- Measurements are CPU-only and single-process, with the voice cache warm after the per-voice warm-up run. A busy machine shifts the latency columns. +- The tolerance verdict is signal-based, not a human judgement; the checklist above remains the AC7 manual step. diff --git a/docs/TASKS.md b/docs/TASKS.md index b74cebc..687ac0d 100644 --- a/docs/TASKS.md +++ b/docs/TASKS.md @@ -38,7 +38,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining | ID | Task | Branch | Verification | Status | |---|---|---|---|---| -| _(empty)_ | | | | | +| T5.3 | Measurement | `arch/tts/t5.3` | 3 texts (139 / 1,999 / 4,975 chars) x 2 voices, 3 runs of the 2,000-char text; `docs/MEASUREMENTS.md` written with hardware note; 160 measurable word onsets (p95 15 ms, max 32 ms); SSE p95 191 ms; TTF audio ~3 s | PR open | ## Remaining @@ -67,7 +67,6 @@ _All P4 tasks done._ | ID | Task | Files | Deps | Acceptance criteria (summary) | |---|---|---|---|---| | T5.2 | Docs | `README.md`, `docs/USER_GUIDE.md`, `docs/KNOWN_LIMITATIONS.md`, `docs/PRD.md` | T5.1 | Fresh-machine workflow completes using README alone | -| T5.3 | Measurement | `tests/measure.py`, `docs/MEASUREMENTS.md` | T4.1 | Performance and timing measurements with hardware note | ## Notes @@ -158,4 +157,9 @@ _All P4 tasks done._ - T5.1 browser finding (recorded, no production change): a native `