c7ee891a90
- Add FlowUtteranceEndCoordinator with 350ms silence drain and 150ms post-roll - Extend FinalChunkRecovery for short/empty final chunks in chunked pipeline - Snapshot partial at mic stop and guard final transcript in FlowSessionManager - Unify tail drain presets (iosFlow/macMLX) and expand diagnostics Co-authored-by: Rocky <hkgood@users.noreply.github.com>
36 lines
1.2 KiB
Swift
36 lines
1.2 KiB
Swift
// UtteranceTranscriptGuard.swift
|
|
// OSGKeyboard · Shared
|
|
//
|
|
// Chooses the best available transcript when pipelined final text may have
|
|
// dropped a weak tail segment.
|
|
|
|
import Foundation
|
|
|
|
public enum UtteranceTranscriptGuard {
|
|
/// Partial must exceed final by at least this many characters to win.
|
|
public static let defaultPartialAdvantage = 8
|
|
|
|
/// Prefer `stitchedFinal` unless empty or clearly shorter than the live
|
|
/// partial snapshot taken at mic stop.
|
|
public static func resolve(
|
|
stitchedFinal: String,
|
|
partialSnapshot: String,
|
|
minimumPartialAdvantage: Int = defaultPartialAdvantage
|
|
) -> String {
|
|
let final = stitchedFinal.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
let partial = partialSnapshot.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
if final.isEmpty { return partial }
|
|
if partial.isEmpty { return final }
|
|
|
|
if partial.count >= final.count + minimumPartialAdvantage {
|
|
FlowPipelineDiagnostics.logTranscriptGuardUsedPartial(
|
|
finalLength: final.count,
|
|
partialLength: partial.count
|
|
)
|
|
return partial
|
|
}
|
|
return final
|
|
}
|
|
}
|