# Voice Dictation

## Objective

Put a microphone in text fields so people can speak their input instead of typing it.

A dictation control on the app's longer text inputs that transcribes speech into the field as the user talks.

## 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. Add the control to the fields where typing is genuinely tedious: long descriptions, notes, comments, and message bodies. A microphone on a postcode field is clutter.
2. Show interim results in the field as they arrive, visually distinct from committed text, so the speaker can see it is working and correct course before they finish.
3. Reuse the app's existing Voice Transcription for the server-side path so one recognition configuration and one set of language settings serve both dictation and recorded audio.
4. Make the recording state unmistakable: a change of colour alone is not enough. Show an active indicator and a stop control that is always reachable.
5. Do not clear or replace the field when dictation starts. Speaking is usually an addition to something already written, and wiping existing text is unrecoverable if undo is not wired up.

## 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

- Insert transcribed text at the current caret position and respect an active selection, rather than appending to the end or overwriting the whole field.
- Where the browser has no speech input support, hide the control entirely and leave a fully working text field. A microphone button that errors on press is worse than no button.
- Stop listening automatically after a stretch of silence, and tell the user why it stopped so they do not keep talking to a field that is no longer listening.
- Handle spoken punctuation and line breaks consistently, and document the phrases that work. Unpredictable punctuation makes every dictated sentence need a manual pass.
- Release the microphone when the field loses focus, the dialog closes, or the user navigates away. A stubbornly active recording indicator is alarming and looks like a bug even when it is one.
- Undo must treat a dictated block as a single step, so one keystroke removes it rather than fifty.
- Dictation into a field that also autosaves must not save every interim result; commit on a pause or on stop.
- Background noise and multiple voices produce garbage. Give the user an obvious way to discard the last dictated block without hunting for where it began.

## 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

- [ ] Long text inputs across the app offer a dictation control.
- [ ] Transcribed text is inserted at the caret and existing content is preserved.
- [ ] Interim results are visually distinguished from committed text.
- [ ] Unsupported browsers show no control and a fully functional text field.
- [ ] Listening stops after sustained silence and on focus loss, navigation, or dialog close, with the microphone released.
- [ ] The recording state is indicated by more than colour and can always be stopped.
- [ ] A dictated block can be undone in a single step.
- [ ] 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.
