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

feat(dictionary): dictate into wizard fields natively

altic-dev77c462f5d241
diff --git a/Sources/Fluid/UI/CustomDictionaryView.swift b/Sources/Fluid/UI/CustomDictionaryView.swift
index 3d20fa45..5b1fdb9d 100644
--- a/Sources/Fluid/UI/CustomDictionaryView.swift
+++ b/Sources/Fluid/UI/CustomDictionaryView.swift
@@ -63,6 +63,8 @@ struct CustomDictionaryView: View {
@State private var isTrainedReplacementGlowExpanded = false
@State private var replacementConfirmation: ReplacementConfirmation?
@State private var composerMode: DictionaryComposerMode = .train
+ @State private var manualSourceWord = ""
+ @State private var manualReturnStep: DictionaryWordWizardStep = .spelling
@State private var manualTriggerDraft = ""
@State private var manualReplacement = ""
@State private var isYourDictionaryPresented = false
@@ -591,7 +593,7 @@ struct CustomDictionaryView: View {
ThemedCard(style: .standard, hoverEffect: false) {
if self.wizardStep == .manual {
VStack(alignment: .leading, spacing: self.theme.metrics.spacing.lg) {
- Button { self.wizardStep = .recording } label: {
+ Button { self.wizardStep = self.manualReturnStep } label: {
Label("Back", systemImage: "chevron.left")
}.fluidGlassAction()
Text("Add a correction").font(self.theme.typography.sectionTitle)
@@ -635,7 +637,12 @@ struct CustomDictionaryView: View {
onBack: { self.wizardStep = .spelling },
onNewWord: { self.resetTraining(); self.wizardStep = .spelling },
onManual: {
- self.manualReplacement = self.normalizedTrainingReplacement
+ self.manualReturnStep = self.wizardStep
+ if self.manualSourceWord != self.normalizedTrainingReplacement || self.manualReplacement.isEmpty {
+ self.manualSourceWord = self.normalizedTrainingReplacement
+ self.manualReplacement = self.normalizedTrainingReplacement
+ self.manualTriggerDraft = self.trainingVariants.joined(separator: ", ")
+ }
self.wizardStep = .manual
},
onPracticeMore: {
@@ -767,13 +774,13 @@ struct CustomDictionaryView: View {
VStack(alignment: .leading, spacing: self.theme.metrics.spacing.md) {
ViewThatFits(in: .horizontal) {
HStack(alignment: .top, spacing: self.theme.metrics.spacing.md) {
- self.manualTriggerField
self.manualReplacementField
+ self.manualTriggerField
}
VStack(alignment: .leading, spacing: self.theme.metrics.spacing.md) {
- self.manualTriggerField
self.manualReplacementField
+ self.manualTriggerField
}
}
@@ -829,12 +836,12 @@ struct CustomDictionaryView: View {
private var manualReplacementField: some View {
VStack(alignment: .leading, spacing: self.theme.metrics.spacing.sm) {
- Text("What it should type")
+ Text("Correct word")
.font(self.theme.typography.captionStrong)
TextField("FluidVoice", text: self.$manualReplacement)
.dictionaryInputChrome()
.onSubmit { self.addManualReplacementIfValid() }
- Text("This is what appears in your transcription.")
+ Text("The spelling you want in your transcription.")
.font(self.theme.typography.caption)
.foregroundStyle(self.theme.palette.secondaryText)
}
@@ -2928,6 +2935,7 @@ private struct DictionaryInputChrome: ViewModifier {
content
.textFieldStyle(.plain)
.focused(self.$isFocused)
+ .dictionaryDictationInput(focused: self.isFocused)
.padding(.horizontal, 10)
.padding(.vertical, 6)
.frame(minHeight: self.minHeight)
diff --git a/Sources/Fluid/UI/DictionaryFieldDictation.swift b/Sources/Fluid/UI/DictionaryFieldDictation.swift
new file mode 100644
index 00000000..489bfb12
--- /dev/null
+++ b/Sources/Fluid/UI/DictionaryFieldDictation.swift
@@ -0,0 +1,75 @@
+import AppKit
+import Combine
+import SwiftUI
+
+/// Delivers only a shortcut capture begun in this field, through its native editor.
+/// Native insertion preserves the selection and invokes the field's existing binding.
+private struct DictionaryFieldDictation: ViewModifier {
+ let focused: Bool
+ @EnvironmentObject private var services: AppServices
+ @State private var editor: NSTextView?
+ @State private var originalText = ""
+ @State private var originalSelection = NSRange(location: 0, length: 0)
+ @State private var attempt: UUID?
+ @State private var stopped = false
+
+ func body(content: Content) -> some View {
+ content
+ .onReceive(self.services.asr.$isRunning.dropFirst()) { running in
+ if running {
+ self.cancel()
+ guard self.focused, NSApp.isActive,
+ !self.services.asr.isDictionaryTrainingCaptureActive,
+ let editor = NSApp.keyWindow?.firstResponder as? NSTextView,
+ editor.isEditable
+ else { return }
+ self.editor = editor
+ self.originalText = editor.string
+ self.originalSelection = editor.selectedRange()
+ self.attempt = UUID()
+ } else if self.attempt != nil {
+ self.stopped = true
+ }
+ }
+ .onReceive(self.services.asr.$finalText.dropFirst()) { text in
+ guard self.attempt != nil, self.stopped,
+ !text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
+ else { return }
+ defer { self.cancel() }
+ guard self.focused, NSApp.isActive, let editor = self.editor,
+ NSApp.keyWindow?.firstResponder === editor,
+ editor.string == self.originalText,
+ editor.selectedRange() == self.originalSelection
+ else { return }
+ editor.insertText(text, replacementRange: self.originalSelection)
+ }
+ .onReceive(self.services.asr.$showError) { failed in
+ if failed { self.cancel() }
+ }
+ .onReceive(NotificationCenter.default.publisher(for: NSApplication.didResignActiveNotification)) { _ in
+ self.cancel()
+ }
+ .onChange(of: self.focused) { _, focused in
+ if !focused { self.cancel() }
+ }
+ .task(id: self.stopped ? self.attempt : nil) {
+ guard self.stopped, let attempt = self.attempt else { return }
+ do { try await Task.sleep(for: .seconds(60)) } catch { return }
+ if self.attempt == attempt { self.cancel() }
+ }
+ .onDisappear { self.cancel() }
+ }
+
+ private func cancel() {
+ self.attempt = nil
+ self.stopped = false
+ self.editor = nil
+ self.originalText = ""
+ }
+}
+
+extension View {
+ func dictionaryDictationInput(focused: Bool) -> some View {
+ self.modifier(DictionaryFieldDictation(focused: focused))
+ }
+}
diff --git a/Sources/Fluid/UI/DictionaryWordWizard.swift b/Sources/Fluid/UI/DictionaryWordWizard.swift
index 9df32cc4..3581bbfa 100644
--- a/Sources/Fluid/UI/DictionaryWordWizard.swift
+++ b/Sources/Fluid/UI/DictionaryWordWizard.swift
@@ -120,6 +120,7 @@ struct DictionaryWordWizard: View {
}
.font(self.theme.typography.body)
.focused(self.$wordFocused)
+ .dictionaryDictationInput(focused: self.wordFocused)
.accessibilityLabel("Word to learn")
.onSubmit { if !self.word.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty { self.onContinue() } }
self.primary("Continue", action: self.onContinue)
@@ -149,19 +150,13 @@ struct DictionaryWordWizard: View {
}
private var manualAlternative: some View {
- VStack(spacing: self.theme.metrics.spacing.lg) {
- Divider().padding(.vertical, self.theme.metrics.spacing.md)
- ViewThatFits(in: .horizontal) {
- HStack(spacing: self.theme.metrics.spacing.lg) {
- self.manualExplanation.frame(minWidth: 240, maxWidth: .infinity, alignment: .leading)
- self.manualButton.disabled(self.busy)
- }
- VStack(alignment: .leading, spacing: self.theme.metrics.spacing.md) {
- self.manualExplanation
- self.manualButton.disabled(self.busy)
- }
- }
+ HStack(spacing: self.theme.metrics.spacing.md) {
+ Text("Prefer typing?")
+ .font(self.theme.typography.body)
+ .foregroundStyle(self.theme.palette.secondaryText)
+ self.manualButton.disabled(self.busy)
}
+ .frame(maxWidth: .infinity)
}
private var captureStage: some View {
@@ -357,25 +352,6 @@ struct DictionaryWordWizard: View {
.disabled(self.busy)
}
- private var manualExplanation: some View {
- VStack(alignment: .leading, spacing: self.theme.metrics.spacing.sm) {
- Text("Or, fix a specific spelling")
- .font(self.theme.typography.sectionTitle)
- Text("Tell us what FluidVoice types and what you want instead.")
- .font(self.theme.typography.body)
- .foregroundStyle(self.theme.palette.secondaryText)
- .fixedSize(horizontal: false, vertical: true)
- HStack(spacing: self.theme.metrics.spacing.md) {
- Text("chat GPT").foregroundStyle(self.theme.palette.secondaryText)
- Image(systemName: "arrow.right").foregroundStyle(self.theme.palette.secondaryText)
- Text("ChatGPT").foregroundStyle(self.theme.palette.accent)
- }
- .font(self.theme.typography.body)
- .accessibilityElement(children: .ignore)
- .accessibilityLabel("Example: chat space GPT becomes ChatGPT")
- }
- }
-
private var manualButton: some View {
Button(action: self.onManual) {
Label("Add manually", systemImage: "keyboard")
diff --git a/Tests/Standalone/DictionaryFieldDictationHarness.swift b/Tests/Standalone/DictionaryFieldDictationHarness.swift
new file mode 100644
index 00000000..5971434b
--- /dev/null
+++ b/Tests/Standalone/DictionaryFieldDictationHarness.swift
@@ -0,0 +1,46 @@
+// Standalone UI regression fixture. Compile alongside DictionaryFieldDictation.swift.
+// In First, select "world", then Cmd-1: expect "Hello FluidVoice"; Second stays untouched.
+// Cmd-2 simulates training: neither field changes. Cmd-3 moves focus before completion:
+// neither field changes. Repeat Cmd-1 in Second to verify repeated identical transcripts.
+import AppKit
+import Combine
+import SwiftUI
+
+final class ASRFixture: ObservableObject {
+ @Published var isRunning = false
+ @Published var finalText = ""
+ @Published var showError = false
+ var isDictionaryTrainingCaptureActive = false
+}
+
+final class AppServices: ObservableObject { let asr = ASRFixture() }
+struct Demo: View {
+ @StateObject var services = AppServices()
+ @State var first = "Hello world"
+ @State var second = "Untouched"
+ @FocusState var focus: Int?
+ var body: some View {
+ VStack {
+ TextField("First", text: self.$first).focused(self.$focus, equals: 1).dictionaryDictationInput(focused: self.focus == 1)
+ TextField("Second", text: self.$second).focused(self.$focus, equals: 2).dictionaryDictationInput(focused: self.focus == 2)
+ Button("Dictate") { self.run(training: false, move: false) }.keyboardShortcut("1")
+ Button("Training") { self.run(training: true, move: false) }.keyboardShortcut("2")
+ Button("Change focus") { self.run(training: false, move: true) }.keyboardShortcut("3")
+ Text(self.first + " | " + self.second)
+ }.padding(30).frame(width: 600, height: 220).environmentObject(self.services)
+ }
+
+ func run(training: Bool, move: Bool) {
+ self.services.asr.isDictionaryTrainingCaptureActive = training
+ self.services.asr.isRunning = true
+ Task { @MainActor in
+ try? await Task.sleep(for: .milliseconds(150))
+ if move { self.focus = 2 }
+ self.services.asr.isRunning = false
+ try? await Task.sleep(for: .milliseconds(150))
+ self.services.asr.finalText = "FluidVoice"
+ }
+ }
+}
+
+@main struct Fixture: App { var body: some Scene { WindowGroup { Demo() }}}