# Auto Captions

## Objective

Every uploaded video gets timed captions without anyone typing them out.

An automatic captioning pass over uploaded video that produces a timed caption track shown in the player.

## Before You Begin

This feature is being added to an application that already exists and already
works. Do not scaffold a new project, and do not assume a blank slate.

Inspect the codebase first and establish:

- The existing application structure and where code of this kind already lives.
- The framework and version in use.
- The existing design system — colours, spacing, typography, and component conventions.
- Existing UI components you can reuse instead of writing new ones.
- The existing database structure, if this feature needs to persist anything.
- The existing authentication and authorization system, if this feature is user-scoped.
- Dependencies already installed, so you don't add a library that duplicates one.
- The existing test setup and conventions.

Only start writing code once you understand the above. If the application
already implements part of this feature, extend it rather than replacing it.

## Implementation Instructions

1. Extend the app's existing Voice Transcription rather than adding a second speech pipeline. What is new here is timing, storage as a caption track, and player integration, not the recognition itself.
2. Run captioning as a background job triggered after the upload finishes, and reuse the app's existing job progress reporting so the user can see where a long file has got to.
3. Store the caption track as its own record linked to the media, with a language, a status, and a source marking it as machine-generated so a human correction can supersede it later.
4. Expose the track through the app's existing player with a caption toggle, and remember the viewer's on or off choice across videos.
5. Do not block the upload or the publish step on captioning. The video should be watchable immediately, with captions appearing when they are ready.

## UI and UX Requirements

Match the application's existing design system exactly. Reuse its components,
spacing, and typography. This feature should look like it was always there.

## Responsive Requirements

Works on mobile, tablet, and desktop. Touch targets are large enough to hit on a
phone, and nothing overflows horizontally at 320px.

## Accessibility Requirements

- Fully keyboard navigable.
- Correct semantic elements and ARIA roles.
- Visible focus states.
- Meets WCAG AA contrast.
- Dynamic changes are announced to screen readers.
- Respects prefers-reduced-motion.

## Edge Cases

- Long files must be queued with visible progress rather than holding the upload request open. A ninety minute recording will otherwise time out somewhere between the browser and the worker.
- Audio-only tracks, silent tracks, and pure music must resolve to a clear no-speech-detected state rather than writing an empty caption file that the player advertises as available captions.
- Cap each caption line to a readable length and each cue to a sensible on-screen duration, and split long sentences across cues instead of pushing a wall of text over the picture.
- When generation fails partway through a long file, keep the cues already produced, mark the track as partial, and offer a resume rather than discarding an hour of work.
- Trimming, re-encoding, or replacing the source media invalidates the timings. Detect the change and either re-run the pass or mark the track as out of sync rather than showing captions that drift.
- Multiple speakers, heavy accents, and background noise all reduce accuracy. Label machine-generated tracks as such in the player so viewers calibrate their trust.
- Store a confidence signal per cue where the recognition provides one, so a later editing pass can highlight the lines most likely to be wrong.
- A caption track puts whatever was said in the room onto a public page and into search results, transcribed automatically with nobody reading it first. Give the owner a review step before the track is published, and let them correct or suppress a single line rather than only switching the whole track off.

## Testing

Exercise the feature end to end in the running application. Cover every edge case
above, then run the existing test suite and confirm nothing regressed.

## Acceptance Criteria

- [ ] Uploading a video queues a captioning job without blocking the upload or publish.
- [ ] Progress is visible for long files and reported through the app's existing job progress surface.
- [ ] Completed tracks appear as a selectable caption option in the player and are labelled machine-generated.
- [ ] Silent and audio-only sources produce a no-speech state, never an empty advertised track.
- [ ] Cue length and on-screen duration stay within readable limits.
- [ ] A failed run preserves partial results and can be resumed.
- [ ] Replacing or trimming the source media invalidates or regenerates the track.
- [ ] The feature matches the existing design system.
- [ ] No existing functionality is broken.

## Adaptation Rules

- Match the existing design system. Do not introduce a new colour palette,
  spacing scale, or component library.
- Reuse existing components and utilities wherever they fit.
- Follow the naming, file layout, and code style already present.
- Do not upgrade, replace, or remove existing dependencies to make this
  feature fit. Adapt the feature to the app, not the app to the feature.
- Do not break existing functionality. If a change is genuinely required in
  existing code, make the smallest one that works and say so.
- If something in these instructions conflicts with how the application is
  built, follow the application and explain the deviation.

## Final Verification

Before you report the work as done:

1. Re-read the acceptance criteria above and check each one against what you
   actually built.
2. Run the application and exercise the feature end to end.
3. Run the existing test suite and confirm you have broken nothing.
4. Check the feature on mobile, tablet, and desktop widths.
5. Check keyboard navigation and focus handling.
6. Summarize what changed: files added, files modified, and anything you
   deliberately did differently because of how this application is built.

If any acceptance criterion is unmet, fix it before reporting completion.
