Core Transcription Engine
Relevant source files
The following files were used as context for generating this wiki page:
- VoiceInk/Services/AudioFileTranscriptionManager.swift
- VoiceInk/Services/AudioFileTranscriptionService.swift
- VoiceInk/Whisper/WhisperState+LocalModelManager.swift
- VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift
- VoiceInk/Services/NativeAppleTranscriptionService.swift
- VoiceInk/Models/Transcription.swift
- VoiceInk/Views/Metrics/PerformanceAnalysisView.swift
- VoiceInk/Models/PromptTemplates.swift
- VoiceInk/Services/ParakeetTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift
The Core Transcription Engine is the central component of VoiceInk responsible for converting audio into text. It is a modular system designed to support multiple transcription providers, including local on-device models, various cloud-based services, and native Apple frameworks. The engine manages the entire lifecycle of a transcription task, from audio processing and provider selection to post-processing, AI enhancement, and data persistence.
This engine is orchestrated primarily by the AudioFileTranscriptionManager for new transcriptions and AudioFileTranscriptionService for re-transcribing existing audio. It integrates with the WhisperState for managing local models and delegates to specialized services for different providers, ensuring a flexible and extensible architecture. The final output is a structured Transcription object that captures not only the text but also rich metadata about the process.
Architecture Overview
The transcription engine is built around a set of services and managers that collaborate to process audio files. The AudioFileTranscriptionManager acts as the main entry point, delegating tasks to specific transcription services based on the user's selected model.
This diagram illustrates the high-level architecture and the relationships between the key components.
Transcription Workflow
The core workflow begins when an audio file URL is passed to the AudioFileTranscriptionManager. The manager coordinates a series of steps to produce a final transcription.
Processing Phases
The manager tracks its progress through a series of defined phases, which can be displayed to the user.
| Phase | Description |
|---|---|
idle | No active processing. |
loading | Loading the required transcription model into memory. |
processingAudio | Converting the input audio file into a standardized sample format. |
transcribing | The selected transcription service is converting audio samples to text. |
enhancing | The AIEnhancementService is processing the raw transcript. |
completed | The process is finished and the Transcription object is saved. |
| Sources: VoiceInk/Services/AudioFileTranscriptionManager.swift:30-48 |
Sequence of Operations
The following diagram shows the sequence of events during a typical transcription task managed by AudioFileTranscriptionManager.
A similar workflow exists in AudioFileTranscriptionService for re-transcribing audio, which reuses the same provider-specific services.
Sources: VoiceInk/Services/AudioFileTranscriptionService.swift:40-218
Transcription Providers
The engine supports multiple backends for transcription, categorized as local, cloud, or native. The selection is determined by the currentTranscriptionModel set in WhisperState.
Local Providers
Local providers run entirely on the user's machine, ensuring privacy and offline availability.
Whisper.cpp
- Service:
LocalTranscriptionService - Management: Model downloading, loading, and context management are handled by
WhisperStateand itsLocalModelManagerextension. - Models: Supports
.binfiles compatible withwhisper.cpp. It can download official models from Hugging Face or import user-provided files. Core ML-accelerated models are also supported and downloaded automatically if available. - Process:
WhisperStatedownloads and stores model files in theApplication Supportdirectory.loadModel()creates aWhisperContextfrom the selected.binfile.transcribe()inLocalTranscriptionServiceuses the context to process audio samples.
Sources: VoiceInk/Whisper/WhisperState+LocalModelManager.swift, VoiceInk/Services/AudioFileTranscriptionService.swift:57-58
Parakeet
- Service:
ParakeetTranscriptionService - Technology: Leverages the
FluidAudioframework. - Models: Uses its own
AsrManagerto load Parakeet models (.v2or.v3). - Features: Includes an optional Voice Activity Detection (VAD) step to segment speech from silence in audio files longer than 20 seconds, which can improve performance. This is enabled by the
IsVADEnableduser default.
Sources: VoiceInk/Services/ParakeetTranscriptionService.swift:1-83
Cloud Providers
Cloud providers offload the transcription work to external APIs. This requires an internet connection and API keys, which are stored in UserDefaults.
The CloudTranscriptionService acts as a facade, delegating to a specific service based on the model's provider type.
Soniox
- Service:
SonioxTranscriptionService - API Endpoint:
https://api.soniox.com/v1 - Authentication: Uses a Bearer token from the
SonioxAPIKeyinUserDefaults. - Workflow:
- Upload File:
POST /fileswith multipart/form-data. - Create Transcription:
POST /transcriptionswith thefile_idand model name. It also sends custom dictionary terms and language hints. - Poll Status:
GET /transcriptions/{id}periodically until status iscompleted. - Fetch Transcript:
GET /transcriptions/{id}/transcriptto retrieve the final text.
Sources: VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift:1-224
- Upload File:
Gemini
- Service:
GeminiTranscriptionService - API Endpoint:
https://generativelanguage.googleapis.com/v1beta/models/{model_name}:generateContent - Authentication: Uses an API key from
GeminiAPIKeyinUserDefaultssent in thex-goog-api-keyheader. - Workflow:
- The audio file is read into memory and Base64-encoded.
- A single
POSTrequest is made to the API with a JSON body containing the audio data and a text prompt asking for transcription. - The transcribed text is extracted from the first candidate in the JSON response.
Sources: VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift:1-137
ElevenLabs
- Service:
ElevenLabsTranscriptionService - API Endpoint:
https://api.elevenlabs.io/v1/speech-to-text - Authentication: Uses an API key from
ElevenLabsAPIKeyinUserDefaultssent in thexi-api-keyheader. - Workflow: A single
POSTrequest with multipart/form-data containing the audio file, model ID, and other parameters likelanguage_code.
Sources: VoiceInk/Services/CloudTranscription/ElevenLabsTranscriptionService.swift:1-104
Native Apple Provider
- Service:
NativeAppleTranscriptionService - Technology: Designed to use the
SpeechAnalyzerandSpeechTranscriberAPIs, which are noted as being available on future versions of macOS (26+). - Availability: The implementation is guarded by
#if canImport(Speech) && ENABLE_NATIVE_SPEECH_ANALYZER, indicating it is a forward-looking feature. On current systems, it will throw anunsupportedOSerror. - Features: It supports locale detection and can automatically request the download of necessary language model assets from Apple's servers.
Sources: VoiceInk/Services/NativeAppleTranscriptionService.swift:1-150
Post-Processing and Enhancement
After raw text is generated by a provider, it undergoes several optional processing steps.
Text Formatting
TranscriptionOutputFilter.filter(text): A function (not detailed in the provided files) that likely cleans up common transcription artifacts.WhisperTextFormatter.format(text): A formatter (not detailed) that is applied ifIsTextFormattingEnabledis true.WordReplacementService.shared.applyReplacements(to: text): Applies user-defined word and phrase replacements ifIsWordReplacementEnabledis true.
Sources: VoiceInk/Services/AudioFileTranscriptionManager.swift:125-136
AI Enhancement
If AIEnhancementService is enabled and configured, the transcribed text can be sent to another AI model for refinement (e.g., summarization, rephrasing, formatting).
- Prompts: The enhancement is guided by a system prompt. The app includes several predefined templates for different contexts like "Chat," "Email," and "Rewrite."
- Data Capture: When enhancement occurs, the
enhancedText,enhancementDuration, the name of the AI model, and the prompt used are all saved in theTranscriptionobject.
Sources: VoiceInk/Services/AudioFileTranscriptionManager.swift:140-173, VoiceInk/Models/PromptTemplates.swift:1-125
Data Model: Transcription
All metadata and results from the transcription process are stored in a Transcription object using SwiftData.
This diagram shows the schema for the Transcription model.
Key fields include:
text: The original, raw transcript.enhancedText: The result from theAIEnhancementService.duration: The duration of the original audio file in seconds.transcriptionModelName: The display name of the model used (e.g., "ggml-tiny.bin").transcriptionDuration: The time taken for the transcription step, in seconds.enhancementDuration: The time taken for the AI enhancement step, in seconds.
Performance Analysis
The engine is designed to capture performance metrics, which are then used in the PerformanceAnalysisView to provide insights to the user.
The PerformanceAnalysisView.analyze function processes a list of Transcription objects to calculate statistics for each transcription and enhancement model used.
| Metric | Description | Source Field |
|---|---|---|
fileCount | The number of times a model was used. | Grouping by transcriptionModelName or aiEnhancementModelName. |
totalProcessingTime | Sum of all processing durations for a model. | transcriptionDuration or enhancementDuration. |
avgProcessingTime | Average time taken by the model to process a file. | totalProcessingTime / fileCount. |
avgAudioDuration | Average audio length of files processed by the model. | duration. |
speedFactor | Real-Time Factor (RTFx). How many times faster than real-time the transcription is. | totalAudioDuration / totalProcessingTime. |
| Sources: VoiceInk/Views/Metrics/PerformanceAnalysisView.swift:108-161 |
This data allows users to compare the speed and efficiency of different models directly within the application.
Summary
The VoiceInk Core Transcription Engine is a robust and flexible system for converting speech to text. Its key strengths are its modular support for diverse transcription providers (local, cloud, and native), a comprehensive workflow that includes optional post-processing and AI enhancement, and detailed performance metric collection. By decoupling the orchestration logic from the specific provider implementations, the engine is easily extensible to support new services in the future. The rich data captured in the Transcription model provides valuable insights for both the user and potential future development.