Import and Export Service
Relevant source files
The following files were used as context for generating this wiki page:
- VoiceInk/Services/ImportExportService.swift
- VoiceInk/Services/VoiceInkCSVExportService.swift
- VoiceInk/Views/Settings/SettingsView.swift
- VoiceInk/Whisper/WhisperState+LocalModelManager.swift
- VoiceInk/Services/AIEnhancementService.swift
- VoiceInk/PowerMode/PowerModeConfigView.swift
- VoiceInk/Views/AI Models/ModelManagementView.swift
The Import and Export Service in VoiceInk provides robust functionality for data management, allowing users to back up their application settings, restore them from a file, and export their transcription history for analysis. This system is composed of two main services: ImportExportService for handling JSON-based settings and VoiceInkCSVExportService for exporting transcription data into a CSV format.
Additionally, the application supports importing local ggml model files (.bin) through the WhisperState manager, which complements the settings import by allowing users to add custom, self-hosted transcription models. These features are primarily accessed through the "Data Management" section in the app's settings and the "AI Models" view.
Sources: VoiceInk/Services/ImportExportService.swift, VoiceInk/Services/VoiceInkCSVExportService.swift, VoiceInk/Views/Settings/SettingsView.swift:302-342, VoiceInk/Whisper/WhisperState+LocalModelManager.swift:353-397
Settings Import and Export
This functionality, managed by the singleton ImportExportService, allows users to save a comprehensive snapshot of their configuration to a JSON file and later restore it. This is useful for creating backups or migrating settings between devices.
Sources: VoiceInk/Services/ImportExportService.swift:42-45
Exported Data Structure
The settings are encoded into a single JSON object defined by the VoiceInkExportedSettings struct. This structure encapsulates all user-configurable aspects of the application, except for sensitive data like API keys.
Sources: VoiceInk/Services/ImportExportService.swift:29-38
The following diagram shows the relationship between the main export structure and its nested GeneralSettings.
Diagram illustrating the data structures used for settings export.
VoiceInkExportedSettings
This is the root object for the exported JSON file.
| Property | Type | Description |
|---|---|---|
version | String | The app version at the time of export. Used to check for compatibility during import. |
customPrompts | [CustomPrompt] | User-defined AI enhancement prompts. Predefined prompts are excluded. |
powerModeConfigs | [PowerModeConfig] | All user-configured Power Modes. |
dictionaryItems | [DictionaryItem]? | Custom dictionary entries for spelling correction. |
wordReplacements | [String: String]? | User-defined word replacement rules. |
generalSettings | GeneralSettings? | A nested object containing general application preferences. |
customEmojis | [String]? | User-added custom emojis. |
customCloudModels | [CustomCloudModel]? | User-defined custom cloud models. |
Sources: VoiceInk/Services/ImportExportService.swift:29-38, VoiceInk/Services/ImportExportService.swift:85-87, VoiceInk/PowerMode/PowerModeConfigView.swift:598-617
GeneralSettings
This struct aggregates various application-level settings.
| Property | Type | Description |
|---|---|---|
toggleMiniRecorderShortcut | KeyboardShortcuts.Shortcut? | The primary hotkey for toggling the recorder. |
toggleMiniRecorderShortcut2 | KeyboardShortcuts.Shortcut? | The secondary hotkey for toggling the recorder. |
retryLastTranscriptionShortcut | KeyboardShortcuts.Shortcut? | The hotkey to re-transcribe the last audio. |
selectedHotkey1RawValue | String? | The raw value of the primary hotkey modifier (e.g., Right Command). |
selectedHotkey2RawValue | String? | The raw value of the secondary hotkey modifier. |
launchAtLoginEnabled | Bool? | Whether the app starts at system login. |
isMenuBarOnly | Bool? | Whether the Dock icon is hidden. |
useAppleScriptPaste | Bool? | The selected paste method. |
recorderType | String? | The chosen recorder style ("notch" or "mini"). |
isTranscriptionCleanupEnabled | Bool? | Setting for automatic transcription deletion. |
transcriptionRetentionMinutes | Int? | Retention period for transcriptions if cleanup is enabled. |
isAudioCleanupEnabled | Bool? | Setting for automatic audio file deletion. |
audioRetentionPeriod | Int? | Retention period for audio files if cleanup is enabled. |
isSoundFeedbackEnabled | Bool? | Whether audio cues for recording are enabled. |
isSystemMuteEnabled | Bool? | Whether system audio is muted during recording. |
isPauseMediaEnabled | Bool? | Whether media playback is paused during recording. |
isTextFormattingEnabled | Bool? | Whether text formatting is enabled. |
isExperimentalFeaturesEnabled | Bool? | Whether experimental features are enabled. |
Sources: VoiceInk/Services/ImportExportService.swift:7-27, VoiceInk/Services/ImportExportService.swift:102-124
Export Process
The export process is initiated from the SettingsView. It gathers all relevant configurations from various managers and services, encodes them into a JSON file, and presents a save panel to the user.
This diagram shows the flow of exporting user settings to a JSON file.
Sources: VoiceInk/Views/Settings/SettingsView.swift:328-338, VoiceInk/Services/ImportExportService.swift:80-155
Import Process
The import process overwrites all existing settings with the data from a selected JSON file. It includes a version check to warn the user about potential incompatibilities if the file is from a different app version. After a successful import, an alert recommends restarting the app and reconfiguring API keys.
This diagram illustrates the sequence of events during the settings import process.
Sources: VoiceInk/Views/Settings/SettingsView.swift:314-325, VoiceInk/Services/ImportExportService.swift:158-294
Transcription History Export (CSV)
The VoiceInkCSVExportService allows users to export their transcription history into a structured CSV file. This is useful for data analysis, performance tracking, or external record-keeping.
Sources: VoiceInk/Services/VoiceInkCSVExportService.swift
CSV File Structure
The generateCSV method creates a CSV string with a predefined header row. Each subsequent row corresponds to a single Transcription record.
| Column Header | Description |
|---|---|
Original Transcript | The raw text from the transcription model. |
Enhanced Transcript | The text after being processed by an AI enhancement prompt, if applicable. |
Enhancement Model | The name of the AI model used for enhancement. |
Prompt Name | The name of the enhancement prompt used. |
Transcription Model | The name of the model used for the initial transcription. |
Power Mode | The name and emoji of the active Power Mode. |
Enhancement Time | The duration of the AI enhancement process in seconds. |
Transcription Time | The duration of the transcription process in seconds. |
Timestamp | The ISO 8601 formatted date and time of the transcription. |
Duration | The duration of the original audio recording in seconds. |
Sources: VoiceInk/Services/VoiceInkCSVExportService.swift:23-37
Export Flow
The process is straightforward: generate the CSV content from the provided transcription data and use an NSSavePanel to write it to a file. Special characters like commas and newlines within text fields are properly escaped to maintain CSV integrity.
This diagram outlines the process of generating and saving a CSV export of transcription history.
Sources: VoiceInk/Services/VoiceInkCSVExportService.swift:7-42
Local Model Import
Separate from settings import, VoiceInk allows users to import their own local ggml Whisper models. This feature is handled within the WhisperState manager and is accessible from the "AI Models" screen.
Sources: VoiceInk/Views/AI Models/ModelManagementView.swift:214-228
Import Flow
The user selects a .bin file, which is then copied into the application's model directory. The system checks for name collisions to prevent overwriting existing models.
This diagram shows the workflow for importing a user-provided local model file.
Sources: VoiceInk/Whisper/WhisperState+LocalModelManager.swift:353-397
Conclusion
The import and export capabilities of VoiceInk are essential for user data management and portability. The JSON-based settings backup ensures that complex user configurations, including custom prompts and Power Modes, can be easily saved and restored. The CSV export provides a valuable tool for users to analyze their transcription data externally. Finally, the ability to import local models offers advanced users greater flexibility and control over their transcription environment. Together, these features enhance the usability and power of the application.