# hcharlie/voice-input architecture

> Architecture diagram of the GitHub repository hcharlie/voice-input, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hcharlie/voice-input
- Repository: https://github.com/hcharlie/voice-input

## Overview

1. **What this repo is**
   - `VoiceInput` is a small macOS menu-bar utility, built in Swift, whose core job is to turn a held **Fn** key into a push-to-talk text entry flow.
   - The app listens for a global hotkey, records microphone input, transcribes speech locally, and injects the resulting text into whatever app currently has keyboard focus.

2. **Top-level structure**
   - The project is a single Swift package (`Package.swift`) that builds a macOS application bundle.
   - The main app code lives under `Sources/VoiceInput/`, with one file per major subsystem: startup, keyboard monitoring, speech capture/transcription, text insertion, overlay UI, and settings UI.

3. **Startup and application lifecycle**
   - `main.swift` is the entry point, and `AppDelegate.swift` likely owns app initialization and coordination.
   - Because this is a menu-bar app, the lifecycle is centered around creating the status item, wiring global listeners, and keeping the app resident rather than managing a large document/window scene.

4. **Global input capture boundary**
   - `KeyMonitor.swift` is the boundary between macOS system input events and the app’s recording state.
   - It is responsible for detecting the Fn-key press/release globally, so the app can start and stop recording regardless of which application is active.
   - This requires system-level accessibility-style permissions, which matches the README’s Accessibility requirement.

5. **Speech-to-text pipeline**
   - `SpeechEngine.swift` is the main transcription subsystem.
   - The README indicates it uses Apple’s on-device Speech Recognition framework, so the speech pipeline stays local to the Mac instead of sending audio to a remote service.
   - The data flow is: microphone audio input → speech recognition → incremental or final text output.

6. **Text delivery into other apps**
   - `TextInjector.swift` is the integration boundary with external applications.
   - Its job is to take recognized text and type/paste it into the currently focused text field, which is why Accessibility permission is needed.
   - This is the key “fan-out” point: the app does not own the destination editor; it writes into whatever app currently owns focus.

7. **User feedback and recording state**
   - `OverlayPanel.swift` likely provides a lightweight on-screen overlay while recording or transcribing.
   - In architecture terms, this is a presentation-layer component that reflects the current state of the speech engine and key monitor, rather than being part of the transcription pipeline itself.

8. **Configuration UI**
   - `SettingsWindow.swift` is the explicit settings surface exposed from the menu bar icon.
   - The README mentions changing the recognition language from the menu bar, so this window or menu likely holds app preferences such as language selection and possibly other runtime settings.

9. **Optional text refinement**
   - `LLMRefiner.swift` suggests a post-processing stage for improving recognized text before insertion.
   - That module is architecturally distinct from the core Apple speech path, and it likely sits between transcription output and text injection when enabled.
   - Even if it is not the default route, it represents an optional enhancement boundary for cleanup or normalization.

10. **End-to-end runtime flow**
   - The typical runtime sequence is: app launches → global Fn monitoring starts → user holds Fn → microphone recording begins → speech engine transcribes audio → overlay reflects active capture → on release, recording stops → final text is optionally refined → text is injected into the focused app.
   - This makes the app effectively a state machine driven by keyboard events and speech-recognition events.

11. **External dependencies and platform constraints**
   - The architecture is tightly coupled to macOS APIs: global event monitoring, accessibility permissions, microphone capture, speech recognition, and text injection into other apps.
   - The README’s macOS 14+ requirement and Xcode Command Line Tools requirement indicate the codebase is intentionally narrow in platform support and likely uses modern AppKit/Swift APIs.

12. **Build and deployment shape**
   - The repo uses Swift Package Manager and a simple `Makefile` to build, install, and run the app.
   - The final artifact is a `.app` bundle copied to `/Applications`, which is consistent with a lightweight utility distributed as a standard macOS application rather than a service or daemon.

