Cloud Transcription Providers
Relevant source files
The following files were used as context for generating this wiki page:
- VoiceInk/Services/CloudTranscription/CloudTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/OpenAICompatibleTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/GroqTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/DeepgramTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift
- VoiceInk/Services/CloudTranscription/ElevenLabsTranscriptionService.swift
- VoiceInk/Models/TranscriptionModel.swift
- VoiceInk/Services/AudioFileTranscriptionManager.swift
The Cloud Transcription system in VoiceInk provides a unified interface for transcribing audio files using various third-party cloud-based services. It is designed to be extensible, allowing different providers to be used interchangeably based on user selection. The system abstracts the provider-specific API calls, request formats, and authentication mechanisms behind a common service layer.
The core of this system is the CloudTranscriptionService, which acts as a facade or router. It determines the appropriate provider based on the selected TranscriptionModel and delegates the transcription task to a specialized service class for that provider. This architecture supports a range of providers including Groq, Deepgram, Soniox, Gemini, ElevenLabs, Mistral, and any OpenAI-compatible custom endpoint.
System Architecture
The cloud transcription module is orchestrated by the CloudTranscriptionService, which lazily initializes and manages instances of individual provider services. When a transcription request is made, this central service inspects the provider property of the TranscriptionModel and routes the call to the corresponding service implementation.
This diagram illustrates the class relationships within the cloud transcription module.
General Data Flow
The typical flow for a cloud transcription begins in a manager class like AudioTranscriptionManager, which calls the main CloudTranscriptionService. This service then dispatches the request to the specific provider service, which handles the network communication and returns the transcribed text.
This sequence diagram shows the high-level interaction for a cloud-based transcription.
Common Components
Error Handling
A standardized set of errors is defined in the CloudTranscriptionError enum to ensure consistent error handling across all cloud providers.
| Error Case | Description |
|---|---|
unsupportedProvider | The selected model's provider is not supported. |
missingAPIKey | The API key for the service is not configured in UserDefaults. |
invalidAPIKey | The provided API key is invalid. |
audioFileNotFound | The local audio file for transcription could not be found or read. |
apiRequestFailed | The API request failed with a specific HTTP status code and message. |
networkError | A general network error occurred (e.g., bad server response). |
noTranscriptionReturned | The API returned a successful but empty or invalid response. |
dataEncodingError | Failed to encode the request body (e.g., multipart form or JSON). |
Sources: VoiceInk/Services/CloudTranscription/CloudTranscriptionService.swift:4-28
API Key Management
All provider services retrieve their required API keys from UserDefaults. Each service checks for a specific key and throws a missingAPIKey error if it's not found.
| Provider | UserDefaults Key |
|---|---|
| Groq | GROQAPIKey |
| Deepgram | DeepgramAPIKey |
| ElevenLabs | ElevenLabsAPIKey |
| Gemini | GeminiAPIKey |
| Mistral | MistralAPIKey |
| Soniox | SonioxAPIKey |
| Custom | The key is stored within the CustomCloudModel object itself. |
Sources: VoiceInk/Services/CloudTranscription/GroqTranscriptionService.swift:38-40, VoiceInk/Services/CloudTranscription/DeepgramTranscriptionService.swift:43-45, VoiceInk/Services/CloudTranscription/ElevenLabsTranscriptionService.swift:29-31, VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift:70-72, VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift:21-23, VoiceInk/Services/CloudTranscription/OpenAICompatibleTranscriptionService.swift:11-15
Provider Implementations
Each cloud provider has a dedicated service class that implements the specific logic for API interaction.
OpenAI-Compatible (Groq, Custom)
Services like Groq and the user-configurable "Custom" provider use an API format compatible with OpenAI's transcription endpoint. They send a multipart/form-data request containing the audio file and various parameters.
The OpenAICompatibleTranscriptionService is used for any model of type CustomCloudModel, taking the API endpoint and key directly from the model's properties. The GroqTranscriptionService is a specialized version that hardcodes the Groq API endpoint.
Sources: VoiceInk/Services/CloudTranscription/OpenAICompatibleTranscriptionService.swift, VoiceInk/Services/CloudTranscription/GroqTranscriptionService.swift
This diagram shows the sequence for an OpenAI-compatible transcription request.
Request Parameters
The following parameters are sent in the multipart/form-data body for OpenAI-compatible requests.
| Parameter | Description | Source |
|---|---|---|
file | The audio file to be transcribed. | OpenAICompatibleTranscriptionService.swift:48-51 |
model | The name of the transcription model to use. | OpenAICompatibleTranscriptionService.swift:53-56 |
language | An optional language code (ISO-639-1). Defaults to "auto". | OpenAICompatibleTranscriptionService.swift:58-63 |
prompt | An optional text prompt to guide the model. | OpenAICompatibleTranscriptionService.swift:65-70 |
response_format | The format of the response. Hardcoded to json. | OpenAICompatibleTranscriptionService.swift:72-75 |
temperature | The sampling temperature. Hardcoded to 0. | OpenAICompatibleTranscriptionService.swift:77-80 |
Deepgram
The DeepgramTranscriptionService sends the raw audio data directly in the request body and passes parameters via URL query strings. It dynamically selects the model (nova-3 for English, nova-2 for other languages) based on the user's language setting.
Sources: VoiceInk/Services/CloudTranscription/DeepgramTranscriptionService.swift
Request Parameters (URL Query)
| Parameter | Value | Description |
|---|---|---|
model | nova-3 or nova-2 | The transcription model. |
smart_format | true | Enables smart formatting features like punctuation. |
punctuate | true | Enables punctuation. |
paragraphs | true | Enables paragraph detection. |
language | e.g., en, es | The language of the audio. |
Sources: VoiceInk/Services/CloudTranscription/DeepgramTranscriptionService.swift:52-64
Soniox
The Soniox integration is a multi-step process involving file upload, transcription job creation, status polling, and finally, transcript retrieval.
This sequence diagram details the multi-step Soniox transcription flow.
A unique feature of the Soniox service is its ability to use the app's custom dictionary to improve accuracy by passing the terms in the context field during transcription creation.
Sources: VoiceInk/Services/CloudTranscription/SonioxTranscriptionService.swift:80-85
Gemini
The GeminiTranscriptionService uses a JSON-based request body where the audio file is Base64-encoded and sent as part of the payload. The request is sent to a generative model endpoint, prompted specifically to perform transcription.
Sources: VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift
Request Body Structure
The service constructs a GeminiRequest object, which is then serialized to JSON. The audio is included as a Base64 string.
{
"contents": [
{
"parts": [
{
"text": "Please transcribe this audio file. Provide only the transcribed text."
},
{
"inlineData": {
"mimeType": "audio/wav",
"data": "<base64_encoded_audio_data>"
}
}
]
}
]
}
Sources: VoiceInk/Services/CloudTranscription/GeminiTranscriptionService.swift:28-42
ElevenLabs
The ElevenLabsTranscriptionService uses a multipart/form-data request similar to the OpenAI-compatible services but with its own specific field names and authentication header (xi-api-key).
Sources: VoiceInk/Services/CloudTranscription/ElevenLabsTranscriptionService.swift
Request Parameters
| Parameter | Description | Source |
|---|---|---|
file | The audio file to be transcribed. | ElevenLabsTranscriptionService.swift:45-49 |
model_id | The name of the transcription model to use. | ElevenLabsTranscriptionService.swift:52-55 |
tag_audio_events | Disables audio event tagging. Hardcoded to false. | ElevenLabsTranscriptionService.swift:58-61 |
temperature | The sampling temperature. Hardcoded to 0. | ElevenLabsTranscriptionService.swift:64-67 |
language_code | An optional language code. | ElevenLabsTranscriptionService.swift:70-75 |
Conclusion
The cloud transcription system in VoiceInk is a robust and modular component that effectively isolates the complexities of interacting with diverse third-party APIs. By using a central facade (CloudTranscriptionService) and dedicated services for each provider, the application can easily support and switch between multiple transcription backends. This design also simplifies the process of adding new cloud providers in the future, as it only requires creating a new service class that conforms to the expected interface.