How Asian Language Autocorrect Is Integrated in OpenSuperWhisper
OpenSuperWhisper implements Asian language autocorrect as an optional post-processing step that runs after Whisper transcription completes, using a Swift wrapper around a native C library to improve punctuation and spacing for Chinese, Japanese, and Korean text.
OpenSuperWhisper extends OpenAI's Whisper with intelligent post-processing for Asian scripts. The integration follows a clean separation of concerns: user preferences are persisted in AppPreferences, language detection happens in Settings, and the transcription engine conditionally invokes the autocorrect wrapper only when appropriate.
Architecture Overview
The integration follows a seven-step data flow that keeps the autocorrect logic decoupled from the core Whisper engine:
- User Preference – A boolean
useAsianAutocorrectis stored inAppPreferencesand exposed through the Settings UI. - Language Detection –
Settings.isAsianLanguagechecks if the selected language belongs to the hard-coded set["zh","ja","ko"]. - Decision Logic –
Settings.shouldApplyAsianAutocorrectcombines the language check with the user preference. - Engine Hook – After Whisper finishes producing raw text,
WhisperEngine.transcribeAudiocallsAutocorrectWrapper.formatonly whensettings.shouldApplyAsianAutocorrectreturns true. - C Library Bridge –
AutocorrectWrapperis a thin Swift wrapper around the nativeautocorrectC library that formats the string and returns the corrected version.
This design ensures that the autocorrect step is strictly opt-in and only activates for the three supported Asian scripts without affecting other languages.
Key Implementation Files
AppPreferences.swift
User preferences are persisted using a property wrapper in OpenSuperWhisper/Utils/AppPreferences.swift:
@UserDefault(key:"useAsianAutocorrect")
var useAsianAutocorrect: Bool
Settings.swift
The Settings model in OpenSuperWhisper/Settings.swift defines the Asian language set and the decision logic:
// Lines 11-13
var asianLanguages: Set<String> = ["zh", "ja", "ko"]
// Lines 24-26
var isAsianLanguage: Bool {
asianLanguages.contains(selectedLanguage)
}
// Lines 28-30
var shouldApplyAsianAutocorrect: Bool {
useAsianAutocorrect && isAsianLanguage
}
The UI toggle is implemented in the same file (lines 84-90), conditionally showing the option only when an Asian language is selected:
if Settings.asianLanguages.contains(viewModel.selectedLanguage) {
HStack {
Text("Use Asian Autocorrect")
Spacer()
Toggle("", isOn: $viewModel.useAsianAutocorrect)
}
}
WhisperEngine.swift
The transcription engine in OpenSuperWhisper/Engines/WhisperEngine.swift (lines 22-27) checks the flag before applying autocorrect:
func transcribeAudio(url: URL, settings: Settings) async throws -> String {
// … Whisper processing produces `cleanedText`
var processedText = cleanedText
if settings.shouldApplyAsianAutocorrect && !cleanedText.isEmpty {
processedText = AutocorrectWrapper.format(cleanedText)
}
return processedText
}
AutocorrectWrapper.swift
The bridge to the native library lives in OpenSuperWhisper/Utils/AutocorrectWrapper.swift. This thin Swift wrapper calls the underlying C library's formatting functions:
let corrected = AutocorrectWrapper.format(rawText)
Practical Usage Examples
Enabling Autocorrect via the UI
When a user selects Chinese, Japanese, or Korean in the Settings view, the toggle automatically appears:
if Settings.asianLanguages.contains(viewModel.selectedLanguage) {
HStack {
Text("Use Asian Autocorrect")
Spacer()
Toggle("", isOn: $viewModel.useAsianAutocorrect)
}
}
The toggle writes the value to AppPreferences.shared.useAsianAutocorrect, which persists across app launches.
Programmatically Toggling the Feature
You can enable autocorrect for the current session without using the UI:
import OpenSuperWhisper
// Turn on autocorrect
AppPreferences.shared.useAsianAutocorrect = true
// Optionally force a refresh of the engine's settings
TranscriptionService.shared.reloadEngine()
Manually Applying Autocorrect
For custom processing pipelines, you can invoke the wrapper directly on any string:
import OpenSuperWhisper
let raw = "こんにちは、世界"
let corrected = AutocorrectWrapper.format(raw)
// Returns string with corrected Japanese punctuation and spacing
print(corrected)
Summary
- OpenSuperWhisper treats Asian language autocorrect as a post-processing step that runs after Whisper transcription completes.
- The feature is controlled by the
useAsianAutocorrectboolean inAppPreferences, exposed through a conditional UI toggle inSettingsView. - Language detection uses a hard-coded set
["zh","ja","ko"]inSettings.swiftto determine if the current target language qualifies. - The
WhisperEngineonly invokesAutocorrectWrapper.formatwhensettings.shouldApplyAsianAutocorrectreturns true. AutocorrectWrapperbridges Swift to a native C library that handles the actual punctuation and spacing corrections.
Frequently Asked Questions
Which languages does the autocorrect feature support?
The integration supports Chinese (zh), Japanese (ja), and Korean (ko). These languages are defined as a hard-coded set in OpenSuperWhisper/Settings.swift lines 11-13. The feature automatically activates only when the user has selected one of these languages and enabled the autocorrect toggle.
Can I use the autocorrect functionality outside of the transcription engine?
Yes. While the engine automatically applies autocorrect when appropriate, you can manually invoke AutocorrectWrapper.format(_:) from OpenSuperWhisper/Utils/AutocorrectWrapper.swift on any string. This is useful for custom text processing or correcting imported transcripts that weren't generated by the app's Whisper engine.
Where is the user preference for autocorrect stored?
The preference is stored using the @UserDefault property wrapper in OpenSuperWhisper/Utils/AppPreferences.swift with the key "useAsianAutocorrect". This persists the boolean value across app launches using standard UserDefaults, ensuring the user's choice survives app restarts.
Does enabling autocorrect affect transcription performance?
The autocorrect step adds minimal overhead because it runs only after Whisper has completed transcription and uses a thin Swift wrapper around an optimized C library. The check in WhisperEngine.transcribeAudio includes a guard !cleanedText.isEmpty to avoid unnecessary processing on empty strings, ensuring the feature only runs when there is actual text to correct.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →