Transcription History
Relevant source files
The following files were used as context for generating this wiki page:- VoiceInk/Views/TranscriptionHistoryView.swift
- VoiceInk/Models/Transcription.swift
- VoiceInk/Services/VoiceInkCSVExportService.swift
- VoiceInk/Views/Metrics/PerformanceAnalysisView.swift
- Whisper/WhisperState.swift
- VoiceInk/Services/AudioFileTranscriptionManager.swift
- VoiceInk/Views/Settings/SettingsView.swift
The Transcription History system provides a persistent, searchable, and manageable log of all transcriptions created within the VoiceInk application. It serves as the central repository for users to review, analyze, and export their past voice-to-text sessions. The entire feature is built using SwiftUI and leverages the SwiftData framework for data persistence.
Users can interact with their history through the TranscriptionHistoryView, which offers functionalities like full-text search, bulk selection, deletion, performance analysis, and CSV export. Each entry in the history is represented by a Transcription object, which stores not only the text but also rich metadata about the transcription process.
Data Model
The core of the history feature is the Transcription data model, which is managed by SwiftData. This model captures all relevant details of a single transcription event.
Sources: VoiceInk/Models/Transcription.swift
Transcription Entity Relationship
The diagram below shows the schema for the Transcription entity.
Fields
The table below details the properties of the Transcription model.
| Field | Type | Description |
|---|---|---|
id | UUID | A unique identifier for the transcription record. |
text | String | The original, raw transcribed text. |
enhancedText | String? | The AI-enhanced version of the transcript, if applicable. |
timestamp | Date | The date and time when the transcription record was created. |
duration | TimeInterval | The duration of the original audio recording in seconds. |
audioFileURL | String? | A string representation of the URL to the saved audio file. |
transcriptionModelName | String? | The display name of the model used for transcription (e.g., "Whisper Base"). |
aiEnhancementModelName | String? | The name of the AI model used for enhancement (e.g., "GPT-4"). |
promptName | String? | The name of the prompt template used for AI enhancement. |
transcriptionDuration | TimeInterval? | The time taken to perform the initial transcription. |
enhancementDuration | TimeInterval? | The time taken for the AI enhancement step. |
aiRequestSystemMessage | String? | The system message sent to the AI service for enhancement. |
aiRequestUserMessage | String? | The user message (containing the transcript) sent for enhancement. |
powerModeName | String? | The name of the active Power Mode, if any. |
powerModeEmoji | String? | The emoji of the active Power Mode, if any. |
transcriptionStatus | String? | The status of the transcription (pending, completed, failed). |
Sources: VoiceInk/Models/Transcription.swift:11-30
User Interface (TranscriptionHistoryView)
The TranscriptionHistoryView is the main user-facing component for the history feature. It provides a scrollable list of past transcriptions with support for search, selection, and various actions.
Sources:- VoiceInk/Views/TranscriptionHistoryView.swift
Key UI Components
- Search Bar: A text field that allows users to filter transcriptions by searching the content of
textandenhancedText. - Transcription List: A
LazyVStackthat displaysTranscriptionCardviews for each record. It uses cursor-based pagination to efficiently handle large histories. - Selection Toolbar: A toolbar that appears at the bottom of the view when one or more transcriptions are selected, providing access to bulk actions.
- Empty State: A view that is displayed when no transcriptions match the search criteria or when the history is empty.
Data Fetching and Pagination
The view implements a cursor-based pagination strategy to load data in batches, ensuring good performance even with a large number of transcription records.
- Initial Load:
loadInitialContentfetches the first page ofpageSize(20) items, sorted by timestamp in descending order. - Loading More: When the user scrolls to the end and clicks "Load More",
loadMoreContentis triggered. It uses thetimestampof the last displayed item as a cursor to fetch the next page. - Dynamic Refresh: The view observes changes to the most recent transcription. If a new transcription is created while the view is visible, it automatically resets and reloads the list to show the latest entry.
The following flowchart illustrates the pagination logic.
Core Functionality
Transcription Creation and Persistence
New Transcription objects are created and persisted whenever a recording is processed. This process is handled by services like WhisperState and AudioFileTranscriptionManager.
The sequence diagram below shows how a new transcription is created by AudioFileTranscriptionManager and saved to the ModelContext, which makes it available to TranscriptionHistoryView.
Deletion
Users can delete individual or multiple transcriptions. The deletion logic ensures that both the SwiftData record and the associated audio file on disk are removed.
// From TranscriptionHistoryView.swift
private func deleteTranscription(_ transcription: Transcription) {
// First delete the audio file if it exists
if let urlString = transcription.audioFileURL,
let url = URL(string: urlString) {
try? FileManager.default.removeItem(at: url)
}
modelContext.delete(transcription)
// ... UI update logic ...
}
Sources: VoiceInk/Views/TranscriptionHistoryView.swift:270-286
Bulk Actions
When one or more items are selected, a toolbar provides the following actions:
| Action | Description | Implementation |
|---|---|---|
| Analyze | Opens the PerformanceAnalysisView to display statistics about the selected transcriptions. | Presents a sheet with PerformanceAnalysisView(transcriptions: Array(selectedTranscriptions)). |
| Export | Exports the selected transcriptions to a CSV file using VoiceInkCSVExportService. | Calls exportService.exportTranscriptionsToCSV(transcriptions: Array(selectedTranscriptions)). |
| Delete | Deletes all selected transcriptions and their associated audio files. | Calls deleteSelectedTranscriptions(), which iterates through the selection and deletes each item. |
| Select/Deselect All | Selects all transcriptions matching the current search filter or deselects all. | The selectAllTranscriptions function fetches all matching items from SwiftData and adds them to the selection set. |
Sources: VoiceInk/Views/TranscriptionHistoryView.swift:150-184
Integrated Features
CSV Export
The VoiceInkCSVExportService is responsible for converting a list of Transcription objects into a CSV formatted string and prompting the user to save the file.
Sources: VoiceInk/Services/VoiceInkCSVExportService.swift
The generated CSV file includes the following columns:
Original TranscriptEnhanced TranscriptEnhancement ModelPrompt NameTranscription ModelPower ModeEnhancement TimeTranscription TimeTimestampDuration
Sources: VoiceInk/Services/VoiceInkCSVExportService.swift:20-33
Performance Analysis
From the history view, users can launch the PerformanceAnalysisView for a set of selected transcriptions. This view provides insights into transcription and enhancement performance.
The analysis logic is encapsulated in the static analyze function within PerformanceAnalysisView, which calculates metrics for transcription and enhancement models.
Automatic Cleanup
While the service implementation is not detailed in the provided files, the settings UI (SettingsView.swift) includes an AudioCleanupSettingsView. This indicates that the application contains a feature for automatically managing and deleting old transcription history and audio files based on user-configured rules (e.g., age or total count).