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

Keep a failed retranscription from mislabeling or hiding the stored transcript. Fixes #1033

ParamKataria0a30678313bb
diff --git a/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swift b/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swift
index ad38ceb9..2fae3bcc 100644
--- a/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swift
+++ b/Sources/Fluid/Services/Meeting/MeetingProcessingConfiguration.swift
@@ -89,6 +89,22 @@ enum MeetingRetranscriptionLanguage {
static func displayName(for languageCode: String) -> String {
Self.choices.first { $0.id == languageCode }?.displayName ?? languageCode
}
+
+ /// A same-language run replaces nothing and, if it fails, hides the transcript that is already there.
+ static func canRetranscribe(selection: String, currentLanguageCode: String) -> Bool {
+ guard let code = Self.canonicalCode(selection) else { return false }
+ return code != currentLanguageCode
+ }
+
+ /// The language a failed empty transcript should try again. The session language stays the one
+ /// that labels the stored result, so the requested language lives only on the failed attempt.
+ static func failedAttemptLanguage(for session: MeetingSession) -> String? {
+ guard session.transcriptSegments.isEmpty,
+ let language = session.processingAttempts.last(where: { $0.errorCode != nil })?.languageCode,
+ Self.canRetranscribe(selection: language, currentLanguageCode: session.languageCode)
+ else { return nil }
+ return Self.canonicalCode(language)
+ }
}
/// Inert value snapshot of live-caption ASR configuration. Live captions do no diarization.
diff --git a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift
index 6b3d3360..cd339c72 100644
--- a/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift
+++ b/Sources/Fluid/Services/Meeting/MeetingSessionCoordinator.swift
@@ -681,9 +681,15 @@ final class MeetingSessionCoordinator: ObservableObject {
guard let session = self.activeSession, session.hasRetryableAudio else {
throw MeetingCoordinatorError.noRecoverableAudio
}
+ let retainedLanguage = session.languageCode
+ let hadVisibleTranscript = session.state == .completed && !session.transcriptSegments.isEmpty
let prepared = try self.sessionPreparedForRetranscription(session, languageCode: languageCode)
self.activeSession = prepared
- return try await self.beginProcessingRetry(prepared)
+ return try await self.beginProcessingRetry(
+ prepared,
+ retainedLanguage: retainedLanguage,
+ hadVisibleTranscript: hadVisibleTranscript
+ )
}
if let offer = self.activeSession {
@@ -727,10 +733,16 @@ final class MeetingSessionCoordinator: ObservableObject {
self.state = .idle
}
+ let retainedLanguage = session.languageCode
+ let hadVisibleTranscript = session.state == .completed && !session.transcriptSegments.isEmpty
let prepared = try self.sessionPreparedForRetranscription(session, languageCode: languageCode)
self.activeSession = prepared
self.trackHealth = Dictionary(uniqueKeysWithValues: prepared.audioTracks.map { ($0.kind, $0.health) })
- return try await self.beginProcessingRetry(prepared)
+ return try await self.beginProcessingRetry(
+ prepared,
+ retainedLanguage: retainedLanguage,
+ hadVisibleTranscript: hadVisibleTranscript
+ )
}
/// A nil language keeps the session's current language. A new code must be one final meeting
@@ -763,21 +775,11 @@ final class MeetingSessionCoordinator: ObservableObject {
session.transcriptTimeDomain = inputSession.transcriptTimeDomain
}
- /// The language of the transcript that is still stored, including a completed attempt that produced no text.
- private func previousCompletedLanguage(_ session: MeetingSession) -> String? {
- session.processingAttempts.dropLast().last(where: {
- $0.languageCode != nil && $0.errorCode == nil && $0.stage == .completed
- })?.languageCode
- }
-
- /// Puts the session language back so a failed attempt cannot reject the save or mislabel an export.
- /// Returns whether a previous completed language replaced the language that did not finish.
- private func restorePreviousCompletedLanguage(_ session: inout MeetingSession) -> Bool {
- guard let previousLanguage = self.previousCompletedLanguage(session),
- previousLanguage != session.languageCode
- else { return false }
- session.languageCode = previousLanguage
- return true
+ /// Puts the pre-retry language back. Legacy meetings may have no attempt language at all, so the
+ /// session language from before this run is the one that still labels the stored transcript.
+ private func restoreRetainedLanguage(_ session: inout MeetingSession, retainedLanguage: String) {
+ guard retainedLanguage != session.languageCode else { return }
+ session.languageCode = retainedLanguage
}
private func publishRetryOutcome(_ session: MeetingSession, failure: MeetingSessionFailure?) {
@@ -795,7 +797,11 @@ final class MeetingSessionCoordinator: ObservableObject {
}
}
- private func beginProcessingRetry(_ inputSession: MeetingSession) async throws -> MeetingSession {
+ private func beginProcessingRetry(
+ _ inputSession: MeetingSession,
+ retainedLanguage: String,
+ hadVisibleTranscript: Bool
+ ) async throws -> MeetingSession {
var session = inputSession
if self.activityLease == nil {
self.activityLease = try await self.audioArbiter.acquireMeetingCapture()
@@ -820,7 +826,12 @@ final class MeetingSessionCoordinator: ObservableObject {
// Processing regenerates the transcript; only clear the undo stack once retry actually
// proceeds so a lease/save failure above leaves the prior correction undoable.
self.correctionUndoStacks[session.id] = nil
- return try await self.process(session, generation: generation)
+ return try await self.process(
+ session,
+ generation: generation,
+ retainedLanguage: retainedLanguage,
+ hadVisibleTranscript: hadVisibleTranscript
+ )
}
func deleteSession(id: MeetingSessionID) async throws {
@@ -1615,14 +1626,24 @@ final class MeetingSessionCoordinator: ObservableObject {
self.activeSession = session
self.trackHealth = Dictionary(uniqueKeysWithValues: session.audioTracks.map { ($0.kind, $0.health) })
try? await self.store.save(session)
- let processed = try await self.process(session, generation: generation)
+ let processed = try await self.process(
+ session,
+ generation: generation,
+ retainedLanguage: session.languageCode,
+ hadVisibleTranscript: false
+ )
#if DEBUG
diagnosticsStopSucceeded = true
#endif
return processed
}
- private func process(_ inputSession: MeetingSession, generation: UUID) async throws -> MeetingSession {
+ private func process(
+ _ inputSession: MeetingSession,
+ generation: UUID,
+ retainedLanguage: String,
+ hadVisibleTranscript: Bool
+ ) async throws -> MeetingSession {
let diagnosticStarted = ContinuousClock.now
var diagnosticStage = MeetingProcessingStage.pending
var diagnosticOutcome = "failed"
@@ -1773,18 +1794,12 @@ final class MeetingSessionCoordinator: ObservableObject {
}
if error is CancellationError {
self.restoreStoredTranscript(&session, from: inputSession)
- let previousLanguage = session.processingAttempts.dropLast().last(where: {
- $0.languageCode != nil && $0.errorCode == nil && $0.stage == .completed
- })?.languageCode
- if let previousLanguage, previousLanguage != session.languageCode,
- let lastIndex = session.processingAttempts.indices.last
- {
+ if retainedLanguage != session.languageCode, let lastIndex = session.processingAttempts.indices.last {
session.processingAttempts[lastIndex].errorCode = "cancelled"
session.processingAttempts[lastIndex].completedAt = Date()
}
- let restoredLanguage = self.restorePreviousCompletedLanguage(&session)
- let showCompletedTranscript = restoredLanguage && !session.transcriptSegments.isEmpty
- session.state = showCompletedTranscript ? .completed : .interrupted
+ self.restoreRetainedLanguage(&session, retainedLanguage: retainedLanguage)
+ session.state = hadVisibleTranscript ? .completed : .interrupted
session.updatedAt = Date()
await self.flushQueuedPersistence()
try? await self.store.save(session)
@@ -1803,13 +1818,12 @@ final class MeetingSessionCoordinator: ObservableObject {
session.processingAttempts[lastIndex].completedAt = Date()
}
session.failures.append(failure)
- let restoredLanguage = self.restorePreviousCompletedLanguage(&session)
- let showCompletedTranscript = restoredLanguage && !session.transcriptSegments.isEmpty
- session.state = showCompletedTranscript ? .completed : .failed
+ self.restoreRetainedLanguage(&session, retainedLanguage: retainedLanguage)
+ session.state = hadVisibleTranscript ? .completed : .failed
session.updatedAt = Date()
await self.flushQueuedPersistence()
try? await self.store.save(session)
- self.publishRetryOutcome(session, failure: showCompletedTranscript ? nil : failure)
+ self.publishRetryOutcome(session, failure: hadVisibleTranscript ? nil : failure)
await self.releaseActivityLease()
throw error
}
diff --git a/Sources/Fluid/UI/MeetingSessionCanvases.swift b/Sources/Fluid/UI/MeetingSessionCanvases.swift
index 558e9be0..b7cf8e54 100644
--- a/Sources/Fluid/UI/MeetingSessionCanvases.swift
+++ b/Sources/Fluid/UI/MeetingSessionCanvases.swift
@@ -581,6 +581,7 @@ struct MeetingResultCanvas: View {
.sheet(isPresented: self.$isChoosingRetranscriptionLanguage) {
MeetingRetranscriptionLanguageSheet(
languages: MeetingRetranscriptionLanguage.choices,
+ currentLanguageCode: self.session.languageCode,
selection: self.$retranscriptionLanguageCode,
isBusy: self.isRetranscribing,
onCancel: { self.isChoosingRetranscriptionLanguage = false },
@@ -1258,6 +1259,7 @@ struct MeetingTranscriptTextEditor: View {
private struct MeetingRetranscriptionLanguageSheet: View {
let languages: [VoiceEngineLanguage]
+ let currentLanguageCode: String
@Binding var selection: String
let isBusy: Bool
let onCancel: () -> Void
@@ -1295,7 +1297,12 @@ private struct MeetingRetranscriptionLanguageSheet: View {
Button(self.isBusy ? "Transcribing…" : "Transcribe", action: self.onConfirm)
.meetingGlassAction(prominent: true)
.keyboardShortcut(.defaultAction)
- .disabled(self.isBusy || MeetingRetranscriptionLanguage.canonicalCode(self.selection) == nil)
+ .disabled(
+ self.isBusy || !MeetingRetranscriptionLanguage.canRetranscribe(
+ selection: self.selection,
+ currentLanguageCode: self.currentLanguageCode
+ )
+ )
}
}
.padding(self.theme.metrics.spacing.xl)
diff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swift
index 845a8130..da9265c2 100644
--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift
+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift
@@ -200,7 +200,7 @@ struct MeetingTranscriptionView: View {
errorMessage: self.actionErrorMessage,
onStart: self.startRecording,
onStop: self.stopAndTranscribe,
- onRetrySession: { self.retryProcessingSession(id: $0.id) },
+ onRetrySession: { self.retryProcessingSession(id: $0.id, languageCode: MeetingRetranscriptionLanguage.failedAttemptLanguage(for: $0)) },
onRetranscribe: { self.retryProcessingSession(id: $0, languageCode: $1) },
onRevealAudio: self.revealCapturedAudio,
onRecordAgain: self.recordAgain,
@@ -251,7 +251,13 @@ struct MeetingTranscriptionView: View {
isLoading: !self.historySnapshot.hasLoaded,
isQuiescent: self.coordinator.isQuiescent,
onRefresh: { Task { await self.loadMeetingHistory() } },
- onRetry: { self.retryProcessingSession(id: $0) },
+ onRetry: { id in
+ let session = self.historySnapshot.sessions.first { $0.id == id }
+ self.retryProcessingSession(
+ id: id,
+ languageCode: session.flatMap(MeetingRetranscriptionLanguage.failedAttemptLanguage(for:))
+ )
+ },
onRevealAudio: self.revealCapturedAudio,
onExportAudio: self.exportAudio,
onExportTranscript: { self.exportTranscript($0, format: $1, includeEchoes: false) },
diff --git a/Tests/FluidDictationIntegrationTests/MeetingProviderOptionsTests.swift b/Tests/FluidDictationIntegrationTests/MeetingProviderOptionsTests.swift
index 52728a24..12236404 100644
--- a/Tests/FluidDictationIntegrationTests/MeetingProviderOptionsTests.swift
+++ b/Tests/FluidDictationIntegrationTests/MeetingProviderOptionsTests.swift
@@ -22,6 +22,8 @@ final class MeetingProviderOptionsTests: XCTestCase {
XCTAssertNil(MeetingRetranscriptionLanguage.canonicalCode("zh"))
XCTAssertNil(MeetingRetranscriptionLanguage.canonicalCode(" "))
XCTAssertEqual(MeetingRetranscriptionLanguage.displayName(for: "de"), "German")
+ XCTAssertFalse(MeetingRetranscriptionLanguage.canRetranscribe(selection: "en", currentLanguageCode: "en"))
+ XCTAssertTrue(MeetingRetranscriptionLanguage.canRetranscribe(selection: "nl", currentLanguageCode: "en"))
XCTAssertEqual(
MeetingFinalProcessingConfiguration(languageCode: "de").asrModel,
"parakeet-tdt"
diff --git a/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift b/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift
index 4a95d0cb..8e078d77 100644
--- a/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift
+++ b/Tests/FluidDictationIntegrationTests/MeetingRecoveryTests.swift
@@ -2642,6 +2642,46 @@ final class MeetingRecoveryTests: XCTestCase {
XCTAssertFalse(persisted.failures.isEmpty)
XCTAssertEqual(persisted.processingAttempts.map(\.languageCode), ["en", "nl"])
XCTAssertNotNil(persisted.processingAttempts.last?.errorCode)
+ XCTAssertEqual(MeetingRetranscriptionLanguage.failedAttemptLanguage(for: persisted), "nl")
+ }
+
+ func testFailedLanguageChangeWithoutAttemptMetadataKeepsOriginalLanguage() async throws {
+ let dir = self.makeTempDirectory()
+ defer { try? FileManager.default.removeItem(at: dir) }
+ let store = MeetingSessionStore(rootDirectory: dir)
+ var session = self.makeSession(
+ state: .completed,
+ endedAt: Date(),
+ audioTracks: [self.makeMicrophoneTrack(chunks: [self.makeFinalizedChunk()])]
+ )
+ session.languageCode = "en"
+ session.processingAttempts = []
+ let trackID = try XCTUnwrap(session.audioTracks.first?.id)
+ session.transcriptSegments = [self.makeTranscriptSegment(sourceTrackID: trackID, speakerID: nil)]
+ session.transcriptSegments[0].text = "Legacy transcript"
+ try await store.create(session)
+
+ let coordinator = MeetingSessionCoordinator(
+ store: store,
+ capture: StubCaptureController(),
+ processing: DiagnosticFailingProcessingController(error: ProcessingFailure()),
+ audioArbiter: StubArbiter()
+ )
+ await coordinator.ensureRestored()
+ do {
+ _ = try await coordinator.retryProcessing(sessionID: session.id, languageCode: "nl")
+ XCTFail("Expected the language-changing retry to fail during transcription")
+ } catch {
+ XCTAssertTrue(error is ProcessingFailure)
+ }
+
+ let saved = try await store.load(id: session.id)
+ let persisted = try XCTUnwrap(saved)
+ XCTAssertEqual(persisted.languageCode, "en")
+ XCTAssertEqual(persisted.state, .completed)
+ XCTAssertEqual(persisted.transcriptSegments.map(\.text), ["Legacy transcript"])
+ let exported = try JSONSerialization.jsonObject(with: MeetingTranscriptExporter.json(for: persisted)) as? [String: Any]
+ XCTAssertEqual(exported?["languageCode"] as? String, "en")
}
func testProcessingDiagnosticsPreserveFailureAndTranscriptAcrossRetries() async throws {