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 persistent history for file transcriptions

Harry Hextall2ee6ffb217fc
diff --git a/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift b/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift
new file mode 100644
index 00000000..5acee844
--- /dev/null
+++ b/Sources/Fluid/Persistence/FileTranscriptionHistoryStore.swift
@@ -0,0 +1,168 @@
+//
+// FileTranscriptionHistoryStore.swift
+// Fluid
+//
+// Persistence for file (meeting) transcription history so results survive navigation.
+//
+
+import Combine
+import Foundation
+
+// MARK: - File Transcription Entry Model
+
+struct FileTranscriptionEntry: Codable, Identifiable, Equatable {
+ let id: UUID
+ let timestamp: Date
+ let fileName: String
+ let duration: TimeInterval
+ let processingTime: TimeInterval
+ let confidence: Float
+ let text: String
+
+ init(
+ id: UUID = UUID(),
+ timestamp: Date = Date(),
+ fileName: String,
+ duration: TimeInterval,
+ processingTime: TimeInterval,
+ confidence: Float,
+ text: String
+ ) {
+ self.id = id
+ self.timestamp = timestamp
+ self.fileName = fileName
+ self.duration = duration
+ self.processingTime = processingTime
+ self.confidence = confidence
+ self.text = text
+ }
+
+ init(from result: TranscriptionResult) {
+ self.id = result.id
+ self.timestamp = result.timestamp
+ self.fileName = result.fileName
+ self.duration = result.duration
+ self.processingTime = result.processingTime
+ self.confidence = result.confidence
+ self.text = result.text
+ }
+
+ /// Preview text for list display (first 80 chars)
+ var previewText: String {
+ let trimmed = self.text.trimmingCharacters(in: .whitespacesAndNewlines)
+ if trimmed.count > 80 {
+ return String(trimmed.prefix(77)) + "..."
+ }
+ return trimmed
+ }
+
+ /// Relative time string for display
+ var relativeTimeString: String {
+ let formatter = RelativeDateTimeFormatter()
+ formatter.unitsStyle = .abbreviated
+ return formatter.localizedString(for: self.timestamp, relativeTo: Date())
+ }
+
+ /// Full formatted date string
+ var fullDateString: String {
+ let formatter = DateFormatter()
+ formatter.dateStyle = .medium
+ formatter.timeStyle = .short
+ return formatter.string(from: self.timestamp)
+ }
+
+ /// Convert to TranscriptionResult for reuse of export/copy UI
+ func toTranscriptionResult() -> TranscriptionResult {
+ TranscriptionResult(
+ id: self.id,
+ text: self.text,
+ confidence: self.confidence,
+ duration: self.duration,
+ processingTime: self.processingTime,
+ fileName: self.fileName,
+ timestamp: self.timestamp
+ )
+ }
+}
+
+// MARK: - File Transcription History Store
+
+@MainActor
+final class FileTranscriptionHistoryStore: ObservableObject {
+ static let shared = FileTranscriptionHistoryStore()
+
+ private let defaults = UserDefaults.standard
+ private let maxEntries = 50
+
+ private enum Keys {
+ static let fileTranscriptionHistory = "FileTranscriptionHistoryEntries"
+ }
+
+ @Published private(set) var entries: [FileTranscriptionEntry] = []
+ @Published var selectedEntryID: UUID?
+
+ private init() {
+ self.loadEntries()
+ }
+
+ // MARK: - Public Methods
+
+ var selectedEntry: FileTranscriptionEntry? {
+ guard let id = selectedEntryID else { return nil }
+ return self.entries.first(where: { $0.id == id })
+ }
+
+ /// Add a completed file transcription to history (call after successful transcribeFile).
+ func addEntry(_ result: TranscriptionResult) {
+ guard !result.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty else { return }
+
+ let entry = FileTranscriptionEntry(from: result)
+ self.entries.insert(entry, at: 0)
+
+ if self.entries.count > maxEntries {
+ self.entries.removeLast()
+ }
+
+ self.selectedEntryID = entry.id
+ self.saveEntries()
+
+ DebugLogger.shared.debug(
+ "Added file transcription to history (total: \(self.entries.count))",
+ source: "FileTranscriptionHistoryStore"
+ )
+ }
+
+ func deleteEntry(id: UUID) {
+ self.entries.removeAll { $0.id == id }
+ if self.selectedEntryID == id {
+ self.selectedEntryID = self.entries.first?.id
+ }
+ self.saveEntries()
+ }
+
+ func clearAll() {
+ self.entries.removeAll()
+ self.selectedEntryID = nil
+ self.saveEntries()
+ DebugLogger.shared.info("Cleared all file transcription history", source: "FileTranscriptionHistoryStore")
+ }
+
+ // MARK: - Persistence
+
+ private func loadEntries() {
+ guard let data = self.defaults.data(forKey: Keys.fileTranscriptionHistory),
+ let decoded = try? JSONDecoder().decode([FileTranscriptionEntry].self, from: data)
+ else {
+ self.entries = []
+ return
+ }
+ self.entries = decoded
+ }
+
+ private func saveEntries() {
+ if let encoded = try? JSONEncoder().encode(self.entries) {
+ self.defaults.set(encoded, forKey: Keys.fileTranscriptionHistory)
+ }
+ self.objectWillChange.send()
+ }
+}
diff --git a/Sources/Fluid/Services/MeetingTranscriptionService.swift b/Sources/Fluid/Services/MeetingTranscriptionService.swift
index 22a93710..f3a1367d 100644
--- a/Sources/Fluid/Services/MeetingTranscriptionService.swift
+++ b/Sources/Fluid/Services/MeetingTranscriptionService.swift
@@ -5,17 +5,56 @@ import Foundation
/// Result of a transcription operation
struct TranscriptionResult: Identifiable, Sendable, Codable {
- let id = UUID()
+ let id: UUID
let text: String
let confidence: Float
let duration: TimeInterval
let processingTime: TimeInterval
let fileName: String
- let timestamp: Date = .init()
+ let timestamp: Date
+
+ init(
+ id: UUID = UUID(),
+ text: String,
+ confidence: Float,
+ duration: TimeInterval,
+ processingTime: TimeInterval,
+ fileName: String,
+ timestamp: Date = Date()
+ ) {
+ self.id = id
+ self.text = text
+ self.confidence = confidence
+ self.duration = duration
+ self.processingTime = processingTime
+ self.fileName = fileName
+ self.timestamp = timestamp
+ }
enum CodingKeys: String, CodingKey {
case text, confidence, duration, processingTime, fileName, timestamp
}
+
+ init(from decoder: Decoder) throws {
+ let c = try decoder.container(keyedBy: CodingKeys.self)
+ self.id = UUID()
+ self.text = try c.decode(String.self, forKey: .text)
+ self.confidence = try c.decode(Float.self, forKey: .confidence)
+ self.duration = try c.decode(TimeInterval.self, forKey: .duration)
+ self.processingTime = try c.decode(TimeInterval.self, forKey: .processingTime)
+ self.fileName = try c.decode(String.self, forKey: .fileName)
+ self.timestamp = try c.decode(Date.self, forKey: .timestamp)
+ }
+
+ func encode(to encoder: Encoder) throws {
+ var c = encoder.container(keyedBy: CodingKeys.self)
+ try c.encode(text, forKey: .text)
+ try c.encode(confidence, forKey: .confidence)
+ try c.encode(duration, forKey: .duration)
+ try c.encode(processingTime, forKey: .processingTime)
+ try c.encode(fileName, forKey: .fileName)
+ try c.encode(timestamp, forKey: .timestamp)
+ }
}
/// Service for transcribing complete audio/video files with optional speaker diarization
@@ -258,6 +297,7 @@ final class MeetingTranscriptionService: ObservableObject {
)
self.result = result
+ FileTranscriptionHistoryStore.shared.addEntry(result)
return result
} catch let error as TranscriptionError {
diff --git a/Sources/Fluid/UI/MeetingTranscriptionView.swift b/Sources/Fluid/UI/MeetingTranscriptionView.swift
index 90e7a6e3..2bcbf199 100644
--- a/Sources/Fluid/UI/MeetingTranscriptionView.swift
+++ b/Sources/Fluid/UI/MeetingTranscriptionView.swift
@@ -4,6 +4,7 @@ import UniformTypeIdentifiers
struct MeetingTranscriptionView: View {
let asrService: ASRService
@StateObject private var transcriptionService: MeetingTranscriptionService
+ @ObservedObject private var fileHistoryStore = FileTranscriptionHistoryStore.shared
@State private var selectedFileURL: URL?
@Environment(\.theme) private var theme
@@ -14,6 +15,7 @@ struct MeetingTranscriptionView: View {
@State private var showingFilePicker = false
@State private var showingExportDialog = false
+ @State private var exportResult: TranscriptionResult?
@State private var exportFormat: ExportFormat = .text
@State private var showingCopyConfirmation = false
@@ -68,6 +70,13 @@ struct MeetingTranscriptionView: View {
if let error = transcriptionService.error {
self.errorCard(error: error)
}
+
+ // Recent transcriptions (persisted history)
+ if !self.fileHistoryStore.entries.isEmpty {
+ Divider()
+ .padding(.vertical, 8)
+ self.recentTranscriptionsSection
+ }
}
.padding(24)
}
@@ -87,6 +96,24 @@ struct MeetingTranscriptionView: View {
.transition(.move(edge: .top).combined(with: .opacity))
}
}
+ .fileExporter(
+ isPresented: self.$showingExportDialog,
+ document: TranscriptionDocument(
+ result: self.exportResult ?? TranscriptionResult(text: "", confidence: 0, duration: 0, processingTime: 0, fileName: "transcript"),
+ format: self.exportFormat,
+ service: self.transcriptionService
+ ),
+ contentType: self.exportFormat == .text ? .plainText : .json,
+ defaultFilename: "\((self.exportResult?.fileName).map { "\($0)_transcript" } ?? "transcript").\(self.exportFormat.fileExtension)"
+ ) { exportCompletion in
+ switch exportCompletion {
+ case .success:
+ DebugLogger.shared.info("File exported successfully", source: "MeetingTranscriptionView")
+ case let .failure(error):
+ DebugLogger.shared.error("Export failed: \(error)", source: "MeetingTranscriptionView")
+ }
+ self.exportResult = nil
+ }
}
// MARK: - File Selection Card
@@ -264,6 +291,7 @@ struct MeetingTranscriptionView: View {
.help("Copy to clipboard")
Button(action: {
+ self.exportResult = result
self.showingExportDialog = true
}) {
Image(systemName: "square.and.arrow.up")
@@ -302,23 +330,146 @@ struct MeetingTranscriptionView: View {
.stroke(self.theme.palette.cardBorder.opacity(0.45), lineWidth: 1)
)
)
- .fileExporter(
- isPresented: self.$showingExportDialog,
- document: TranscriptionDocument(
- result: result,
- format: self.exportFormat,
- service: self.transcriptionService
- ),
- contentType: self.exportFormat == .text ? .plainText : .json,
- defaultFilename: "\(result.fileName)_transcript.\(self.exportFormat.fileExtension)"
- ) { result in
- switch result {
- case .success:
- DebugLogger.shared.info("File exported successfully", source: "MeetingTranscriptionView")
- case let .failure(error):
- DebugLogger.shared.error("Export failed: \(error)", source: "MeetingTranscriptionView")
+ }
+
+ // MARK: - Recent Transcriptions Section
+
+ private var recentTranscriptionsSection: some View {
+ VStack(alignment: .leading, spacing: 16) {
+ HStack {
+ Text("Recent transcriptions")
+ .font(.headline)
+ Spacer()
+ if !self.fileHistoryStore.entries.isEmpty {
+ Button("Clear all") {
+ self.fileHistoryStore.clearAll()
+ }
+ .buttonStyle(.plain)
+ .foregroundColor(.secondary)
+ .font(.caption)
+ }
+ }
+
+ VStack(spacing: 8) {
+ ForEach(self.fileHistoryStore.entries) { entry in
+ self.recentEntryRow(entry: entry)
+ }
+ }
+
+ if let entry = self.fileHistoryStore.selectedEntry {
+ self.historyDetailCard(entry: entry)
+ }
+ }
+ }
+
+ private func recentEntryRow(entry: FileTranscriptionEntry) -> some View {
+ let isSelected = self.fileHistoryStore.selectedEntryID == entry.id
+ return Button(action: {
+ self.fileHistoryStore.selectedEntryID = entry.id
+ }) {
+ HStack {
+ Image(systemName: "doc.text.fill")
+ .font(.body)
+ .foregroundColor(Color.fluidGreen)
+ .frame(width: 24)
+
+ VStack(alignment: .leading, spacing: 2) {
+ Text(entry.fileName)
+ .font(.system(size: 14, weight: .medium))
+ .lineLimit(1)
+ Text(entry.relativeTimeString)
+ .font(.caption)
+ .foregroundColor(.secondary)
+ Text(entry.previewText)
+ .font(.caption)
+ .foregroundColor(.secondary)
+ .lineLimit(1)
+ }
+
+ Spacer()
+
+ if isSelected {
+ Image(systemName: "chevron.right.circle.fill")
+ .foregroundColor(Color.fluidGreen)
+ }
+ }
+ .padding(12)
+ .background(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .fill(self.theme.palette.cardBackground)
+ .overlay(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .stroke(isSelected ? Color.fluidGreen.opacity(0.5) : self.theme.palette.cardBorder.opacity(0.3), lineWidth: isSelected ? 2 : 1)
+ )
+ )
+ }
+ .buttonStyle(.plain)
+ }
+
+ private func historyDetailCard(entry: FileTranscriptionEntry) -> some View {
+ let result = entry.toTranscriptionResult()
+ return VStack(alignment: .leading, spacing: 16) {
+ HStack {
+ VStack(alignment: .leading, spacing: 4) {
+ Text("From history")
+ .font(.headline)
+ HStack(spacing: 16) {
+ Label("\(String(format: "%.1f", entry.duration))s", systemImage: "clock")
+ Label("\(String(format: "%.0f%%", entry.confidence * 100))", systemImage: "checkmark.circle")
+ Label(entry.fullDateString, systemImage: "calendar")
+ }
+ .font(.caption)
+ .foregroundColor(.secondary)
+ }
+ Spacer()
+ HStack(spacing: 8) {
+ Button(action: { self.copyToClipboard(entry.text) }) {
+ Image(systemName: "doc.on.doc")
+ }
+ .help("Copy to clipboard")
+ Button(action: {
+ self.exportResult = result
+ self.showingExportDialog = true
+ }) {
+ Image(systemName: "square.and.arrow.up")
+ }
+ .help("Export transcription")
+ Button(action: {
+ self.fileHistoryStore.deleteEntry(id: entry.id)
+ }) {
+ Image(systemName: "trash")
+ }
+ .help("Remove from history")
+ }
+ .buttonStyle(.borderless)
}
+ Divider()
+ ScrollView {
+ Text(entry.text)
+ .font(.body)
+ .textSelection(.enabled)
+ .frame(maxWidth: .infinity, alignment: .leading)
+ .padding()
+ }
+ .frame(maxHeight: 300)
+ .background(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .fill(self.theme.palette.contentBackground)
+ .overlay(
+ RoundedRectangle(cornerRadius: 8, style: .continuous)
+ .stroke(self.theme.palette.cardBorder.opacity(0.45), lineWidth: 1)
+ )
+ )
}
+ .padding()
+ .background(
+ RoundedRectangle(cornerRadius: 12, style: .continuous)
+ .fill(self.theme.palette.cardBackground)
+ .overlay(
+ RoundedRectangle(cornerRadius: 12, style: .continuous)
+ .stroke(self.theme.palette.cardBorder.opacity(0.45), lineWidth: 1)
+ )
+ )
}
// MARK: - Error Card