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) let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
text = WhisperHallucinationFilter.filter(text)
text = text.trimmingCharacters(in: .whitespacesAndNewlines) text = text.trimmingCharacters(in: .whitespacesAndNewlines)
if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true {
text = WhisperTextFormatter.format(text)
}
// Apply word replacements if enabled // Apply word replacements if enabled
if UserDefaults.standard.bool(forKey: "IsWordReplacementEnabled") { if UserDefaults.standard.bool(forKey: "IsWordReplacementEnabled") {
text = WordReplacementService.shared.applyReplacements(to: text) text = WordReplacementService.shared.applyReplacements(to: text)

View File

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

View File

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

View File

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

View File

@ -135,10 +135,6 @@ class NativeAppleTranscriptionService: TranscriptionService {
var finalTranscription = String(transcript.characters).trimmingCharacters(in: .whitespacesAndNewlines) 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.") logger.notice("Native transcription successful. Length: \(finalTranscription.count) characters.")
return finalTranscription return finalTranscription
#else #else

View File

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

View File

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