Centralize text formatting in main flows

This commit is contained in:
Beingpax 2025-09-19 09:09:05 +05:45
parent 02ae4a040b
commit afd6e91207
7 changed files with 19 additions and 22 deletions

View File

@ -111,8 +111,13 @@ class AudioTranscriptionManager: ObservableObject {
}
let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
text = WhisperHallucinationFilter.filter(text)
text = text.trimmingCharacters(in: .whitespacesAndNewlines)
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
text = WhisperTextFormatter.format(text)
}
// Apply word replacements if enabled
if UserDefaults.standard.bool(forKey: "IsWordReplacementEnabled") {
text = WordReplacementService.shared.applyReplacements(to: text)

View File

@ -62,7 +62,11 @@ class AudioTranscriptionService: ObservableObject {
let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
text = WhisperHallucinationFilter.filter(text)
text = text.trimmingCharacters(in: .whitespacesAndNewlines)
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
text = WhisperTextFormatter.format(text)
}
// Apply word replacements if enabled
if UserDefaults.standard.bool(forKey: "IsWordReplacementEnabled") {
text = WordReplacementService.shared.applyReplacements(to: text)

View File

@ -65,10 +65,6 @@ class CloudTranscriptionService: TranscriptionService {
throw CloudTranscriptionError.unsupportedProvider
}
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
text = WhisperTextFormatter.format(text)
}
return text
}

View File

@ -70,11 +70,7 @@ class LocalTranscriptionService: TranscriptionService {
}
var text = await whisperContext.getTranscription()
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
text = WhisperTextFormatter.format(text)
}
logger.notice("✅ Local transcription completed successfully.")
// Only release resources if we created a new context (not using the shared one)

View File

@ -134,11 +134,7 @@ class NativeAppleTranscriptionService: TranscriptionService {
}
var finalTranscription = String(transcript.characters).trimmingCharacters(in: .whitespacesAndNewlines)
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
finalTranscription = WhisperTextFormatter.format(finalTranscription)
}
logger.notice("Native transcription successful. Length: \(finalTranscription.count) characters.")
return finalTranscription
#else

View File

@ -139,11 +139,7 @@ class ParakeetTranscriptionService: TranscriptionService {
}
var text = result.text
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
text = WhisperTextFormatter.format(text)
}
return text
}

View File

@ -274,7 +274,11 @@ class WhisperState: NSObject, ObservableObject {
if await checkCancellationAndCleanup() { return }
text = text.trimmingCharacters(in: .whitespacesAndNewlines)
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
text = WhisperTextFormatter.format(text)
}
if UserDefaults.standard.bool(forKey: "IsWordReplacementEnabled") {
text = WordReplacementService.shared.applyReplacements(to: text)
}