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
fix: harden speaker-labeled file transcription
postoso4e5a89d8f479
diff --git a/Sources/Fluid/Persistence/BackupService.swift b/Sources/Fluid/Persistence/BackupService.swiftindex cf3fc71e..1b43ae34 100644--- a/Sources/Fluid/Persistence/BackupService.swift+++ b/Sources/Fluid/Persistence/BackupService.swift@@ -102,6 +102,8 @@ struct SettingsBackupPayload: Codable, Equatable {let editPromptRoutingScope: SettingsStore.PromptRoutingScope?let defaultDictationPromptOverride: String?let defaultEditPromptOverride: String?+ let fileTranscriptionSpeakerLabelsEnabled: Bool?+ let fileTranscriptionExpectedSpeakerCount: Int?}struct AppBackupDocument: Codable, Equatable {diff --git a/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift b/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swiftindex 3f31fe21..a646acd0 100644--- a/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift+++ b/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift@@ -18,6 +18,8 @@ struct FileTranscriptionEntry: Codable, Identifiable, Equatable {let processingTime: TimeIntervallet confidence: Floatlet text: String+ /// Speaker-attributed segments when diarization was enabled; empty otherwise.+ let speakerSegments: [SpeakerTranscriptSegment]init(id: UUID = UUID(),@@ -26,7 +28,8 @@ struct FileTranscriptionEntry: Codable, Identifiable, Equatable {duration: TimeInterval,processingTime: TimeInterval,confidence: Float,- text: String+ text: String,+ speakerSegments: [SpeakerTranscriptSegment] = []) {self.id = idself.timestamp = timestamp@@ -35,6 +38,7 @@ struct FileTranscriptionEntry: Codable, Identifiable, Equatable {self.processingTime = processingTimeself.confidence = confidenceself.text = text+ self.speakerSegments = speakerSegments}init(from result: TranscriptionResult) {@@ -45,6 +49,38 @@ struct FileTranscriptionEntry: Codable, Identifiable, Equatable {self.processingTime = result.processingTimeself.confidence = result.confidenceself.text = result.text+ self.speakerSegments = result.speakerSegments+ }++ enum CodingKeys: String, CodingKey {+ case id, timestamp, fileName, duration, processingTime, confidence, text, speakerSegments+ }++ init(from decoder: Decoder) throws {+ let c = try decoder.container(keyedBy: CodingKeys.self)+ self.id = try c.decode(UUID.self, forKey: .id)+ self.timestamp = try c.decode(Date.self, forKey: .timestamp)+ self.fileName = try c.decode(String.self, forKey: .fileName)+ self.duration = try c.decode(TimeInterval.self, forKey: .duration)+ self.processingTime = try c.decode(TimeInterval.self, forKey: .processingTime)+ self.confidence = try c.decode(Float.self, forKey: .confidence)+ self.text = try c.decode(String.self, forKey: .text)+ // Older history entries predate speaker labels — tolerate a missing key.+ self.speakerSegments = try c.decodeIfPresent([SpeakerTranscriptSegment].self, forKey: .speakerSegments) ?? []+ }++ func encode(to encoder: Encoder) throws {+ var c = encoder.container(keyedBy: CodingKeys.self)+ try c.encode(self.id, forKey: .id)+ try c.encode(self.timestamp, forKey: .timestamp)+ try c.encode(self.fileName, forKey: .fileName)+ try c.encode(self.duration, forKey: .duration)+ try c.encode(self.processingTime, forKey: .processingTime)+ try c.encode(self.confidence, forKey: .confidence)+ try c.encode(self.text, forKey: .text)+ if !self.speakerSegments.isEmpty {+ try c.encode(self.speakerSegments, forKey: .speakerSegments)+ }}/// Preview text for list display (first 80 chars)@@ -80,7 +116,8 @@ struct FileTranscriptionEntry: Codable, Identifiable, Equatable {duration: self.duration,processingTime: self.processingTime,fileName: self.fileName,- timestamp: self.timestamp+ timestamp: self.timestamp,+ speakerSegments: self.speakerSegments)}}diff --git a/Sources/Fluid/Persistence/SettingsStore.swift b/Sources/Fluid/Persistence/SettingsStore.swiftindex bcecd4df..8fa12707 100644--- a/Sources/Fluid/Persistence/SettingsStore.swift+++ b/Sources/Fluid/Persistence/SettingsStore.swift@@ -3103,7 +3103,9 @@ final class SettingsStore: ObservableObject {selectedEditPromptID: self.selectedEditPromptID,editPromptRoutingScope: self.editPromptRoutingScope,defaultDictationPromptOverride: self.defaultDictationPromptOverride,- defaultEditPromptOverride: self.defaultEditPromptOverride+ defaultEditPromptOverride: self.defaultEditPromptOverride,+ fileTranscriptionSpeakerLabelsEnabled: self.fileTranscriptionSpeakerLabelsEnabled,+ fileTranscriptionExpectedSpeakerCount: self.fileTranscriptionExpectedSpeakerCount)}@@ -3246,6 +3248,12 @@ final class SettingsStore: ObservableObject {self.selectedEditPromptID = payload.selectedEditPromptIDself.defaultDictationPromptOverride = payload.defaultDictationPromptOverrideself.defaultEditPromptOverride = payload.defaultEditPromptOverride+ if let fileTranscriptionSpeakerLabelsEnabled = payload.fileTranscriptionSpeakerLabelsEnabled {+ self.fileTranscriptionSpeakerLabelsEnabled = fileTranscriptionSpeakerLabelsEnabled+ }+ if let fileTranscriptionExpectedSpeakerCount = payload.fileTranscriptionExpectedSpeakerCount {+ self.fileTranscriptionExpectedSpeakerCount = fileTranscriptionExpectedSpeakerCount+ }self.promptModeSelectedPromptID = payload.promptModeSelectedPromptIDself.isSecondaryDictationPromptOff = payload.secondaryDictationPromptOff ?? falseself.normalizePromptSelectionsIfNeeded()diff --git a/Sources/Fluid/Services/MeetingTranscriptionService.swift b/Sources/Fluid/Services/MeetingTranscriptionService.swiftindex 5b2ebb22..0825b376 100644--- a/Sources/Fluid/Services/MeetingTranscriptionService.swift+++ b/Sources/Fluid/Services/MeetingTranscriptionService.swift@@ -529,46 +529,31 @@ final class MeetingTranscriptionService: ObservableObject {self.currentStatus = "Transcribing speaker segments (\(index + 1)/\(turns.count))..."self.progress = 0.3 + (Double(index) / Double(turns.count)) * 0.65- let samples: [Float]+ let transcribed: (text: String, confidence: Float)?do {- samples = try self.readSamples(- from: audioFile,- startSeconds: turn.startSeconds,- endSeconds: turn.endSeconds,- minimumDurationSeconds: 1.1- )- } catch {- DebugLogger.shared.warning(- "Skipping speaker segment at \(String(format: "%.1f", turn.startSeconds))s: \(error.localizedDescription)",- source: "MeetingTranscriptionService"- )- continue- }-- // Mirror the standard path's 1-second ASR minimum- guard samples.count >= 16_000 else { continue }-- let chunkResult: ASRTranscriptionResult- do {- chunkResult = try await provider.transcribe(samples)+ transcribed = try await self.transcribeSpeakerTurn(turn, from: audioFile, provider: provider)} catch {+ // A genuine audio-read or ASR failure would drop this turn's time range,+ // leaving a silent gap in the labeled transcript. Abandon the labeled path+ // so the caller re-transcribes the whole file — baseline behavior is never+ // at risk (a complete unlabeled transcript beats a labeled one with holes).DebugLogger.shared.warning(- "Transcription failed for speaker segment at \(String(format: "%.1f", turn.startSeconds))s: \(error.localizedDescription)",+ "Speaker labeling aborted at segment \(index + 1)/\(turns.count) (\(String(format: "%.1f", turn.startSeconds))s): \(error.localizedDescription); falling back to standard transcription",source: "MeetingTranscriptionService")- continue+ return nil}- let text = chunkResult.text.trimmingCharacters(in: .whitespacesAndNewlines)- guard !text.isEmpty else { continue }+ // No usable audio in this turn (too short or silent) — skip without losing content.+ guard let transcribed else { continue }segments.append(SpeakerTranscriptSegment(speaker: turn.speakerLabel,startSeconds: turn.startSeconds,endSeconds: turn.endSeconds,- text: text+ text: transcribed.text))- totalConfidence += chunkResult.confidence+ totalConfidence += transcribed.confidence}guard !segments.isEmpty else {@@ -614,6 +599,59 @@ final class MeetingTranscriptionService: ObservableObject {return result}+ /// Transcribe a single speaker turn, splitting overlong turns into model-sized chunks so a+ /// long single-speaker stretch never exceeds the ASR input limit (mirrors the standard+ /// path's 20-minute chunking). Returns the concatenated text and mean confidence, or nil+ /// when the turn holds no usable audio (too short or silent). Throws on a genuine audio-read+ /// or ASR failure so the caller can fall back to full-file transcription rather than emit a+ /// transcript with silent gaps.+ private func transcribeSpeakerTurn(+ _ turn: SpeakerDiarizationService.SpeakerTurn,+ from audioFile: AVAudioFile,+ provider: TranscriptionProvider+ ) async throws -> (text: String, confidence: Float)? {+ // Keep each ASR request well under the model's input limit, matching the standard path.+ let maxChunkSeconds: Double = 20 * 60++ var ranges: [(start: Double, end: Double)] = []+ if turn.endSeconds - turn.startSeconds > maxChunkSeconds {+ var chunkStart = turn.startSeconds+ while chunkStart < turn.endSeconds {+ let chunkEnd = min(chunkStart + maxChunkSeconds, turn.endSeconds)+ ranges.append((chunkStart, chunkEnd))+ chunkStart = chunkEnd+ }+ } else {+ ranges.append((turn.startSeconds, turn.endSeconds))+ }++ var pieces: [String] = []+ var confidenceSum: Float = 0+ var transcribedChunks = 0++ for range in ranges {+ let samples = try self.readSamples(+ from: audioFile,+ startSeconds: range.start,+ endSeconds: range.end,+ minimumDurationSeconds: 1.1+ )+ // Mirror the standard path's 1-second ASR minimum.+ guard samples.count >= 16_000 else { continue }++ let chunkResult = try await provider.transcribe(samples)+ let text = chunkResult.text.trimmingCharacters(in: .whitespacesAndNewlines)+ guard !text.isEmpty else { continue }++ pieces.append(text)+ confidenceSum += chunkResult.confidence+ transcribedChunks += 1+ }++ guard transcribedChunks > 0 else { return nil }+ return (pieces.joined(separator: " "), confidenceSum / Float(transcribedChunks))+ }+/// Read a time range from an audio file as 16kHz mono Float32 samples./// Short ranges are widened symmetrically to `minimumDurationSeconds` (clamped to/// the file bounds) so very brief speaker turns still meet the ASR input minimum.