Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions docs/MEASUREMENTS.md
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 7 additions & 3 deletions docs/TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -158,4 +157,9 @@ _All P4 tasks done._
- T5.1 browser finding (recorded, no production change): a native `<audio controls>` element absorbs several Tab presses inside its own shadow controls, and when a generation finishes the Generate button is replaced, so focus returns to the document and forward Tab skips ahead to the sentence cues. Keyboard users can still play from the main landmark with the documented Space shortcut; AC15 reaches that landmark through the skip link. This is existing UI behavior outside T5.1's owned files, noted for T5.2.
- T5.1 verification: 15/15 Playwright specs (three runs, one from empty data dirs); `npx tsc -p tests/e2e --noEmit`; 201 pytest unit; 16 integration (`TTS_DATA_DIR=.venv/tts-data`, `--basetemp .venv/ptmp-t51-int`); 111 Vitest; Ruff check/format; strict mypy; ESLint; frontend `tsc --noEmit`; Prettier (CRLF); `git diff --check`. PR CI must confirm the two-server topology on Linux.

- Timing fix (found by T5.3 measurement, merged before T5.3): `engine/piper_engine.py` dropped piper's `^`/`$`/`_` alignments entirely, discarding their sample counts, so `timing/reconcile.py` placed every word early by the sentence-leading silence (measured 60-320 ms on the two test voices, exceeding AC7's ±100 ms target). `_chunk_alignments` now keeps every entry; reconcile already skips boundary phonemes for word matching while still advancing its sample cursor by their durations. ARCHITECTURE §7.2's `SentenceAudio.phoneme_alignments` comment was updated in the same PR (shared-file protocol), and alignment counts now sum exactly to `len(samples)` as §14.5 point 1 asserts. Dependent tasks: T1.2, T1.3, T5.1 (AC7 tolerance and the AC10 spec, whose "first cue starts at zero" assertion became "first cue starts at or before the first audible word"), T5.3.
- Timing fix (found by T5.3 measurement, merged before T5.3): `engine/piper_engine.py` dropped piper's `^`/`$`/`_` alignments entirely, discarding their sample counts, so `timing/reconcile.py` placed every word early by the sentence-leading silence (measured 60-320 ms on the two test voices, exceeding AC7's ±100 ms target). `_chunk_alignments` now keeps every entry; reconcile already skips boundary phonemes for word matching while still advancing its sample cursor by their durations. ARCHITECTURE §7.2's `SentenceAudio.phoneme_alignments` comment was updated in the same PR (shared-file protocol), and alignment counts now sum exactly to `len(samples)` as §14.5 point 1 asserts. Dependent tasks: T1.2, T1.3, T5.1 (AC7 tolerance and the AC10 spec, whose "first cue starts at zero" assertion became "first cue starts at or before the first audible word"), T5.3.

- T5.3 measurement: `tests/measure.py` starts the real app (`create_app`) in a background uvicorn thread on an ephemeral port with `TTS_DATA_DIR=.venv/measure-data` and drives generations through the public HTTP API, so the numbers describe the shipped path rather than a direct engine call. Texts: 139, 1,999 and 4,975 characters; `en_US-lessac-medium` and `en_US-amy-medium`; the 2,000-character text repeated 3 times per voice after a warm-up generation. Hardware note (recorded in the report): 16 logical cores (Intel Family 6 Model 154), 15.8 GiB RAM, Windows 11 build 26300, Python 3.12.2, piper-tts 1.8.0, onnxruntime 1.32.0, CPU inference, single process.
- T5.3 results: time-to-first-audio for the 1,999-character text is 2,960 ms median on `lessac` and 3,210 ms on `amy` (the app serves the finished WAV, so this equals total synthesis time; the first progress event arrives at 87-93 ms). Per-sentence SSE progress: pooled p95 191 ms, median 129 ms over 234 intervals, inside section 11's 250 ms target. Word-start deviation over 160 measurable onsets: p95 |deviation| 15 ms, max 32 ms across both voices. This confirms A-3's +/-100 ms word-start tolerance, so `tests/e2e/support/env.ts` keeps `WORD_START_TOLERANCE_MS = 100` unchanged; no T5.1 edit was needed.
- T5.3 honesty and caveats: only 160 of 3,656 word instances are measurable by signal (3,168 excluded for lacking a silent gap before the word, 491 unaligned by design), because connected speech rarely pauses between words. Every exclusion is counted in `MEASUREMENTS.md`, and the report says plainly that this is a signal proxy pending the manual AC7 listening checklist, which lists 8 words (0/25/50/75% through the target text) and stays marked pending until a human listens.
- T5.3 harness bug found and fixed before the numbers were recorded: 22,050 Hz does not divide into whole 10 ms frames (220 samples = 9.977 ms), so converting frame indexes with a nominal 10 ms invented a 0.23% scale error - a 260 ms "late drift" at 115 s that looked like a timing defect. Frame positions now use the exact frame duration; the apparent drift disappeared and the residual deviations are the small numbers above. The earlier "unexplained outlier" for sentences starting with the token "A" was the same artifact.
Loading
Loading