Centralize text formatting in main flows
This commit is contained in:
parent
02ae4a040b
commit
afd6e91207
@ -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)
|
||||||
|
|||||||
@ -62,7 +62,11 @@ class AudioTranscriptionService: ObservableObject {
|
|||||||
let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
|
let transcriptionDuration = Date().timeIntervalSince(transcriptionStart)
|
||||||
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)
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -70,11 +70,7 @@ 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)
|
||||||
|
|||||||
@ -134,11 +134,7 @@ 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
|
||||||
|
|||||||
@ -139,11 +139,7 @@ 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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -274,7 +274,11 @@ class WhisperState: NSObject, ObservableObject {
|
|||||||
if await checkCancellationAndCleanup() { return }
|
if await checkCancellationAndCleanup() { return }
|
||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user