|
|
|
@ -74,22 +74,26 @@ public final class TextProcessor { |
|
|
|
/// Lightweight inline formatter applied to live streaming chunks so words, domain terms, |
|
|
|
/// and numbers match the final post-processed text in real time. |
|
|
|
public func processLiveChunk(_ text: String) -> String { |
|
|
|
if text.isEmpty { return "" } |
|
|
|
let hasLeadingSpace = text.first?.isWhitespace == true |
|
|
|
let hasTrailingSpace = text.last?.isWhitespace == true |
|
|
|
if text.isEmpty { return "" } |
|
|
|
let hadLeadingSpace = text.first?.isWhitespace == true |
|
|
|
let hadTrailingSpace = text.last?.isWhitespace == true |
|
|
|
|
|
|
|
var result = text |
|
|
|
if SonioxSettings.shared.voicePunctuation { |
|
|
|
result = applyVoicePunctuation(result) |
|
|
|
} |
|
|
|
if SonioxSettings.shared.domainVocabulary { |
|
|
|
result = applyDomainVocabulary(result) |
|
|
|
} |
|
|
|
result = applyNumberFormatting(result, format: SonioxSettings.shared.numberFormat) |
|
|
|
var result = text |
|
|
|
if SonioxSettings.shared.voicePunctuation { |
|
|
|
result = applyVoicePunctuation(result) |
|
|
|
} |
|
|
|
if SonioxSettings.shared.domainVocabulary { |
|
|
|
result = applyDomainVocabulary(result) |
|
|
|
} |
|
|
|
result = applyNumberFormatting(result, format: SonioxSettings.shared.numberFormat) |
|
|
|
|
|
|
|
let trimmed = result.trimmingCharacters(in: .whitespaces) |
|
|
|
if trimmed.isEmpty { return text } |
|
|
|
return (hasLeadingSpace ? " " : "") + trimmed + (hasTrailingSpace ? " " : "") |
|
|
|
let resultHasLeadingSpace = result.first?.isWhitespace == true |
|
|
|
let resultHasTrailingSpace = result.last?.isWhitespace == true |
|
|
|
let trimmed = result.trimmingCharacters(in: .whitespaces) |
|
|
|
if trimmed.isEmpty { return text } |
|
|
|
let keepLeading = hadLeadingSpace || resultHasLeadingSpace |
|
|
|
let keepTrailing = hadTrailingSpace || resultHasTrailingSpace |
|
|
|
return (keepLeading ? " " : "") + trimmed + (keepTrailing ? " " : "") |
|
|
|
} |
|
|
|
|
|
|
|
public func applyDomainVocabularyInline(_ text: String) -> String { |
|
|
|
|