# Voice Search

## Objective

Let people speak a search query instead of typing it, and still edit what was heard.

A microphone control on the app's existing search field that turns speech into a query the user can correct before it runs.

## 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 microphone to the search input the app already has. Do not build a separate voice search screen or a second results page; the spoken query must go through the same search, the same filters, and the same ranking as a typed one.
2. Show words as they are recognised, in the search field itself, so the user can see the microphone is working before the final result arrives.
3. Leave the recognised text in the field as ordinary editable text once recognition finishes. The single most common repair is the user fixing one wrong word and pressing enter.
4. If the app already has Voice Transcription, reuse its recognition path, its permission handling, and its language selection rather than introducing a second way of listening.
5. Do not auto-submit a low-confidence transcription. Running a search on a misheard query and showing no results reads as a broken product, when the real problem was one mangled word.

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

- Show interim words as they are recognised. A microphone that sits silent for four seconds and then produces a sentence feels broken, and users tap it again mid-utterance.
- Recognition mangles proper nouns, product names, and internal jargon. Bias recognition toward the app's own vocabulary where that is possible, and fall back to fuzzy matching on the search side so a near-miss still finds the record.
- In a noisy room recognition may return nothing usable. Time out after a bounded silence, stop the microphone, and say plainly that nothing was heard rather than listening indefinitely.
- The recognised query must remain fully editable after it lands, including backspacing into it, without the microphone re-arming or the field resetting.
- A low-confidence result must be presented for confirmation rather than submitted. State the confidence in behaviour, not in a percentage shown to the user.
- Microphone permission may be denied, revoked later, or unavailable on an insecure origin. Hide or disable the control and explain why, instead of failing silently on tap.
- The microphone must stop when the user navigates away, switches tabs, or the field loses focus. A recording indicator that stays lit after the user has moved on is a trust problem.
- Announce listening, recognising, and stopped states to screen readers, and give the control a real label rather than an unlabelled icon button.

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

- [ ] Speaking a query populates the existing search field and runs the existing search.
- [ ] Interim words appear while the user is still speaking.
- [ ] The recognised text stays editable and can be corrected before submission.
- [ ] A low-confidence or empty result never submits a search on its own.
- [ ] Denied or unavailable microphone permission produces a clear explanation, not a dead control.
- [ ] The microphone stops on blur, navigation, and timeout, and the recording state is visible while it is on.
- [ ] 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.
