Skip to content
Merged
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
1 change: 1 addition & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ tts/
│ └── src/
│ ├── main.tsx # mount
│ ├── App.tsx # single page layout
│ ├── strings.ts # every user-visible string (section 11, NFR-04)
│ ├── api/
│ │ ├── client.ts # typed fetch wrapper, error envelope decoding
│ │ ├── mock.ts # MockApi implementing ApiInterface (VITE_API_MODE=mock)
Expand Down
9 changes: 7 additions & 2 deletions docs/TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Statuses: done (PR merged) · doing (branch open, pending review) · remaining

| ID | Task | Branch | Verification | Status |
|---|---|---|---|---|
| _(empty)_ | | | | |
| T4.2 | Accessibility + error-copy pass | `arch/tts/t4.2` | 111 Vitest (18 new); ESLint; `tsc --noEmit`; Prettier (CRLF); live Vite build; 23/23 keyboard-only AC15 checks against the built bundle with the real voice; 196 pytest unit; `git diff --check` | Awaiting PR review |

## Remaining

Expand All @@ -61,7 +61,6 @@ _T4.1 done — see Done._

| ID | Task | Files | Deps | Acceptance criteria (summary) |
|---|---|---|---|---|
| T4.2 | Accessibility + error-copy pass | `frontend/src/components/`, `frontend/src/strings.ts` | T3.1–T3.3 | Keyboard-only workflow manually verified and recorded |
| T4.3 | Observability polish | `src/tts/config.py`, `src/tts/jobs/manager.py` | P2 | Failure reason logged without full input text |

