How nfarina/whisper-dictate works
Project type and purpose
• WhisperDictate is a native macOS menu bar application built with SwiftUI.
• It captures audio via a global hotkey, sends it to OpenAI’s Whisper API for transcription, and injects the resulting text into any active application using macOS accessibility services.
File structure
• Top-level Xcode project: WhisperDictate.xcodeproj (build configs, schemes).
• Swift source files under WhisperDictate/:
– WhisperDictateApp.swift (app entry point)
– ContentView.swift, MenuBarView.swift (UI layer)
– AudioManager.swift (audio capture and buffer management)
– HotkeyManager.swift (global hotkey registration & handling)
– RecordingCoordinator.swift (state machine for recording sessions)
– TranscriptionManager.swift (HTTP client to OpenAI Whisper API)
– Logger.swift (centralized logging)
• WhisperDictate.entitlements (accessibility, keystroke permissions)
README for additional insights
• Describes a simple event-driven architecture: hotkey → record audio → call Whisper API → type text.
• Lists external dependencies: OpenAI Whisper API; macOS Keychain for secure storage; SwiftUI for UI.
• Mentions privacy/security requirements (no local audio storage, secure API key).
Main components
a. UI Layer
– Displays recording state and settings (API key entry).
b. Hotkey & Input Handling
– HotkeyManager: listens for ⌘+Ctrl+R, triggers recording.
c. Audio Capture & Coordination
– AudioManager: interfaces with AVFoundation, streams audio buffers.
– RecordingCoordinator: manages recording lifecycle (start/stop, state transitions).
d. Transcription Service
– TranscriptionManager: sends audio buffers over HTTPS to OpenAI Whisper API; receives text.
e. Text Injection
– Uses macOS accessibility APIs to “type” the transcribed text into the active application.
f. Security & Persistence
– Keychain Integration: secure storage/retrieval of OpenAI API key.
g. Logging
– Logger: centralized logging of events, errors, API responses.
Interactions & Data Flows
2. RecordingCoordinator invokes AudioManager to capture audio.
3. AudioManager streams audio data to RecordingCoordinator.
4. On stop, RecordingCoordinator forwards audio to TranscriptionManager.
5. TranscriptionManager retrieves API key from Keychain → HTTPS POST to Whisper API → receives transcript.
6. TranscriptionManager passes text back to RecordingCoordinator → triggers TextInjection via accessibility APIs.
7. Logger records each step (start/stop, API call, errors).
Architectural patterns & design principles
• Event-driven, MVC/MVVM-style separation:
– View (SwiftUI views) ←→ Controller/Coordinator (RecordingCoordinator) ←→ Model/Service (AudioManager, TranscriptionManager).
• Single process, modular manager classes.
• Dependency inversion: managers expose protocols/interfaces (e.g., audio, transcription).
• Secure by design: Keychain for secrets, no local audio caching.