13. **How to think about the architecture diagram**
   - The cleanest diagram is a center-out flow with three main domains:
     - **Input capture**: global Fn monitoring + microphone recording
     - **Processing**: speech recognition, with optional refinement
     - **Output/UI**: overlay/settings UI and text injection into external apps
   - The core trust boundary is the handoff from local recognition to system-wide text insertion, which depends on user-granted permissions and interacts with arbitrary foreground applications.

Main entry points: [`Sources/VoiceInput/AppDelegate.swift`](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/AppDelegate.swift) (AppDelegate), [`Sources/VoiceInput/SpeechEngine.swift`](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/SpeechEngine.swift) (SpeechEngine), [`Sources/VoiceInput/TextInjector.swift`](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/TextInjector.swift) (TextInjector), [`Sources/VoiceInput/KeyMonitor.swift`](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/KeyMonitor.swift) (KeyMonitor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_app["App Core"]
  node_node_main["main.swift<br/>entrypoint<br/>[main.swift]"]
  node_node_app_delegate["AppDelegate<br/>lifecycle<br/>[AppDelegate.swift]"]
  node_node_menu_bar(("Status item<br/>menu-bar ui"))
  node_node_app_bundle[("VoiceInput.app<br/>bundle")]
end

subgraph group_group_input["Input Capture"]
  node_node_key_monitor["KeyMonitor<br/>global hotkey<br/>[KeyMonitor.swift]"]
end

subgraph group_group_processing["Processing"]
  node_node_speech_engine["SpeechEngine<br/>speech-to-text<br/>[SpeechEngine.swift]"]
  node_node_llm_refiner["LLMRefiner<br/>postprocess<br/>[LLMRefiner.swift]"]
end

subgraph group_group_output["Output"]
  node_node_text_injector["TextInjector<br/>text delivery<br/>[TextInjector.swift]"]
  node_node_overlay_panel["OverlayPanel<br/>status ui<br/>[OverlayPanel.swift]"]
  node_node_settings_window["SettingsWindow<br/>preferences ui"]
end

subgraph group_group_platform["Platform"]
  node_node_microphone[("Microphone<br/>audio input")]
  node_node_speech_framework{{"Apple Speech<br/>os framework"}}
  node_node_accessibility{{"Accessibility<br/>os permission"}}
  node_node_foreground_app(("Focused app<br/>external destination"))
end

node_node_main -->|"launches"| node_node_app_delegate
node_node_app_delegate -->|"creates"| node_node_menu_bar
node_node_app_delegate -->|"wires"| node_node_key_monitor
node_node_app_delegate -->|"configures"| node_node_speech_engine
node_node_app_delegate -->|"wires"| node_node_text_injector
node_node_app_delegate -->|"shows"| node_node_overlay_panel
node_node_app_delegate -->|"opens"| node_node_settings_window
node_node_key_monitor -->|"start/stop"| node_node_speech_engine
node_node_speech_engine -->|"records"| node_node_microphone
node_node_speech_engine -->|"transcribes"| node_node_speech_framework
node_node_speech_engine -->|"optionally sends"| node_node_llm_refiner
node_node_llm_refiner -->|"returns text"| node_node_text_injector
node_node_speech_engine -->|"updates"| node_node_overlay_panel
node_node_overlay_panel -->|"reports state"| node_node_app_delegate
node_node_text_injector -->|"requires"| node_node_accessibility
node_node_key_monitor -->|"requires"| node_node_accessibility
node_node_text_injector -->|"inserts into"| node_node_foreground_app
node_node_app_delegate -->|"packages"| node_node_app_bundle

click node_node_main "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/main.swift"
click node_node_app_delegate "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/AppDelegate.swift"
click node_node_key_monitor "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/KeyMonitor.swift"
click node_node_speech_engine "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/SpeechEngine.swift"
click node_node_llm_refiner "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/LLMRefiner.swift"
click node_node_text_injector "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/TextInjector.swift"
click node_node_overlay_panel "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/OverlayPanel.swift"
click node_node_settings_window "https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/SettingsWindow.swift"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_node_main,node_node_app_delegate,node_node_menu_bar,node_node_app_bundle toneBlue
class node_node_key_monitor toneAmber
class node_node_speech_engine,node_node_llm_refiner toneMint
class node_node_text_injector,node_node_overlay_panel,node_node_settings_window toneRose
class node_node_microphone,node_node_speech_framework,node_node_accessibility,node_node_foreground_app toneIndigo
```

## Components

### App Core

Startup and coordination for the resident menu-bar app.

- [main.swift](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/main.swift): entrypoint · Package entry point that starts the macOS app process. · `Sources/VoiceInput/main.swift`
- [AppDelegate](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/AppDelegate.swift): lifecycle · Owns app initialization and wires the menu-bar runtime together. · `Sources/VoiceInput/AppDelegate.swift`
- **Status item**: menu-bar ui · Persistent menu-bar presence for launching and controlling the utility.
- **VoiceInput.app**: bundle · The packaged macOS application built from the Swift package.

### Input Capture

Global keyboard and microphone capture boundaries.

- [KeyMonitor](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/KeyMonitor.swift): global hotkey · Detects the Fn-key globally and drives recording state changes. · `Sources/VoiceInput/KeyMonitor.swift`

### Processing

Speech transcription and optional text refinement.

- [SpeechEngine](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/SpeechEngine.swift): speech-to-text · Captures microphone audio and performs local transcription. · `Sources/VoiceInput/SpeechEngine.swift`
- [LLMRefiner](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/LLMRefiner.swift): postprocess · Optional cleanup stage that refines recognized text before insertion. · `Sources/VoiceInput/LLMRefiner.swift`

### Output

Text delivery and user-facing feedback.

- [TextInjector](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/TextInjector.swift): text delivery · Injects finalized text into the currently focused application. · `Sources/VoiceInput/TextInjector.swift`
- [OverlayPanel](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/OverlayPanel.swift): status ui · Shows recording or transcribing feedback during capture. · `Sources/VoiceInput/OverlayPanel.swift`
- [SettingsWindow](https://github.com/hcharlie/voice-input/blob/main/Sources/VoiceInput/SettingsWindow.swift): preferences ui · Exposes runtime settings such as recognition language. · `Sources/VoiceInput/SettingsWindow.swift`

### Platform

External macOS services and destinations the app depends on.

- **Microphone**: audio input · System microphone source used for speech capture.
- **Apple Speech**: os framework · On-device macOS speech recognition framework used for transcription.
- **Accessibility**: os permission · macOS permission boundary required for global input monitoring and text injection.
- **Focused app**: external destination · Any currently active application that receives inserted text.

## Connections

- main.swift → AppDelegate: launches · Process entry hands control to the app delegate.
- AppDelegate → Status item: creates · Initializes the resident menu-bar presence.
- AppDelegate → KeyMonitor: wires · Starts global Fn monitoring as part of app startup.
- AppDelegate → SpeechEngine: configures · Connects the speech subsystem to the runtime.
- AppDelegate → TextInjector: wires · Provides the delivery path for finalized text.
- AppDelegate → OverlayPanel: shows · Manages recording feedback UI.
- AppDelegate → SettingsWindow: opens · Exposes preferences from the menu-bar app.
- KeyMonitor → SpeechEngine: start/stop · Fn press and release drive recording state.
- SpeechEngine → Microphone: records · Consumes microphone audio input.
- SpeechEngine → Apple Speech: transcribes · Uses the local Apple speech stack for recognition.
- SpeechEngine → LLMRefiner: optionally sends · Can pass recognized text through refinement.
- LLMRefiner → TextInjector: returns text · Produces cleaned text for insertion.
- SpeechEngine → OverlayPanel: updates · Drives active recording/transcribing status.
- OverlayPanel → AppDelegate: reports state · Presentation follows app-managed capture state.
- TextInjector → Accessibility: requires · Needs accessibility-style permission to type into other apps.
- KeyMonitor → Accessibility: requires · Needs system-level input monitoring permission.
- TextInjector → Focused app: inserts into · Types or pastes into whichever app currently has focus.
- AppDelegate → VoiceInput.app: packages · The Swift package builds the distributable macOS app bundle.
