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)
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user