Transcription Services Overview
Relevant source files
The following files were used as context for generating this wiki page:
- VoiceInk/Whisper/WhisperState.swift
- VoiceInk/Services/AudioFileTranscriptionManager.swift
- VoiceInk/Services/AudioFileTranscriptionService.swift
- VoiceInk/Models/Transcription.swift
- VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/GroqTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/ElevenLabsTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/OpenAICompatibleTranscriptionService.swift
- VoiceInk/Services/NativeAppleTranscriptionService.swift
- VoiceInk/Services/ParakeetTranscriptionService.swift
- VoiceInk/Models/PromptTemplates.swift
- VoiceInk/Services/VoiceInkCSVExportService.swift
- VoiceInk/Views/Metrics/PerformanceAnalysisView.swift
- BUILDING.md
- README.md
The transcription system is the core of the VoiceInk application, responsible for converting spoken audio into text. It is designed with a modular architecture to support a wide variety of transcription providers, including local, offline models for privacy and speed, as well as various cloud-based services for potentially higher accuracy or specialized features. This architecture allows users to choose the best model for their needs.
The system manages the entire lifecycle of a transcription, from audio capture and processing to model inference, text formatting, optional AI enhancement, and final output. It also handles data persistence, performance metrics, and data export functionalities.
Core Architecture
The transcription system is orchestrated by several key components that manage state, delegate tasks, and process data. The central manager is WhisperState, which handles the user-facing recording state machine and initiates the transcription process.
The diagram below illustrates the high-level architecture of the transcription services.
Key Components
| Component | Description | Source File |
|---|---|---|
WhisperState | The main state machine for the application. Manages recording state (idle, recording, transcribing), handles user input via toggleRecord(), and orchestrates the live transcription flow. | VoiceInk/Whisper/WhisperState.swift |
AudioTranscriptionManager | Manages the transcription of pre-existing audio files dropped into the application. It follows a similar flow to WhisperState but for non-live audio. | VoiceInk/Services/AudioFileTranscriptionManager.swift |
AudioFileTranscriptionService | Handles re-transcribing an existing audio recording with a different model. | VoiceInk/Services/AudioFileTranscriptionService.swift |
TranscriptionService (Protocol) | A protocol that defines the transcribe method, ensuring a consistent interface for all transcription providers. | VoiceInk/Services/ParakeetTranscriptionService.swift:9 |
AIEnhancementService | An optional service that takes the transcribed text and uses a secondary AI model (e.g., GPT) to clean it up, reformat it, or apply a specific prompt. | VoiceInk/Whisper/WhisperState.swift:252-276 |
Transcription (Model) | A SwiftData model used to persist all information about a transcription session, including the text, audio file path, durations, and models used. | VoiceInk/Models/Transcription.swift |
Transcription Flow
The primary transcription process begins when the user initiates a recording. The WhisperState class manages this flow from start to finish.
The following sequence diagram shows the typical lifecycle of a live transcription:
Transcription Providers
VoiceInk supports multiple transcription backends, categorized as Local, Parakeet, Native Apple, and Cloud. The selection is determined by the provider property of the currently selected TranscriptionModel.
Sources: VoiceInk/Whisper/WhisperState.swift:211-220, VoiceInk/Services/AudioFileTranscriptionManager.swift:98-103
Local (whisper.cpp)
This provider uses a local inference engine for OpenAI's Whisper models, powered by the whisper.cpp library. This is the primary offline, privacy-focused option.
- Implementation:
LocalTranscriptionService - Dependency: Requires a compiled
whisper.xcframeworkfrom thewhisper.cpprepository. - Process: The
LocalTranscriptionServiceis initialized byWhisperStateand uses aWhisperContextto run inference on the audio file.
Sources: BUILDING.md:11-15, VoiceInk/Whisper/WhisperState.swift:75
Parakeet
This is another local provider that uses the Parakeet ASR models, managed via the FluidAudio library.
- Implementation:
ParakeetTranscriptionService - Process: It loads the appropriate Parakeet model version (
.v2or.v3) and uses anAsrManagerto perform transcription. It also supports Voice Activity Detection (VAD) to process only speech segments from longer audio files, which is enabled by default for audio >= 20 seconds.
Sources: VoiceInk/Services/ParakeetTranscriptionService.swift
Native Apple
This provider leverages Apple's built-in speech recognition framework, available on macOS 26 (Tahoe) and later.
- Implementation:
NativeAppleTranscriptionService - Process: It uses the
SpeechAnalyzerandSpeechTranscriberAPIs. The service maps the app's simple language codes (e.g., "en") to Apple's BCP-47 locale identifiers (e.g., "en-US"). It checks if the required language assets are installed and can trigger a system download if they are not. - Note: This feature is conditionally compiled and requires the
ENABLE_NATIVE_SPEECH_ANALYZERflag.
Sources: VoiceInk/Services/NativeAppleTranscriptionService.swift
Cloud Services
For users who prefer cloud-based transcription, VoiceInk integrates with several third-party APIs. The CloudTranscriptionService acts as a dispatcher, delegating the request to the appropriate service based on the selected model's provider type. All cloud services require an API key stored in UserDefaults.
The following cloud providers are supported:
| Provider | Service Class | UserDefaults API Key |
|---|---|---|
| Groq | GroqTranscriptionService | GROQAPIKey |
| Soniox | SonioxTranscriptionService | SonioxAPIKey |
| Gemini | GeminiTranscriptionService | GeminiAPIKey |
| ElevenLabs | ElevenLabsTranscriptionService | ElevenLabsAPIKey |
| Custom (OpenAI-Compatible) | OpenAICompatibleTranscriptionService | Stored in the CustomCloudModel object. |
Sources: VoiceInk/Services/CloudTranscription/GroqTranscriptionService.swift:42, VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift:19, VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift:80, VoiceInk/Services/CloudTranscription/ElevenLabsTranscriptionService.swift:36, VoiceInk/Services/CloudTranscription/OpenAICompatibleTranscriptionService.swift:11
Soniox Transcription Flow
The Soniox service uses a multi-step asynchronous process involving file upload, transcription job creation, status polling, and finally, fetching the result.
This diagram shows the asynchronous transcription flow for the Soniox service.
Sources: VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift:6-15
OpenAI-Compatible Flow
Providers like Groq and custom endpoints use a simpler, single-request flow compatible with the OpenAI API specification.
- Implementation:
GroqTranscriptionService,OpenAICompatibleTranscriptionService - Process: A
multipart/form-datarequest is constructed containing the audio file, model name, and other parameters like language and prompt. The request is sent to the provider's/audio/transcriptionsendpoint, and the response directly contains the transcribed text in JSON format.
Sources: VoiceInk/Services/CloudTranscription/GroqTranscriptionService.swift:10-33, VoiceInk/Services/CloudTranscription/OpenAICompatibleTranscriptionService.swift:10-33
Data Model and Persistence
All transcription results are stored in a local SwiftData database using the Transcription model. This allows for history, metrics, and re-transcription capabilities.
Transcription Model
The diagram below shows the structure of the Transcription entity.
Data Export
The application provides a utility to export transcription history to a CSV file. The VoiceInkCSVExportService generates a CSV string with detailed columns for each transcription record and prompts the user to save the file.
The exported columns include:
- Original Transcript
- Enhanced Transcript
- Enhancement Model
- Prompt Name
- Transcription Model
- Power Mode
- Enhancement Time
- Transcription Time
- Timestamp
- Duration
Sources: VoiceInk/Services/VoiceInkCSVExportService.swift:20-33
Post-Processing and Enhancement
After the initial transcription, the raw text goes through several optional processing steps to improve quality and formatting.
- Output Filtering:
TranscriptionOutputFilter.filter(text)is applied to clean up common transcription artifacts. - Text Formatting:
WhisperTextFormatter.format(text)applies standard text formatting rules ifIsTextFormattingEnabledis true. - Word Replacement:
WordReplacementService.shared.applyReplacements(to: text)substitutes user-defined words and phrases ifIsWordReplacementEnabledis true. - AI Enhancement: If enabled, the
AIEnhancementServicesends the formatted text to another AI model (like GPT) with a specific system prompt (e.g., "Email", "Chat") to transform the text. The available prompts are defined inPromptTemplates.swift.
Sources: VoiceInk/Whisper/WhisperState.swift:239-251, VoiceInk/Models/PromptTemplates.swift
Performance Analysis
The application includes a PerformanceAnalysisView to provide users with insights into the performance of different transcription and enhancement models. This view calculates and displays metrics based on the stored Transcription data.
Key metrics calculated:
- Total Transcripts: The total number of recordings.
- Average Processing Time: The average time taken by a model to process audio.
- Speed Factor (RTFx): The "Real-Time Factor," calculated as
totalAudioDuration / totalProcessingTime. This shows how much faster than real-time a transcription model is. - Average Enhancement Time: The average time taken for AI enhancement.
Sources: VoiceInk/Views/Metrics/PerformanceAnalysisView.swift:103-110, VoiceInk/Views/Metrics/PerformanceAnalysisView.swift:129-132
Conclusion
The transcription architecture in VoiceInk is robust, flexible, and extensible. By abstracting the transcription logic behind a common interface and using a central state manager, the system can easily integrate various local and cloud-based providers. This modularity provides users with a choice between privacy-first offline processing and the power of cloud APIs. The inclusion of post-processing, AI enhancement, and detailed performance analytics further enhances the utility and user experience of the core transcription feature.