# How Asian Language Autocorrect Is Integrated in OpenSuperWhisper

> Discover how OpenSuperWhisper integrates Asian language autocorrect using a Swift wrapper and a native C library to enhance Chinese, Japanese, and Korean transcription with improved punctuation and spacing.

- Repository: [Starmel/OpenSuperWhisper](https://github.com/Starmel/OpenSuperWhisper)
- Tags: internals
- Published: 2026-07-07

---

**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:

1. **User Preference** – A boolean `useAsianAutocorrect` is stored in `AppPreferences` and exposed through the Settings UI.
2. **Language Detection** – `Settings.isAsianLanguage` checks if the selected language belongs to the hard-coded set `["zh","ja","ko"]`.
3. **Decision Logic** – `Settings.shouldApplyAsianAutocorrect` combines the language check with the user preference.
4. **Engine Hook** – After Whisper finishes producing raw text, `WhisperEngine.transcribeAudio` calls `AutocorrectWrapper.format` only when `settings.shouldApplyAsianAutocorrect` returns true.
5. **C Library Bridge** – `AutocorrectWrapper` is a thin Swift wrapper around the native `autocorrect` C 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`](https://github.com/Starmel/OpenSuperWhisper/blob/main/OpenSuperWhisper/Utils/AppPreferences.swift):

```swift
@UserDefault(key:"useAsianAutocorrect")
var useAsianAutocorrect: Bool

```

### Settings.swift

The `Settings` model in [`OpenSuperWhisper/Settings.swift`](https://github.com/Starmel/OpenSuperWhisper/blob/main/OpenSuperWhisper/Settings.swift) defines the Asian language set and the decision logic:

```swift
// 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:

```swift
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`](https://github.com/Starmel/OpenSuperWhisper/blob/main/OpenSuperWhisper/Engines/WhisperEngine.swift) (lines 22-27) checks the flag before applying autocorrect:

```swift
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`](https://github.com/Starmel/OpenSuperWhisper/blob/main/OpenSuperWhisper/Utils/AutocorrectWrapper.swift). This thin Swift wrapper calls the underlying C library's formatting functions:

```swift
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:

```swift
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:

```swift
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:

```swift
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 `useAsianAutocorrect` boolean in `AppPreferences`, exposed through a conditional UI toggle in `SettingsView`.
- Language detection uses a hard-coded set `["zh","ja","ko"]` in [`Settings.swift`](https://github.com/Starmel/OpenSuperWhisper/blob/main/Settings.swift) to determine if the current target language qualifies.
- The `WhisperEngine` only invokes `AutocorrectWrapper.format` when `settings.shouldApplyAsianAutocorrect` returns true.
- `AutocorrectWrapper` bridges 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`](https://github.com/Starmel/OpenSuperWhisper/blob/main/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`](https://github.com/Starmel/OpenSuperWhisper/blob/main/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`](https://github.com/Starmel/OpenSuperWhisper/blob/main/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.