Skip to content

Fastest and only macOS Dictation app with on-device STT and custom trained AI enhancement model. Windows, iOS testflight! Android, Linux waitlist open! A local Wispr Flow alternative. Follow https://x.com/fluidvoiceapp for more

Add a locale picker for Apple Speech (macOS 26+) (#1236)

chyulin206711661b91
diff --git a/Fluid.xcodeproj/project.pbxproj b/Fluid.xcodeproj/project.pbxproj
index 6ca82216..6cefe3fb 100644
--- a/Fluid.xcodeproj/project.pbxproj
+++ b/Fluid.xcodeproj/project.pbxproj
@@ -120,6 +120,7 @@
B51800000000000000000002 /* SpokenSendTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51800000000000000000001 /* SpokenSendTests.swift */; };
B51900000000000000000002 /* PrivateAIProviderPromptFormatTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = B51900000000000000000001 /* PrivateAIProviderPromptFormatTests.swift */; };
C0DE63700000000000000002 /* WhisperLanguageSelectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DE63700000000000000001 /* WhisperLanguageSelectionTests.swift */; };
+ C0DE63800000000000000002 /* AppleSpeechLocaleSelectionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C0DE63800000000000000001 /* AppleSpeechLocaleSelectionTests.swift */; };
CACEC0010000000000000002 /* KeychainServiceCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CACEC0010000000000000001 /* KeychainServiceCacheTests.swift */; };
FEED67600000000000000002 /* PasteDeliveryCoordinatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FEED67600000000000000001 /* PasteDeliveryCoordinatorTests.swift */; };
7CDB0A2F2F3C4D5600FB7CAD /* dictation_fixture.wav in Resources */ = {isa = PBXBuildFile; fileRef = 7CDB0A2B2F3C4D5600FB7CAD /* dictation_fixture.wav */; };
@@ -278,6 +279,7 @@
B51900000000000000000001 /* PrivateAIProviderPromptFormatTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateAIProviderPromptFormatTests.swift; sourceTree = "<group>"; };
B52000000000000000000001 /* PrivateAIDictationTokenBudgetTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrivateAIDictationTokenBudgetTests.swift; sourceTree = "<group>"; };
C0DE63700000000000000001 /* WhisperLanguageSelectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhisperLanguageSelectionTests.swift; sourceTree = "<group>"; };
+ C0DE63800000000000000001 /* AppleSpeechLocaleSelectionTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppleSpeechLocaleSelectionTests.swift; sourceTree = "<group>"; };
CACEC0010000000000000001 /* KeychainServiceCacheTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeychainServiceCacheTests.swift; sourceTree = "<group>"; };
FEED67600000000000000001 /* PasteDeliveryCoordinatorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasteDeliveryCoordinatorTests.swift; sourceTree = "<group>"; };
7C078D8F2E3B339200FB7CAC /* FluidVoice Debug.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "FluidVoice Debug.app"; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -548,6 +550,7 @@
B52000000000000000000001 /* PrivateAIDictationTokenBudgetTests.swift */,
C0DE123A0000000000000001 /* DictationContextCaptureTests.swift */,
C0DE63700000000000000001 /* WhisperLanguageSelectionTests.swift */,
+ C0DE63800000000000000001 /* AppleSpeechLocaleSelectionTests.swift */,
CACEC0010000000000000001 /* KeychainServiceCacheTests.swift */,
0B05F11E000000000000A001 /* SupportedFileExtensionsTests.swift */,
FEED67600000000000000001 /* PasteDeliveryCoordinatorTests.swift */,
@@ -954,6 +957,7 @@
B51900000000000000000002 /* PrivateAIProviderPromptFormatTests.swift in Sources */,
C0DE123A0000000000000002 /* DictationContextCaptureTests.swift in Sources */,
C0DE63700000000000000002 /* WhisperLanguageSelectionTests.swift in Sources */,
+ C0DE63800000000000000002 /* AppleSpeechLocaleSelectionTests.swift in Sources */,
CACEC0010000000000000002 /* KeychainServiceCacheTests.swift in Sources */,
0B05F11E000000000000A002 /* SupportedFileExtensionsTests.swift in Sources */,
FEED67600000000000000002 /* PasteDeliveryCoordinatorTests.swift in Sources */,
diff --git a/Sources/Fluid/Persistence/VoiceEngineLanguageCatalog.swift b/Sources/Fluid/Persistence/VoiceEngineLanguageCatalog.swift
index 92b2d9f3..98e67ace 100644
--- a/Sources/Fluid/Persistence/VoiceEngineLanguageCatalog.swift
+++ b/Sources/Fluid/Persistence/VoiceEngineLanguageCatalog.swift
@@ -56,7 +56,22 @@ struct VoiceEngineLanguageRoute: Identifiable, Equatable {
}
}
+struct AppleSpeechLocaleOption: Identifiable, Equatable {
+ let id: String
+ let displayName: String
+}
+
enum VoiceEngineLanguageCatalog {
+ static func appleSpeechLocaleOptions(
+ identifiers: [String],
+ displayLocale: Locale = .current
+ ) -> [AppleSpeechLocaleOption] {
+ let uniqueIdentifiers = Set(identifiers.map { Self.normalizedLocaleIdentifier($0) })
+ return uniqueIdentifiers
+ .map { AppleSpeechLocaleOption(id: $0, displayName: displayLocale.localizedString(forIdentifier: $0) ?? $0) }
+ .sorted { $0.displayName.localizedStandardCompare($1.displayName) == .orderedAscending }
+ }
+
static func allLanguages(
availableModels: [SettingsStore.SpeechModel] = SettingsStore.SpeechModel.availableModels
) -> [VoiceEngineLanguage] {
diff --git a/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift b/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift
index 781217f4..d75243de 100644
--- a/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift
+++ b/Sources/Fluid/Services/AppleSpeechAnalyzerProvider.swift
@@ -36,6 +36,10 @@ final class AppleSpeechAnalyzerProvider: TranscriptionProvider {
init() {}
+ static func supportedLocaleIdentifiers() async -> [String] {
+ await SpeechTranscriber.supportedLocales.map { $0.identifier(.bcp47) }
+ }
+
// MARK: - Lifecycle
func prepare(progressHandler: ((ModelPreparationProgress) -> Void)?) async throws {
diff --git a/Sources/Fluid/UI/AISettings/VoiceEngineSettingsView.swift b/Sources/Fluid/UI/AISettings/VoiceEngineSettingsView.swift
index e370eed3..4ae75aa7 100644
--- a/Sources/Fluid/UI/AISettings/VoiceEngineSettingsView.swift
+++ b/Sources/Fluid/UI/AISettings/VoiceEngineSettingsView.swift
@@ -7,6 +7,9 @@ struct VoiceEngineSettingsView: View {
@State var isShowingNemotronLanguagePicker = false
@State var isShowingWhisperLanguagePicker = false
@State var whisperLanguageSearchText = ""
+ @State var isShowingAppleSpeechLocalePicker = false
+ @State var appleSpeechLocaleSearchText = ""
+ @State var appleSpeechLocaleOptions: [AppleSpeechLocaleOption] = []
let theme: AppTheme
var voiceEngineTitleText: Color {
diff --git a/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swift b/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swift
index 05079950..af1c0847 100644
--- a/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swift
+++ b/Sources/Fluid/UI/AISettings/VoiceEngineSettingsViewModel.swift
@@ -147,6 +147,28 @@ final class VoiceEngineSettingsViewModel: ObservableObject {
}
}
+ /// The analyzer provider binds its locale during preparation, so a new locale needs a
+ /// provider reset. Preparation downloads the locale's model when it isn't installed.
+ func selectAppleSpeechLocale(_ localeIdentifier: String) {
+ guard !self.areSpeechModelActionsBlocked,
+ localeIdentifier != self.settings.selectedAppleSpeechLocaleIdentifier
+ else { return }
+ self.settings.selectedAppleSpeechLocaleIdentifier = localeIdentifier
+ self.asr.resetTranscriptionProvider()
+ Task {
+ do {
+ try await self.asr.ensureAsrReady(source: .settings)
+ } catch is CancellationError {
+ DebugLogger.shared.info("Apple Speech locale change cancelled: \(localeIdentifier)", source: "AISettingsView")
+ } catch {
+ DebugLogger.shared.error("Failed to prepare Apple Speech locale \(localeIdentifier): \(error)", source: "AISettingsView")
+ self.asr.errorTitle = "Language Change Failed"
+ self.asr.errorMessage = error.localizedDescription
+ self.asr.showError = true
+ }
+ }
+ }
+
func downloadSpeechModel(_ model: SettingsStore.SpeechModel, updateWeights: Bool = false) {
guard !self.areSpeechModelActionsBlocked else { return }
Task { [weak self] in
diff --git a/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swift b/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swift
index cb077623..6f0d11b1 100644
--- a/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swift
+++ b/Sources/Fluid/UI/AISettingsView+SpeechRecognition.swift
@@ -431,6 +431,13 @@ extension VoiceEngineSettingsView {
.background(Capsule().fill(Color.fluidGreen.opacity(0.25)))
.foregroundStyle(Color.fluidGreen)
} else {
+ // A failed or cancelled locale download leaves Apple Speech configured but not ready.
+ // Keep the picker so people can switch back to an installed locale.
+ if isConfiguredActive, model == .appleSpeechAnalyzer {
+ self.appleSpeechLocalePickerButton
+ .disabled(self.viewModel.areSpeechModelActionsBlocked)
+ }
+
Button("Activate") {
self.viewModel.activateSpeechModel(model)
}
@@ -547,6 +554,73 @@ extension VoiceEngineSettingsView {
.fluidDropdownStyle()
} else if model == .nemotronOffline || model == .nemotronStreaming || model == .nemotronStreaming320 {
self.nemotronLanguagePickerButton
+ } else if model == .appleSpeechAnalyzer {
+ self.appleSpeechLocalePickerButton
+ }
+ }
+
+ private var appleSpeechLocalePickerButton: some View {
+ Button {
+ self.appleSpeechLocaleSearchText = ""
+ self.isShowingAppleSpeechLocalePicker.toggle()
+ } label: {
+ self.languageChipLabel(self.selectedAppleSpeechLocaleName)
+ }
+ .buttonStyle(.plain)
+ .popover(isPresented: self.$isShowingAppleSpeechLocalePicker, arrowEdge: .bottom) {
+ self.appleSpeechLocalePickerPopover
+ }
+ }
+
+ private var selectedAppleSpeechLocaleName: String {
+ let localeIdentifier = self.settings.selectedAppleSpeechLocaleIdentifier
+ return Locale.current.localizedString(forIdentifier: localeIdentifier) ?? localeIdentifier
+ }
+
+ private var filteredAppleSpeechLocaleOptions: [AppleSpeechLocaleOption] {
+ let query = self.appleSpeechLocaleSearchText.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
+ guard !query.isEmpty else { return self.appleSpeechLocaleOptions }
+ return self.appleSpeechLocaleOptions.filter { option in
+ option.displayName.lowercased().contains(query) || option.id.lowercased().contains(query)
+ }
+ }
+
+ private var appleSpeechLocalePickerPopover: some View {
+ VStack(spacing: 0) {
+ HStack(spacing: 8) {
+ Image(systemName: "magnifyingglass")
+ .foregroundStyle(self.voiceEngineTertiaryText)
+ TextField("Search languages", text: self.$appleSpeechLocaleSearchText)
+ .textFieldStyle(.plain)
+ }
+ .padding(.horizontal, 12)
+ .frame(height: 36)
+
+ Divider()
+
+ ScrollView(.vertical, showsIndicators: true) {
+ LazyVStack(alignment: .leading, spacing: 0) {
+ ForEach(self.filteredAppleSpeechLocaleOptions) { option in
+ Button {
+ self.viewModel.selectAppleSpeechLocale(option.id)
+ self.isShowingAppleSpeechLocalePicker = false
+ } label: {
+ self.whisperLanguagePickerRow(
+ title: option.displayName,
+ isSelected: option.id == self.settings.selectedAppleSpeechLocaleIdentifier
+ )
+ }
+ .buttonStyle(.plain)
+ }
+ }
+ .padding(.vertical, 6)
+ }
+ }
+ .frame(width: 280, height: 420)
+ .task {
+ guard #available(macOS 26, *) else { return }
+ let identifiers = await AppleSpeechAnalyzerProvider.supportedLocaleIdentifiers()
+ self.appleSpeechLocaleOptions = VoiceEngineLanguageCatalog.appleSpeechLocaleOptions(identifiers: identifiers)
}
}
diff --git a/Tests/FluidDictationIntegrationTests/AppleSpeechLocaleSelectionTests.swift b/Tests/FluidDictationIntegrationTests/AppleSpeechLocaleSelectionTests.swift
new file mode 100644
index 00000000..0d01c563
--- /dev/null
+++ b/Tests/FluidDictationIntegrationTests/AppleSpeechLocaleSelectionTests.swift
@@ -0,0 +1,32 @@
+@testable import FluidVoice_Debug
+import XCTest
+
+final class AppleSpeechLocaleSelectionTests: XCTestCase {
+ func testLocaleOptionsAreNormalizedDeduplicatedAndSortedByName() {
+ let english = Locale(identifier: "en")
+ let options = VoiceEngineLanguageCatalog.appleSpeechLocaleOptions(
+ identifiers: ["en-US", "zh_TW", "zh-TW"],
+ displayLocale: english
+ )
+
+ XCTAssertEqual(options.map(\.id), ["zh-TW", "en-US"])
+ XCTAssertEqual(options.map(\.displayName), [
+ english.localizedString(forIdentifier: "zh-TW"),
+ english.localizedString(forIdentifier: "en-US"),
+ ])
+ }
+
+ func testLocaleOptionNamesFollowDisplayLocale() {
+ let english = VoiceEngineLanguageCatalog.appleSpeechLocaleOptions(
+ identifiers: ["zh-TW"],
+ displayLocale: Locale(identifier: "en")
+ )
+ let traditionalChinese = VoiceEngineLanguageCatalog.appleSpeechLocaleOptions(
+ identifiers: ["zh-TW"],
+ displayLocale: Locale(identifier: "zh-Hant-TW")
+ )
+
+ XCTAssertNotEqual(english.first?.displayName, "zh-TW")
+ XCTAssertNotEqual(english.first?.displayName, traditionalChinese.first?.displayName)
+ }
+}