How hcharlie/voice-input works
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: AppDelegate.swift AppDelegate · SpeechEngine.swift SpeechEngine · TextInjector.swift TextInjector · KeyMonitor.swift KeyMonitor
Components 14
App Core
Startup and coordination for the resident menu-bar app.
- main.swift · Package entry point that starts the macOS app process.
Sources/VoiceInput/main.swift - AppDelegate · Owns app initialization and wires the menu-bar runtime together.
Sources/VoiceInput/AppDelegate.swift - Status item · Persistent menu-bar presence for launching and controlling the utility.
- VoiceInput.app · The packaged macOS application built from the Swift package.
Input Capture
Global keyboard and microphone capture boundaries.
- KeyMonitor · Detects the Fn-key globally and drives recording state changes.
Sources/VoiceInput/KeyMonitor.swift
Processing
Speech transcription and optional text refinement.
- SpeechEngine · Captures microphone audio and performs local transcription.
Sources/VoiceInput/SpeechEngine.swift - LLMRefiner · Optional cleanup stage that refines recognized text before insertion.
Sources/VoiceInput/LLMRefiner.swift
Output
Text delivery and user-facing feedback.
- TextInjector · Injects finalized text into the currently focused application.
Sources/VoiceInput/TextInjector.swift - OverlayPanel · Shows recording or transcribing feedback during capture.
Sources/VoiceInput/OverlayPanel.swift - SettingsWindow · Exposes runtime settings such as recognition language.
Sources/VoiceInput/SettingsWindow.swift
Platform
External macOS services and destinations the app depends on.
- Microphone · System microphone source used for speech capture.
- Apple Speech · On-device macOS speech recognition framework used for transcription.
- Accessibility · macOS permission boundary required for global input monitoring and text injection.
- Focused app · Any currently active application that receives inserted text.
Connections 18
- 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.