fix(flow): improve tail capture and final chunk ASR recovery
- 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>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
// 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user