### P5 — Verification + docs
Expand Down Expand Up @@ -145,3 +144,9 @@ _T4.1 done — see Done._
- T4.1 mock parity decision (closes T1.4's follow-up): the mock stays as shipped. `mock.ts:buildCues` has no sentence grouping, no 1 200 ms floor, and no audio-duration cap, and its in-memory history is unbounded. Both are accepted **mock-only simplifications** and are recorded here instead of mirrored, because the mock is a P3 scaffold that only runs under `VITE_API_MODE=mock` and `mock.ts` is not one of T4.1's owned files; live behavior (`tts.subtitles.cues`, DAL eviction) is the binding contract.
- T4.1 observation for T5.2 (`KNOWN_LIMITATIONS.md`): words whose phonemes do not reconcile become zero-width `aligned=false` entries, so the highlight is empty while they are spoken — the fixture sentence "Hello world. This is a live check. Numbers like 42 stay honest." produced 2 unaligned words (`This`, `a`) and a highlight gap between `world.` and `is`. This is the FR-05 honest-degradation path (and the words render `.unaligned`), but it is visible to users and should be documented rather than debugged.
- T4.1 environment: this checkout was bare at task start (no `gh`, `.venv`, `frontend/node_modules`, Playwright browsers, or Piper voice); setup was re-run and the voice copied into an isolated `TTS_DATA_DIR=.venv\tts-data` so neither the live run nor the eviction check touched `%LOCALAPPDATA%\tts`. On Windows the Vite dev server binds `localhost` (IPv6) rather than `127.0.0.1`, and `npm run dev -- --port 5173` misparses the port as Vite's root, so the proxy check used `npx vite --port 5173` and `http://localhost:5173`. Prettier's CRLF check also needs the equals form on npm 11: `npx prettier --check . --end-of-line=crlf` (the T2.3 form `npm run format:check -- --end-of-line crlf` now fails with "No files matching the pattern were found: crlf").
- T4.2 decisions: §11's "all strings live in one `strings.ts`" is now enforced — `frontend/src/strings.ts` holds every user-visible literal plus interpolating helpers (`characterCount`, `countLabel`, `statusGenerating`, `jumpLabel`, history labels) and the delete-confirm copy. Copy was moved verbatim (no wording changes) so the frozen aria-label contracts from T2.2/T3.3/T5.1 AC13 (`Open generation: …`, `Delete generation: …`, `N saved generation(s)`) are unchanged. `App.tsx` gained an additive import for the header/tagline/badge/footer copy and `styles.css` gained `.skip-link`, `.banner .error-guidance`, and `.history-confirm` rules; neither file is owned by T4.2, so this is recorded here. §6's frontend tree gained the `strings.ts` line in the same PR.
- T4.2 error copy: `errorGuidance(code)` maps all 15 §9.1 codes to a plain-language corrective action with a fallback for unknown codes; `ErrorBannerContent` (exported, prop-driven) renders heading + server message + "What you can do: …" and is static-markup testable. `ErrorBanner` keeps `role="alert"`, focuses the heading (`tabIndex={-1}`) when an error appears, and Dismiss restores focus to the previously focused element when it is still connected. Errors cleared by other reducer actions (`SET_INPUT`, `GENERATION_CREATED`, …) do not move focus — only the explicit Dismiss does.
- T4.2 accessibility: skip link is the first tab stop and targets `<main id="main" tabIndex={-1}>` (footer stays outside the landmark); the generate section exposes `aria-busy`; `<progress>` is named and carries `aria-valuetext`; the active-word `scrollIntoView` is explicitly `behavior: "auto"` (the highlight transition is already disabled under `prefers-reduced-motion`, which T0.5 shipped). Word spans remain mouse-only seek targets: T3.2's decision is now final, and the sentence cue buttons (one per cue, each in tab order) are the keyboard word-seek path, which AC15 exercises.
- T4.2 history delete: T3.3's deferred confirmation is an inline two-step — Delete swaps to `Confirm delete` + `Keep` and shows "Delete this entry? This cannot be undone.", the confirm button autofocuses, and Keep returns focus to the row's Delete button. No `window.confirm`, no new dependency. Focus effects are not unit-tested (no jsdom, §5 lists vitest only); they were verified in the live keyboard run, while the confirmation markup and labels are covered by static-markup tests.
- T4.2 AC15 record: 23/23 keyboard-only checks passed in **live** mode against the built bundle served by `tts` (port 8322, isolated `TTS_DATA_DIR=.venv\tts-data`, real `en_US-lessac-medium`). Driven by keyboard events only (Tab/Shift+Tab/Enter/Space): first Tab → skip link → Enter → main landmark; Tab → textarea → typed "Hello world. This is a keyboard check."; Tab → voice select (populated) → Tab → Generate audio → Enter → "Audio ready." (aligned ratio 0.714); Tab → Play → Enter starts playback, Space pauses; Tab → sentence cue (focusable `Jump to 00:00: …`); Tab → WAV, SRT, VTT downloads all named `hello-world-this-is-a-keyboard_20261123-125257.{wav,srt,vtt}`; Tab → Delete → Enter (focus moves to Confirm delete) → Tab → Keep → Enter (focus returns to Delete); empty-input pass: error banner takes focus, shows "Enter some text before generating…" plus "What you can do: …", Tab reaches Dismiss, Enter returns focus to Generate audio. The temporary headless-Chromium script was removed after the run and is not committed.
- T4.2 environment: port 8321 was already bound by a stale `tts` process, so the live run used 8322; the temporary script lives in `frontend/` so it resolves `@playwright/test` from `frontend/node_modules`. Vitest count moved 93 → 111 (9 in `strings.test.ts`, 4 in new `ErrorBanner.test.tsx`, 2 history-confirm markup, 2 skip-link/main, 1 `aria-busy`).
13 changes: 13 additions & 0 deletions frontend/src/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ describe("App shell", () => {
expect(html).toContain("Nothing generated yet");
});

it("offers a skip link to the main landmark as the first control", () => {
const html = renderApp();
expect(html.indexOf('class="skip-link"')).toBeGreaterThan(0);
expect(html.indexOf('class="skip-link"')).toBeLessThan(html.indexOf("<header"));
expect(html).toMatch(/<a class="skip-link" href="#main">Skip to main content<\/a>/);
expect(html).toContain('<main id="main" tabindex="-1">');
});

it("keeps the footer outside the main landmark", () => {
const html = renderApp();
expect(html.indexOf("</main>")).toBeLessThan(html.indexOf("<footer"));
});

it("has no alert banner until an error is dispatched", () => {
expect(renderApp()).not.toContain('role="alert"');
});
Expand Down
26 changes: 16 additions & 10 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { PlaybackPanel } from "./components/PlaybackPanel";
import { VoicePanel } from "./components/VoicePanel";
import { clampRate, clampVolume } from "./components/validation";
import { useApp } from "./state/appContext";
import { strings } from "./strings";

export function App() {
const { dispatch } = useApp();
Expand Down Expand Up @@ -63,23 +64,28 @@ export function App() {

return (
<div className="app">
<a className="skip-link" href="#main">
{strings.app.skipLink}
</a>
<header className="app-header">
<h1>tts</h1>
<p className="tagline">Local text to speech with synchronized subtitles.</p>
{apiMode === "mock" ? <p className="badge">Mock mode: sample data</p> : null}
<h1>{strings.app.title}</h1>
<p className="tagline">{strings.app.tagline}</p>
{apiMode === "mock" ? <p className="badge">{strings.app.mockBadge}</p> : null}
</header>

<ErrorBanner />
<InputPanel />
<VoicePanel />
<GenerateBar />
<main id="main" tabIndex={-1}>
<ErrorBanner />
<InputPanel />
<VoicePanel />
<GenerateBar />

<PlaybackPanel />
<PlaybackPanel />

<HistoryPanel />
<HistoryPanel />
</main>

<footer className="app-footer">
<p>Everything runs on this machine; nothing is uploaded.</p>
<p>{strings.app.footer}</p>
</footer>
</div>
);
Expand Down
13 changes: 6 additions & 7 deletions frontend/src/components/DownloadBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import { useState } from "react";
import { api } from "../api";
import { toApiError } from "../api/client";
import { strings } from "../strings";
import { useApp } from "../state/appContext";
import type { GenerationDetail, SubtitleFormat } from "../types/contracts";

Expand Down Expand Up @@ -112,10 +113,8 @@ export function DownloadBar({ detail }: DownloadBarProps) {

return (
<div className="download-block">
<h3>Downloads</h3>
<p className="hint">
Files are named after the first words of the input and when the generation was created.
</p>
<h3>{strings.downloads.heading}</h3>
<p className="hint">{strings.downloads.hint}</p>
<div className="button-row download-row">
<button
type="button"
Expand All @@ -124,7 +123,7 @@ export function DownloadBar({ detail }: DownloadBarProps) {
void downloadAudio();
}}
>
{busy === "wav" ? "Preparing WAV…" : "Download audio (WAV)"}
{busy === "wav" ? strings.downloads.preparingWav : strings.downloads.wav}
</button>
<button
type="button"
Expand All @@ -134,7 +133,7 @@ export function DownloadBar({ detail }: DownloadBarProps) {
void downloadSubtitles("srt");
}}
>
{busy === "srt" ? "Preparing SRT…" : "Download subtitles (SRT)"}
{busy === "srt" ? strings.downloads.preparingSrt : strings.downloads.srt}
</button>
<button
type="button"
Expand All @@ -144,7 +143,7 @@ export function DownloadBar({ detail }: DownloadBarProps) {
void downloadSubtitles("vtt");
}}
>
{busy === "vtt" ? "Preparing VTT…" : "Download subtitles (VTT)"}
{busy === "vtt" ? strings.downloads.preparingVtt : strings.downloads.vtt}
</button>
</div>
</div>
Expand Down
39 changes: 39 additions & 0 deletions frontend/src/components/ErrorBanner.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import type { ErrorInfo } from "../types/contracts";
import { ErrorBannerContent } from "./ErrorBanner";

function renderBanner(code = "ENGINE_ERROR", message = "The speech engine failed."): string {
return renderToStaticMarkup(
<ErrorBannerContent
error={{ code: code as ErrorInfo["code"], message, details: null }}
onDismiss={() => undefined}
/>,
);
}

describe("ErrorBannerContent", () => {
it("announces the problem, the server message, and the corrective action", () => {
const html = renderBanner();
expect(html).toContain('role="alert"');
expect(html).toContain("Something went wrong");
expect(html).toContain("The speech engine failed.");
expect(html).toContain("What you can do");
expect(html).toContain("Try a shorter text or a different voice.");
});

it("makes the heading focusable so focus can move there", () => {
expect(renderBanner()).toMatch(/<h2[^>]*tabindex="-1"/);
});

it("labels the dismiss control for screen readers", () => {
const html = renderBanner();
expect(html).toContain('aria-label="Dismiss error message"');
expect(html).toContain(">Dismiss</button>");
});

it("still gives advice for a code outside the fixed set", () => {
const html = renderBanner("SOMETHING_ELSE", "Unexpected problem.");
expect(html).toContain("Try again. If the problem continues");
});
});
70 changes: 58 additions & 12 deletions frontend/src/components/ErrorBanner.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,78 @@
/**
* Single error surface for the whole page (ARCHITECTURE.md section 16: every
* frontend error goes through here with its message and corrective action).
*
* Accessibility (NFR-04): `role="alert"` announces the error, the message and
* its corrective action are both read, and focus moves to the heading so a
* keyboard user is not stranded at the trigger. Dismiss returns focus to the
* control that was focused when the error appeared.
*/

import { useEffect, useRef, type Ref } from "react";
import { useApp } from "../state/appContext";
import { errorGuidance, strings } from "../strings";
import type { ErrorInfo } from "../types/contracts";

export function ErrorBanner() {
const { state, dispatch } = useApp();

if (state.error === null) {
return null;
}
export interface ErrorBannerContentProps {
error: ErrorInfo;
onDismiss: () => void;
headingRef?: Ref<HTMLHeadingElement>;
}

/** Presentational banner; exported so the copy can be tested without effects. */
export function ErrorBannerContent({ error, onDismiss, headingRef }: ErrorBannerContentProps) {
return (
<section className="section banner" role="alert" aria-labelledby="error-heading">
<div className="banner-heading">
<h2 id="error-heading">Something went wrong</h2>
<h2 id="error-heading" ref={headingRef} tabIndex={-1}>
{strings.error.heading}
</h2>
<button
type="button"
className="secondary"
onClick={() => {
dispatch({ type: "CLEAR_ERROR" });
}}
aria-label={strings.error.dismissLabel}
onClick={onDismiss}
>
Dismiss
{strings.error.dismiss}
</button>
</div>
<p>{state.error.message}</p>
<p>{error.message}</p>
<p className="hint error-guidance">
<strong>{strings.error.guidanceLabel}:</strong> {errorGuidance(error.code)}
</p>
</section>
);
}

export function ErrorBanner() {
const { state, dispatch } = useApp();
const headingRef = useRef<HTMLHeadingElement | null>(null);
const restoreRef = useRef<HTMLElement | null>(null);
const error = state.error;

useEffect(() => {
if (error === null) {
return;
}
const active = document.activeElement;
if (active instanceof HTMLElement && active !== document.body) {
restoreRef.current = active;
}
headingRef.current?.focus();
}, [error]);

if (error === null) {
return null;
}

function dismiss(): void {
const target = restoreRef.current;
restoreRef.current = null;
dispatch({ type: "CLEAR_ERROR" });
if (target !== null && target.isConnected) {
target.focus();
}
}

return <ErrorBannerContent error={error} onDismiss={dismiss} headingRef={headingRef} />;
}
6 changes: 6 additions & 0 deletions frontend/src/components/GenerateBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,10 @@ describe("GenerateBar", () => {
expect(html).toContain("Nothing generated yet");
expect(html).not.toContain("<progress");
});

it("exposes the busy state and a live status line", () => {
const html = renderBar();
expect(html).toContain('aria-busy="false"');
expect(html).toContain('aria-live="polite"');
});
});
44 changes: 25 additions & 19 deletions frontend/src/components/GenerateBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,32 @@
import { useEffect, useRef } from "react";
import { api } from "../api";
import { toApiError } from "../api/client";
import { strings } from "../strings";
import { useApp, type CurrentGeneration } from "../state/appContext";
import type { GenerationDetail, GenerationStreamEvent } from "../types/contracts";
import { validateGeneration } from "./validation";

function statusLabel(current: CurrentGeneration | null): string {
if (current === null) {
return "Nothing generated yet";
return strings.generate.statusEmpty;
}
switch (current.status) {
case "queued":
return "Queued. Waiting for the worker.";
return strings.generate.statusQueued;
case "running":
return current.sentenceCount > 0
? `Generating: ${current.sentenceIndex} of ${current.sentenceCount} sentences done.`
: "Generating…";
? strings.generate.statusGenerating(current.sentenceIndex, current.sentenceCount)
: strings.generate.statusGeneratingUnknown;
case "cancelling":
return "Cancelling…";
return strings.generate.statusCancelling;
case "succeeded":
return current.detail === undefined
? "Finished, but the details could not be loaded. Check the message above."
: "Audio ready.";
? strings.generate.statusMissingDetail
: strings.generate.statusReady;
case "failed":
return "Generation failed. See the message above.";
return strings.generate.statusFailed;
case "cancelled":
return "Generation cancelled. No audio was saved.";
return strings.generate.statusCancelled;
}
}

Expand Down Expand Up @@ -217,25 +218,28 @@ export function GenerateBar() {
const hasVoices = state.voices.length > 0;

return (
<section className="section" aria-labelledby="generate-heading">
<h2 id="generate-heading">Generate</h2>
<section className="section" aria-labelledby="generate-heading" aria-busy={active}>
<h2 id="generate-heading">{strings.generate.heading}</h2>

{hasVoices ? (
<p className="hint">
Start a generation, watch progress, and cancel if you change your mind.
</p>
<p className="hint">{strings.generate.hint}</p>
) : (
<p className="stat warning">
No voices installed, so generation is disabled. Run{" "}
<code>tts add-voice &lt;name&gt;</code> in a terminal, then reload this page.
{strings.generate.noVoicesPrefix} <code>tts add-voice &lt;name&gt;</code>{" "}
{strings.generate.noVoicesSuffix}
</p>
)}

<p className="stat" aria-live="polite">
{statusLabel(current)}
</p>
{active && current !== null && current.sentenceCount > 0 ? (
<progress value={current.sentenceIndex} max={current.sentenceCount} />
<progress
aria-label={strings.generate.progressLabel}
aria-valuetext={`${current.sentenceIndex} of ${current.sentenceCount} sentences`}
value={current.sentenceIndex}
max={current.sentenceCount}
/>
) : null}

<div className="button-row">
Expand All @@ -246,7 +250,7 @@ export function GenerateBar() {
void handleGenerate();
}}
>
Generate audio
{strings.generate.generate}
</button>
{active ? (
<button
Expand All @@ -257,7 +261,9 @@ export function GenerateBar() {
void handleCancel();
}}
>
{current?.status === "cancelling" ? "Cancelling…" : "Cancel generation"}
{current?.status === "cancelling"
? strings.generate.cancelling
: strings.generate.cancel}
</button>
) : null}
</div>
Expand Down
Loading