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

fix: reconcile rebase with upstream file-transcription changes

Shreeraman A K2cfb9af6ab26
diff --git a/Sources/Fluid/Services/FileTranscriptionService.swift b/Sources/Fluid/Services/FileTranscriptionService.swift
index 9e1f0eda..53252c0a 100644
--- a/Sources/Fluid/Services/FileTranscriptionService.swift
+++ b/Sources/Fluid/Services/FileTranscriptionService.swift
@@ -5,7 +5,7 @@ import Foundation
import UniformTypeIdentifiers
/// One speaker-attributed portion of a file transcription.
-struct SpeakerTranscriptSegment: Identifiable, Sendable, Codable, Equatable {
+nonisolated struct SpeakerTranscriptSegment: Identifiable, Sendable, Codable, Equatable {
let speaker: String
let startSeconds: Double
let endSeconds: Double
@@ -35,8 +35,198 @@ struct SpeakerTranscriptSegment: Identifiable, Sendable, Codable, Equatable {
}
}
+/// An audio interval for which speaker-attributed ASR produced no usable text.
+nonisolated struct SpeakerTranscriptGap: Sendable, Codable, Equatable {
+ let startSeconds: Double
+ let endSeconds: Double
+
+ var durationSeconds: Double {
+ max(0, self.endSeconds - self.startSeconds)
+ }
+
+ var timestampRangeText: String {
+ "\(Self.timestamp(self.startSeconds))-\(Self.timestamp(self.endSeconds))"
+ }
+
+ private static func timestamp(_ seconds: Double) -> String {
+ let safeSeconds = max(0, seconds)
+ let wholeMinutes = Int(safeSeconds) / 60
+ let remainingSeconds = safeSeconds - Double(wholeMinutes * 60)
+ return String(format: "%d:%04.1f", wholeMinutes, remainingSeconds)
+ }
+}
+
+nonisolated struct SpeakerChunkTranscription: Sendable, Equatable {
+ let text: String
+ let confidence: Float
+}
+
+nonisolated struct SpeakerTurnTranscription: Sendable, Equatable {
+ let text: String
+ let confidence: Float
+ let gaps: [SpeakerTranscriptGap]
+}
+
+nonisolated struct SpeakerRecognizedTurn: Sendable, Equatable {
+ let speaker: String
+ let startSeconds: Double
+ let endSeconds: Double
+ let transcription: SpeakerTurnTranscription
+}
+
+nonisolated struct SpeakerLabeledTranscript: Sendable, Equatable {
+ let segments: [SpeakerTranscriptSegment]
+ let confidence: Float
+ let gaps: [SpeakerTranscriptGap]
+ let notice: String?
+}
+
+nonisolated struct SpeakerLabelingCoverage: Sendable, Equatable {
+ let gapCount: Int
+ let skippedDurationSeconds: Double
+ let maxGapDurationSeconds: Double
+ let diarizedDurationSeconds: Double
+
+ var skippedRatio: Double {
+ guard self.diarizedDurationSeconds.isFinite, self.diarizedDurationSeconds > 0 else {
+ return self.skippedDurationSeconds > 0 ? .infinity : 0
+ }
+ return self.skippedDurationSeconds / self.diarizedDurationSeconds
+ }
+}
+
+nonisolated enum SpeakerLabeledTranscriptionPolicy {
+ static func transcribeChunks(
+ _ ranges: [SpeakerTranscriptGap],
+ operation: (SpeakerTranscriptGap) async throws -> SpeakerChunkTranscription?
+ ) async rethrows -> SpeakerTurnTranscription {
+ var pieces: [String] = []
+ var confidenceSum: Float = 0
+ var gaps: [SpeakerTranscriptGap] = []
+
+ for range in ranges {
+ let result = try await operation(range)
+ let text = result?.text.trimmingCharacters(in: .whitespacesAndNewlines) ?? ""
+ guard !text.isEmpty, let result else {
+ gaps.append(range)
+ continue
+ }
+
+ pieces.append(text)
+ confidenceSum += result.confidence
+ }
+
+ let confidence = pieces.isEmpty ? 0 : confidenceSum / Float(pieces.count)
+ return SpeakerTurnTranscription(
+ text: pieces.joined(separator: " "),
+ confidence: confidence,
+ gaps: gaps
+ )
+ }
+
+ static func shouldKeepSpeakerLabels(
+ hasRecognizedText: Bool,
+ gaps: [SpeakerTranscriptGap],
+ diarizedDurationSeconds: Double
+ ) -> Bool {
+ guard hasRecognizedText else { return false }
+ guard !gaps.isEmpty else { return true }
+ guard diarizedDurationSeconds.isFinite, diarizedDurationSeconds > 0 else { return false }
+
+ let coverage = self.coverage(
+ gaps: gaps,
+ diarizedDurationSeconds: diarizedDurationSeconds
+ )
+ guard coverage.maxGapDurationSeconds <= 5 else { return false }
+
+ let allowedSkippedDuration = min(30, diarizedDurationSeconds * 0.01)
+ return coverage.skippedDurationSeconds <= allowedSkippedDuration
+ }
+
+ static func coverage(
+ gaps: [SpeakerTranscriptGap],
+ diarizedDurationSeconds: Double
+ ) -> SpeakerLabelingCoverage {
+ let durations = gaps.map(\.durationSeconds)
+ return SpeakerLabelingCoverage(
+ gapCount: gaps.count,
+ skippedDurationSeconds: durations.reduce(0, +),
+ maxGapDurationSeconds: durations.max() ?? 0,
+ diarizedDurationSeconds: diarizedDurationSeconds
+ )
+ }
+
+ static func fallbackDiagnostic(
+ hasRecognizedText: Bool,
+ gaps: [SpeakerTranscriptGap],
+ diarizedDurationSeconds: Double
+ ) -> String {
+ guard hasRecognizedText else {
+ return "Speaker labeling produced no recognized text"
+ }
+ guard diarizedDurationSeconds.isFinite, diarizedDurationSeconds > 0 else {
+ return "Speaker labeling produced an invalid diarized duration"
+ }
+
+ let coverage = self.coverage(
+ gaps: gaps,
+ diarizedDurationSeconds: diarizedDurationSeconds
+ )
+ return String(
+ format: "Speaker labeling omitted too much audio (gaps=%d, skipped=%.3fs, maxGap=%.3fs, diarized=%.3fs, ratio=%.4f)",
+ coverage.gapCount,
+ coverage.skippedDurationSeconds,
+ coverage.maxGapDurationSeconds,
+ coverage.diarizedDurationSeconds,
+ coverage.skippedRatio
+ )
+ }
+
+ static func limitationNotice(for gaps: [SpeakerTranscriptGap]) -> String? {
+ guard !gaps.isEmpty else { return nil }
+ let noun = gaps.count == 1 ? "section" : "sections"
+ let duration = gaps.reduce(0) { $0 + $1.durationSeconds }
+ return "Speaker labels were kept, but \(gaps.count) short audio \(noun) totaling \(String(format: "%.1f", duration)) seconds produced no text."
+ }
+
+ static func assembleTurns(_ turns: [SpeakerRecognizedTurn]) -> SpeakerLabeledTranscript? {
+ let gaps = turns.flatMap(\.transcription.gaps)
+ let recognizedTurns = turns.filter {
+ !$0.transcription.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
+ }
+ let diarizedDuration = turns.reduce(0) {
+ $0 + max(0, $1.endSeconds - $1.startSeconds)
+ }
+ guard self.shouldKeepSpeakerLabels(
+ hasRecognizedText: !recognizedTurns.isEmpty,
+ gaps: gaps,
+ diarizedDurationSeconds: diarizedDuration
+ ) else {
+ return nil
+ }
+
+ let segments = recognizedTurns.map { turn in
+ SpeakerTranscriptSegment(
+ speaker: turn.speaker,
+ startSeconds: turn.startSeconds,
+ endSeconds: turn.endSeconds,
+ text: turn.transcription.text
+ )
+ }
+ let confidence = recognizedTurns.reduce(0) {
+ $0 + $1.transcription.confidence
+ } / Float(recognizedTurns.count)
+ return SpeakerLabeledTranscript(
+ segments: segments,
+ confidence: confidence,
+ gaps: gaps,
+ notice: self.limitationNotice(for: gaps)
+ )
+ }
+}
+
/// Result of a transcription operation
-struct TranscriptionResult: Identifiable, Sendable, Codable {
+nonisolated struct TranscriptionResult: Identifiable, Sendable, Codable {
let id: UUID
let text: String
let confidence: Float
@@ -46,6 +236,10 @@ struct TranscriptionResult: Identifiable, Sendable, Codable {
let timestamp: Date
/// Speaker-attributed segments when diarization was enabled; empty otherwise.
let speakerSegments: [SpeakerTranscriptSegment]
+ /// Persisted explanation when speaker labeling was partial or unavailable.
+ let speakerLabelingNotice: String?
+ /// Exact intervals omitted from an otherwise accepted speaker-attributed transcript.
+ let speakerLabelingGaps: [SpeakerTranscriptGap]
init(
id: UUID = UUID(),
@@ -55,7 +249,9 @@ struct TranscriptionResult: Identifiable, Sendable, Codable {
processingTime: TimeInterval,
fileName: String,
timestamp: Date = Date(),
- speakerSegments: [SpeakerTranscriptSegment] = []
+ speakerSegments: [SpeakerTranscriptSegment] = [],
+ speakerLabelingNotice: String? = nil,
+ speakerLabelingGaps: [SpeakerTranscriptGap] = []
) {
self.id = id
self.text = text
@@ -65,10 +261,13 @@ struct TranscriptionResult: Identifiable, Sendable, Codable {
self.fileName = fileName
self.timestamp = timestamp
self.speakerSegments = speakerSegments
+ self.speakerLabelingNotice = speakerLabelingNotice
+ self.speakerLabelingGaps = speakerLabelingGaps
}
enum CodingKeys: String, CodingKey {
case text, confidence, duration, processingTime, fileName, timestamp, speakerSegments
+ case speakerLabelingNotice, speakerLabelingGaps
}
init(from decoder: Decoder) throws {
@@ -81,6 +280,8 @@ struct TranscriptionResult: Identifiable, Sendable, Codable {
self.fileName = try c.decode(String.self, forKey: .fileName)
self.timestamp = try c.decode(Date.self, forKey: .timestamp)
self.speakerSegments = try c.decodeIfPresent([SpeakerTranscriptSegment].self, forKey: .speakerSegments) ?? []
+ self.speakerLabelingNotice = try c.decodeIfPresent(String.self, forKey: .speakerLabelingNotice)
+ self.speakerLabelingGaps = try c.decodeIfPresent([SpeakerTranscriptGap].self, forKey: .speakerLabelingGaps) ?? []
}
func encode(to encoder: Encoder) throws {
@@ -94,6 +295,27 @@ struct TranscriptionResult: Identifiable, Sendable, Codable {
if !self.speakerSegments.isEmpty {
try c.encode(self.speakerSegments, forKey: .speakerSegments)
}
+ try c.encodeIfPresent(self.speakerLabelingNotice, forKey: .speakerLabelingNotice)
+ if !self.speakerLabelingGaps.isEmpty {
+ try c.encode(self.speakerLabelingGaps, forKey: .speakerLabelingGaps)
+ }
+ }
+
+ var textExport: String {
+ var metadata = [
+ "Transcription: \(self.fileName)",
+ "Date: \(self.timestamp.formatted())",
+ "Duration: \(String(format: "%.1f", self.duration))s",
+ "Processing Time: \(String(format: "%.1f", self.processingTime))s",
+ "Confidence: \(String(format: "%.1f%%", self.confidence * 100))",
+ ]
+ if let speakerLabelingNotice {
+ metadata.append("Speaker labeling: \(speakerLabelingNotice)")
+ }
+ if !self.speakerLabelingGaps.isEmpty {
+ metadata.append("Unlabeled audio ranges: \(self.speakerLabelingGaps.map(\.timestampRangeText).joined(separator: ", "))")
+ }
+ return metadata.joined(separator: "\n") + "\n\n---\n\n" + self.text
}
}
@@ -101,13 +323,13 @@ struct TranscriptionResult: Identifiable, Sendable, Codable {
/// NOTE: This service shares the ASR models with ASRService to avoid duplicate memory usage
@MainActor
final class FileTranscriptionService: ObservableObject {
+ @Published private(set) var currentFileURL: URL?
@Published var isTranscribing: Bool = false
@Published var progress: Double = 0.0
@Published var currentStatus: String = ""
@Published var error: String?
@Published var result: TranscriptionResult?
@Published var fallbackNotice: String?
- @Published private(set) var currentFileURL: URL?
// MARK: - Supported Formats
@@ -164,28 +386,6 @@ final class FileTranscriptionService: ObservableObject {
}
}
- private func errorCategory(for error: Error) -> String {
- guard let transcriptionError = error as? TranscriptionError else {
- return "unknownError"
- }
- return self.errorCategory(for: transcriptionError)
- }
-
- private func errorCategory(for error: TranscriptionError) -> String {
- switch error {
- case .activityInProgress:
- return "activityInProgress"
- case .modelLoadFailed:
- return "modelLoadFailed"
- case .audioConversionFailed:
- return "audioConversionFailed"
- case .transcriptionFailed:
- return "transcriptionFailed"
- case .fileNotSupported:
- return "fileNotSupported"
- }
- }
-
/// Initialize the ASR models (reuses models from ASRService - no duplicate download!)
func initializeModels() async throws {
guard !self.asrService.isAsrReady else { return }
@@ -220,8 +420,8 @@ final class FileTranscriptionService: ObservableObject {
throw wrappedError
}
- self.isTranscribing = true
self.currentFileURL = fileURL
+ self.isTranscribing = true
error = nil
self.fallbackNotice = nil
self.progress = 0.0
@@ -253,6 +453,11 @@ final class FileTranscriptionService: ObservableObject {
.fileNotSupported("Format .\(fileExtension) not supported. \(Self.supportedFormatsDescription)")
}
+ AnalyticsService.shared.recordUsage(
+ mode: .meeting,
+ transcriptionModel: SettingsStore.shared.selectedSpeechModel.analyticsDescriptor
+ )
+
// Get audio duration for progress display
self.currentStatus = "Analyzing audio file..."
self.progress = 0.2
@@ -314,22 +519,13 @@ final class FileTranscriptionService: ObservableObject {
confidence: nativeResult.confidence,
duration: duration,
processingTime: processingTime,
- fileName: fileURL.lastPathComponent
+ fileName: fileURL.lastPathComponent,
+ speakerLabelingNotice: self.fallbackNotice
)
self.currentStatus = "Complete!"
self.progress = 1.0
- AnalyticsService.shared.capture(
- .meetingTranscriptionCompleted,
- properties: [
- "success": true,
- "file_type": fileURL.pathExtension.lowercased(),
- "audio_duration_bucket": AnalyticsBuckets.bucketSeconds(duration),
- "processing_time_bucket": AnalyticsBuckets.bucketSeconds(processingTime),
- ]
- )
-
self.result = result
FileTranscriptionHistoryStore.shared.addEntry(result)
return result
@@ -447,17 +643,8 @@ final class FileTranscriptionService: ObservableObject {
confidence: transcriptionResult.confidence,
duration: duration,
processingTime: processingTime,
- fileName: fileURL.lastPathComponent
- )
-
- AnalyticsService.shared.capture(
- .meetingTranscriptionCompleted,
- properties: [
- "success": true,
- "file_type": fileURL.pathExtension.lowercased(),
- "audio_duration_bucket": AnalyticsBuckets.bucketSeconds(duration),
- "processing_time_bucket": AnalyticsBuckets.bucketSeconds(processingTime),
- ]
+ fileName: fileURL.lastPathComponent,
+ speakerLabelingNotice: self.fallbackNotice
)
self.result = result
@@ -466,45 +653,17 @@ final class FileTranscriptionService: ObservableObject {
} catch let error as TranscriptionError {
self.error = error.localizedDescription
- AnalyticsService.shared.capture(
- .meetingTranscriptionCompleted,
- properties: [
- "success": false,
- "file_type": fileURL.pathExtension.lowercased(),
- "category": errorCategory(for: error),
- ]
- )
throw error
} catch {
let wrappedError = TranscriptionError.transcriptionFailed(error.localizedDescription)
self.error = wrappedError.localizedDescription
- AnalyticsService.shared.capture(
- .meetingTranscriptionCompleted,
- properties: [
- "success": false,
- "file_type": fileURL.pathExtension.lowercased(),
- "category": self.errorCategory(for: wrappedError),
- ]
- )
throw wrappedError
}
}
/// Export transcription result to text file
nonisolated func exportToText(_ result: TranscriptionResult, to destinationURL: URL) throws {
- let content = """
- Transcription: \(result.fileName)
- Date: \(result.timestamp.formatted())
- Duration: \(String(format: "%.1f", result.duration))s
- Processing Time: \(String(format: "%.1f", result.processingTime))s
- Confidence: \(String(format: "%.1f%%", result.confidence * 100))
-
- ---
-
- \(result.text)
- """
-
- try content.write(to: destinationURL, atomically: true, encoding: .utf8)
+ try result.textExport.write(to: destinationURL, atomically: true, encoding: .utf8)
}
/// Export transcription result to JSON
@@ -531,8 +690,9 @@ final class FileTranscriptionService: ObservableObject {
// MARK: - Speaker-Labeled Transcription
/// Diarize-first pipeline: identify speaker turns, then transcribe the audio slice for
- /// each turn with the active provider. Returns nil when diarization fails or yields
- /// nothing usable, so the caller can fall back to the standard transcription paths.
+ /// each turn with the active provider. Tiny empty ASR intervals can be retained as explicit
+ /// gaps. Material omissions or genuine errors return nil so the caller can run the standard
+ /// full-file transcription path instead.
private func transcribeFileWithSpeakerLabels(
_ fileURL: URL,
provider: TranscriptionProvider,
@@ -577,21 +737,18 @@ final class FileTranscriptionService: ObservableObject {
return nil
}
- var segments: [SpeakerTranscriptSegment] = []
- var totalConfidence: Float = 0
+ var recognizedTurns: [SpeakerRecognizedTurn] = []
for (index, turn) in turns.enumerated() {
self.currentStatus = "Transcribing speaker segments (\(index + 1)/\(turns.count))..."
self.progress = 0.3 + (Double(index) / Double(turns.count)) * 0.65
- let transcribed: (text: String, confidence: Float)?
+ let transcribed: SpeakerTurnTranscription
do {
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).
+ // A genuine audio-read or ASR failure can omit an unknown amount of speech.
+ // Use the standard full-file path rather than accepting uncertain labels.
DebugLogger.shared.warning(
"Speaker labeling aborted at segment \(index + 1)/\(turns.count) (\(String(format: "%.1f", turn.startSeconds))s): \(error.localizedDescription); falling back to standard transcription",
source: "FileTranscriptionService"
@@ -599,119 +756,97 @@ final class FileTranscriptionService: ObservableObject {
return nil
}
- // An empty result would omit this turn's time range. Fall back to the complete
- // full-file transcript rather than persist a labeled transcript with a silent gap.
- guard let transcribed else {
- DebugLogger.shared.warning(
- "Speaker segment \(index + 1)/\(turns.count) produced no text; falling back to standard transcription",
- source: "FileTranscriptionService"
- )
- return nil
- }
-
- segments.append(SpeakerTranscriptSegment(
+ recognizedTurns.append(SpeakerRecognizedTurn(
speaker: turn.speakerLabel,
startSeconds: turn.startSeconds,
endSeconds: turn.endSeconds,
- text: transcribed.text
+ transcription: transcribed
))
- totalConfidence += transcribed.confidence
}
- guard !segments.isEmpty else {
+ guard let labeledTranscript = SpeakerLabeledTranscriptionPolicy.assembleTurns(recognizedTurns) else {
+ let gaps = recognizedTurns.flatMap(\.transcription.gaps)
+ let diarizedDuration = recognizedTurns.reduce(0) {
+ $0 + max(0, $1.endSeconds - $1.startSeconds)
+ }
+ let hasRecognizedText = recognizedTurns.contains {
+ !$0.transcription.text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty
+ }
+ let diagnostic = SpeakerLabeledTranscriptionPolicy.fallbackDiagnostic(
+ hasRecognizedText: hasRecognizedText,
+ gaps: gaps,
+ diarizedDurationSeconds: diarizedDuration
+ )
DebugLogger.shared.warning(
- "No speaker segments produced text",
+ "\(diagnostic); falling back to standard transcription",
source: "FileTranscriptionService"
)
return nil
}
- let labeledText = segments
+ let labeledText = labeledTranscript.segments
.map(\.plainText)
.joined(separator: "\n\n")
- let avgConfidence = totalConfidence / Float(segments.count)
let processingTime = Date().timeIntervalSince(startTime)
let result = TranscriptionResult(
text: labeledText,
- confidence: avgConfidence,
+ confidence: labeledTranscript.confidence,
duration: duration,
processingTime: processingTime,
fileName: fileURL.lastPathComponent,
- speakerSegments: segments
+ speakerSegments: labeledTranscript.segments,
+ speakerLabelingNotice: labeledTranscript.notice,
+ speakerLabelingGaps: labeledTranscript.gaps
)
self.currentStatus = "Complete!"
self.progress = 1.0
- AnalyticsService.shared.capture(
- .meetingTranscriptionCompleted,
- properties: [
- "success": true,
- "file_type": fileURL.pathExtension.lowercased(),
- "audio_duration_bucket": AnalyticsBuckets.bucketSeconds(duration),
- "processing_time_bucket": AnalyticsBuckets.bucketSeconds(processingTime),
- "speaker_labels": true,
- "speaker_count": Set(segments.map(\.speaker)).count,
- ]
- )
-
self.result = result
FileTranscriptionHistoryStore.shared.addEntry(result)
return result
}
/// Transcribe a single speaker turn, splitting overlong turns into bounded chunks.
- /// 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.
+ /// Returns the concatenated text, mean confidence, and explicit empty ASR intervals.
+ /// Throws on a genuine audio-read or ASR failure so the caller can use full-file transcription.
private func transcribeSpeakerTurn(
_ turn: SpeakerDiarizationService.SpeakerTurn,
from audioFile: AVAudioFile,
provider: TranscriptionProvider
- ) async throws -> (text: String, confidence: Float)? {
+ ) async throws -> SpeakerTurnTranscription {
// Bound memory for unusually long single-speaker stretches. Providers remain free to
// apply their own model-specific, energy-aware chunking within each request.
let maxChunkSeconds: Double = 20 * 60
- var ranges: [(start: Double, end: Double)] = []
+ var ranges: [SpeakerTranscriptGap] = []
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))
+ ranges.append(SpeakerTranscriptGap(startSeconds: chunkStart, endSeconds: chunkEnd))
chunkStart = chunkEnd
}
} else {
- ranges.append((turn.startSeconds, turn.endSeconds))
+ ranges.append(SpeakerTranscriptGap(startSeconds: turn.startSeconds, endSeconds: turn.endSeconds))
}
- var pieces: [String] = []
- var confidenceSum: Float = 0
- var transcribedChunks = 0
-
- for range in ranges {
+ return try await SpeakerLabeledTranscriptionPolicy.transcribeChunks(ranges) { range in
let samples = try self.readSamples(
from: audioFile,
- startSeconds: range.start,
- endSeconds: range.end,
+ startSeconds: range.startSeconds,
+ endSeconds: range.endSeconds,
minimumDurationSeconds: 1.1
)
- // Mirror the standard path's 1-second ASR minimum.
guard samples.count >= 16_000 else { return nil }
let chunkResult = try await provider.transcribe(samples)
- let text = chunkResult.text.trimmingCharacters(in: .whitespacesAndNewlines)
- guard !text.isEmpty else { return nil }
-
- pieces.append(text)
- confidenceSum += chunkResult.confidence
- transcribedChunks += 1
+ return SpeakerChunkTranscription(
+ text: chunkResult.text,
+ confidence: chunkResult.confidence
+ )
}
-
- 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.
diff --git a/Sources/Fluid/UI/FileTranscriptionView.swift b/Sources/Fluid/UI/FileTranscriptionView.swift
index 70dd395a..d0b13baf 100644
--- a/Sources/Fluid/UI/FileTranscriptionView.swift
+++ b/Sources/Fluid/UI/FileTranscriptionView.swift
@@ -427,7 +427,7 @@ struct FileTranscriptionView: View {
.buttonStyle(.borderless)
}
- if let notice = transcriptionService.fallbackNotice {
+ if let notice = result.speakerLabelingNotice ?? transcriptionService.fallbackNotice {
Label(notice, systemImage: "exclamationmark.triangle.fill")
.font(.caption)
.foregroundColor(.secondary)
diff --git a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift
index d7030422..2e266892 100644
--- a/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift
+++ b/Tests/FluidDictationIntegrationTests/SpeakerTurnMergingTests.swift
@@ -531,6 +531,8 @@ final class SpeakerLabeledTranscriptionPolicyTests: XCTestCase {
]
XCTAssertNil(SpeakerLabeledTranscriptionPolicy.assembleTurns(turns))
+ }
+}
/// Word-timing mapping is meeting-only: `transcribeFinal` never reaches it.
final class FluidAudioProviderWordTimingTests: XCTestCase {