Application Architecture Overview
Relevant source files
The following files were used as context for generating this wiki page:
- VoiceInk/VoiceInk.swift
- VoiceInk/Whisper/WhisperState.swift
- VoiceInk/PowerMode/PowerModeView.swift
- VoiceInk/Services/SystemInfoService.swift
- VoiceInk/Whisper/WhisperState+LocalModelManager.swift
- VoiceInk/Services/ImportExportService.swift
- BUILDING.md
- VoiceInk/PowerMode/PowerModeConfigView.swift
- VoiceInk/Models/PromptTemplates.swift
VoiceInk is a native macOS application built with SwiftUI that provides fast, local voice-to-text transcription. The architecture is designed to be modular, leveraging a combination of modern Apple frameworks and external libraries to deliver its core functionality. The system is centered around a main application entry point that initializes and manages a suite of services responsible for transcription, UI management, hotkey handling, and AI-powered text enhancement.
The application's core transcription capability is powered by the whisper.cpp library, which is integrated as a pre-compiled XCFramework. Data persistence for transcription history is handled by SwiftData, while user preferences and configurations are stored using UserDefaults and @AppStorage. The UI is composed of SwiftUI views, with state management handled through @StateObject and @EnvironmentObject property wrappers to ensure a reactive and consistent user experience.
Core Components
The application is composed of several key components that work together to provide the full feature set. The main VoiceInkApp struct serves as the composition root, where all major services and state managers are instantiated and injected into the SwiftUI environment.
Sources: VoiceInk/VoiceInk.swift:10-103
Application Entry Point & Service Initialization
The application life cycle begins in VoiceInkApp. Its init() method is responsible for setting up the entire dependency graph. Key services are created as @StateObject instances and passed down the view hierarchy via .environmentObject().
This diagram illustrates the main services and their relationships as initialized in VoiceInkApp.
Sources: VoiceInk/VoiceInk.swift:49-93
The startup sequence involves initializing these services and then presenting either the OnboardingView or the main ContentView based on the hasCompletedOnboarding flag.
UI Layer (SwiftUI)
The user interface is built entirely with SwiftUI. The main application window is managed by a WindowGroup, and a MenuBarExtra provides access to key functions from the system menu bar.
ContentView: The main interface after onboarding, which likely contains the navigation to different feature sections.OnboardingView: A guided setup flow for new users, covering permissions and initial model download.SettingsView: A comprehensive view for configuring application settings, including hotkeys, recorder style, and data management.PowerModeView: Manages context-aware configurations for different applications and websites.LicenseManagementView: Handles software licensing and activation.MetricsContent: Displays usage statistics and performance metrics.
State is managed declaratively using @State, @StateObject, @EnvironmentObject, and @AppStorage to ensure the UI reflects the underlying application state.
Sources: VoiceInk/VoiceInk.swift:106-160, VoiceInk/Views/Settings/SettingsView.swift, VoiceInk/PowerMode/PowerModeView.swift, VoiceInk/Views/LicenseManagementView.swift, VoiceInk/Views/Metrics/MetricsContent.swift
Data Persistence (SwiftData)
VoiceInk uses SwiftData to store transcription history.
- Schema: A single
Transcriptionmodel is defined in the schema. - Storage Location: The
ModelContaineris explicitly configured to store the database in the user's Application Support directory at~/Library/Application Support/com.prakashjoshipax.VoiceInk/default.store. This ensures data is stored in a conventional and user-accessible location.
// From VoiceInk/VoiceInk.swift
let schema = Schema([
Transcription.self
])
// Create app-specific Application Support directory URL
let appSupportURL = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
.appendingPathComponent("com.prakashjoshipax.VoiceInk", isDirectory: true)
// ...
// Configure SwiftData to use the conventional location
let storeURL = appSupportURL.appendingPathComponent("default.store")
let modelConfiguration = ModelConfiguration(schema: schema, url: storeURL)
container = try ModelContainer(for: schema, configurations: [modelConfiguration])
Sources: VoiceInk/VoiceInk.swift:33-48
Transcription Engine
The core of VoiceInk is its transcription engine, which revolves around the WhisperState class and its integration with the whisper.cpp library.
WhisperState
WhisperState is an ObservableObject that acts as the central coordinator for all transcription-related activities. Its responsibilities include:
- Managing the recording state (
idle,recording,transcribing). - Handling audio input and processing.
- Loading, unloading, and managing local and cloud transcription models.
- Interacting with the
WhisperContextfrom thewhisper.cppframework to perform transcription. - Storing the resulting
Transcriptionobject in the SwiftDataModelContainer. - Triggering AI enhancement via
AIEnhancementServiceafter transcription.
Sources: VoiceInk/Whisper/WhisperState.swift
Transcription Flow
The following sequence diagram shows a typical transcription process initiated by a user hotkey press.
Model Management
Model management is a key function handled by an extension on WhisperState. The application supports both local ggml models and cloud-based transcription services.
- Local Models: Models are stored as
.binfiles in the application's models directory. The app can download predefined models from Hugging Face or import user-provided.binfiles. - Core ML: For non-quantized local models, the app can download and use a Core ML version of the encoder for better performance on Apple Silicon.
WhisperModelStruct: This struct represents a downloaded local model, containing its name, local file URL, and an optional URL for its Core ML encoder.
The download process for a local model, including its Core ML variant, is as follows:
Feature Modules
Power Modes
Power Modes provide context-aware configurations that are automatically applied based on the active application or website.
PowerModeManager: A singleton that manages the list ofPowerModeConfigobjects. It is responsible for loading, saving, adding, updating, and removing configurations. It also determines the active configuration based on the current context provided byActiveWindowService.PowerModeConfig: A struct defining a single power mode. It includes a name, emoji, trigger conditions (app bundle IDs or website URLs), and overrides for settings like transcription model, language, AI enhancement prompt, and more.ConfigurationView: The SwiftUI view used to add or edit aPowerModeConfig. It provides UI for setting all the properties of a power mode.
Sources: VoiceInk/PowerMode/PowerModeView.swift, VoiceInk/PowerMode/PowerModeConfigView.swift:1-550
AI Enhancement & Prompts
After a raw transcription is generated, it can be passed to the AIEnhancementService for post-processing.
AIEnhancementService: This service orchestrates the enhancement process. It takes the raw text and an activeCustomPromptto generate a cleaned-up or reformatted version of the text using a configured AI provider.AIService: Manages connections and API calls to various AI providers (Groq, OpenAI, etc.).PromptTemplates: A set of predefinedTemplatePromptstructs that provide default enhancement instructions for common use cases like "Chat", "Email", and "Rewrite". Users can also create their own custom prompts.
Sources: VoiceInk/VoiceInk.swift:78-81, VoiceInk/Models/PromptTemplates.swift:1-118
Settings Import/Export
The ImportExportService provides functionality to back up and restore user settings.
VoiceInkExportedSettings: A codable struct that defines the schema for the exported JSON file. It encapsulates custom prompts, power modes, dictionary items, and a wide range of general application settings.- Export Process: Gathers all relevant configurations from their respective managers (
PowerModeManager,AIEnhancementService,UserDefaults,KeyboardShortcuts), encodes them into theVoiceInkExportedSettingsstruct, and saves them as a JSON file. - Import Process: Reads a JSON file, decodes it into a
VoiceInkExportedSettingsobject, and overwrites the current application settings with the imported data.
The following settings are included in the export:
| Category | Data Included |
|---|---|
| Prompts | All user-created custom prompts. |
| Power Modes | All PowerModeConfig objects and their order. |
| Dictionary | Custom spellings and word replacements. |
| Shortcuts | Hotkey selections and custom keyboard shortcuts. |
| General | Launch at login, recorder style, paste method, etc. |
| Custom Models | User-defined custom cloud models. |
Sources: VoiceInk/Services/ImportExportService.swift:8-41, VoiceInk/Services/ImportExportService.swift:58-129
Conclusion
The VoiceInk application architecture is a well-structured, service-oriented system built on modern Apple technologies. By centralizing state management in observable objects like WhisperState and using dependency injection at the application's root, it maintains a clear separation of concerns. The core transcription logic is effectively encapsulated by interfacing with the external whisper.cpp library, while feature modules like Power Modes and AI Enhancement are built as distinct, manageable services. This modular design facilitates maintainability and the potential for future expansion.