Model Management
Relevant source files
The following files were used as context for generating this wiki page:- VoiceInk/Whisper/WhisperState+LocalModelManager.swift
- VoiceInk/Views/AI Models/ModelManagementView.swift
- VoiceInk/Services/CloudTranscription/CustomModelManager.swift
- VoiceInk/Models/TranscriptionModel.swift
- VoiceInk/Whisper/WhisperState.swift
- VoiceInk/Whisper/WhisperState+Parakeet.swift
- VoiceInk/Views/Onboarding/OnboardingModelDownloadView.swift
The Model Management system is a core component of VoiceInk, responsible for the entire lifecycle of transcription models. It provides a unified interface for handling various types of models, including pre-defined local and cloud models, user-imported local models, and user-configured custom cloud endpoints. The system manages discovery, downloading, storage, selection, and deletion of models, ensuring a flexible and powerful transcription experience.
This system is primarily orchestrated by WhisperState, which acts as the central hub for model-related state and operations. It interacts with specialized managers for different model providers and is surfaced to the user through the ModelManagementView.
Core Concepts and Data Structures
The system is built around a protocol-oriented design, allowing for different types of transcription models to be treated uniformly.
Sources: VoiceInk/Models/TranscriptionModel.swift, VoiceInk/Whisper/WhisperState+LocalModelManager.swift, VoiceInk/Services/CloudTranscription/CustomModelManager.swift
TranscriptionModel Protocol
The TranscriptionModel protocol is the cornerstone of the model management system. It defines a common interface for all transcription models, regardless of their provider or location.
// Source: VoiceInk/Models/TranscriptionModel.swift:13-20
protocol TranscriptionModel: Identifiable, Hashable {
var id: UUID { get }
var name: String { get }
var displayName: String { get }
var description: String { get }
var provider: ModelProvider { get }
var isMultilingualModel: Bool { get }
var supportedLanguages: [String: String] { get }
}
Sources: VoiceInk/Models/TranscriptionModel.swift:13-20
Model Implementations
Various structs conform to the TranscriptionModel protocol, each representing a different kind of model.
The following class diagram illustrates the relationship between the TranscriptionModel protocol and its concrete implementations.
ModelProvider Enum
This enum categorizes models based on their source and execution environment. It is used for filtering in the UI and for routing transcription tasks to the correct service.
// Source: VoiceInk/Models/TranscriptionModel.swift:4-12
enum ModelProvider: String, Codable, Hashable, CaseIterable {
case local = "Local"
case parakeet = "Parakeet"
case groq = "Groq"
case elevenLabs = "ElevenLabs"
case deepgram = "Deepgram"
case mistral = "Mistral"
case gemini = "Gemini"
case soniox = "Soniox"
case custom = "Custom"
case nativeApple = "Native Apple"
}
Sources: VoiceInk/Models/TranscriptionModel.swift:4-12
WhisperModel Struct
This struct represents a local whisper.cpp model that has been downloaded to the device. It contains paths to the model's binary file and its optional Core ML-accelerated components.
| Property | Type | Description |
|---|---|---|
id | UUID | A unique identifier for the instance. |
name | String | The base name of the model (e.g., "ggml-base.en"). |
url | URL | The local file URL for the model's .bin file. |
coreMLEncoderURL | URL? | The local URL for the unzipped .mlmodelc directory. |
isCoreMLDownloaded | Bool | A computed property that checks if coreMLEncoderURL is not nil. |
downloadURL | String | The remote URL for downloading the .bin file from Hugging Face. |
coreMLZipDownloadURL | String? | The remote URL for the Core ML encoder's .zip file. Nil for quantized models. |
Sources: VoiceInk/Whisper/WhisperState+LocalModelManager.swift:8-34
Local Model Management (whisper.cpp)
This subsystem, primarily defined in WhisperState+LocalModelManager.swift, handles ggml format models that run locally on the device using whisper.cpp.
Storage
Local models are stored in a dedicated directory within the application's support folder: ~/Library/Application Support/com.prakashjoshipax.VoiceInk/WhisperModels. This directory is created automatically if it doesn't exist.
Sources: VoiceInk/Whisper/WhisperState.swift:88-90, VoiceInk/Whisper/WhisperState+LocalModelManager.swift:42-48
Downloading Models
The application can download pre-defined whisper.cpp models from Hugging Face. The process handles both the main model file (.bin) and an optional, performance-enhancing Core ML model.
The download flow is as follows:
- A download is initiated for a
LocalModel. - The main
.binfile is downloaded with progress tracking. - If the model supports Core ML (i.e., it's not a quantized model like
q5orq8), the corresponding-encoder.mlmodelc.zipfile is also downloaded. - The Core ML zip file is unzipped into the models directory.
- The zip file is deleted, and the path to the new
.mlmodelcdirectory is stored. - The
availableModelsarray inWhisperStateis updated with the newWhisperModelstruct.
This diagram shows the download and setup process for a local model with Core ML support.
Progress for each download component (main and Core ML) is tracked in the downloadProgress dictionary within WhisperState, and the UI is updated via the DownloadProgressView.
Sources: VoiceInk/Whisper/WhisperState+LocalModelManager.swift:159-167, 431-441
Importing Custom Local Models
Users can import their own ggml-compatible .bin models.
- The user selects a
.binfile via anNSOpenPanel. - The
importLocalModelfunction is called. - The function checks if a model with the same name already exists. If so, it aborts and notifies the user.
- The selected file is copied into the
WhisperModelsdirectory. - A new
WhisperModelis created and appended to theavailableModelslist. - An
ImportedLocalModelrepresentation is added toallAvailableModelsto make it selectable in the UI.
Deleting Models
When a user deletes a local model, the deleteModel function performs the following actions:
- Deletes the main
.binmodel file. - Deletes the associated Core ML directory (
-encoder.mlmodelc) if it exists. - Removes the model from the
availableModelsarray. - If the deleted model was the currently selected one, it resets
currentTranscriptionModeland related state.
Sources: VoiceInk/Whisper/WhisperState+LocalModelManager.swift:348-380
Parakeet Model Management
Parakeet models are managed via a separate mechanism provided by the FluidAudio library.
- Download: The
downloadParakeetModelfunction inWhisperState+Parakeet.swiftusesAsrModels.downloadAndLoadto fetch and cache the model. A timer simulates intermediate progress as the library does not provide fine-grained progress updates. - Status Tracking: Download completion is tracked via a
Boolflag inUserDefaultswith a key likeParakeetModelDownloaded_<model_name>. - Deletion:
deleteParakeetModelremoves the model's cache directory and updates theUserDefaultsflag. The cache directory is located viaAsrModels.defaultCacheDirectory(for: version).
Sources: VoiceInk/Whisper/WhisperState+Parakeet.swift
Custom Cloud Model Management
VoiceInk allows users to configure and use their own cloud-based transcription endpoints. This is managed by the CustomModelManager singleton.
CustomModelManager
This class is responsible for all CRUD (Create, Read, Update, Delete) operations for CustomCloudModel objects.
- Persistence: Custom model configurations are encoded to JSON and stored in
UserDefaultsunder the keycustomCloudModels. - State: The manager publishes an array of
customModels, which the UI observes. - Validation: It provides methods (
validateModel) to ensure that new or updated models have valid and unique properties (name, display name, API endpoint, etc.) before saving.
Sources: VoiceInk/Services/CloudTranscription/CustomModelManager.swift
Adding a Custom Model
This sequence diagram shows the flow of adding a new custom cloud model.
User Interface
The ModelManagementView is the primary user-facing component for managing all transcription models.
- Filtering: A
ModelFilterenum allows the user to view models by category:Recommended,Local,Cloud, andCustom. - Model Display:
ModelCardRowViewis used to display each model, showing its status (downloaded, current) and providing actions like download, delete, and set as default. - State Observation: The view observes the
WhisperStateobject to get the list of all models, their download status, and the currently selected default model. It also observesCustomModelManager.sharedto display custom cloud models. - Actions: The view provides buttons and context menus to trigger all management actions, such as downloading, deleting, importing, and setting a model as the default.