(_ transcribedText: String)
| 2804 | } |
| 2805 | |
| 2806 | private func reprocessDictationText(_ transcribedText: String) async { |
| 2807 | // If live recording is still active, stop it first so reprocess does not |
| 2808 | // leave ASR running in the background (which causes the next hotkey press |
| 2809 | // to behave like a stop instead of start). |
| 2810 | if self.asr.isRunning { |
| 2811 | DebugLogger.shared.info("Actions: stopping active recording before reprocess", source: "ContentView") |
| 2812 | await self.asr.stopWithoutTranscription() |
| 2813 | self.cancelPrewarmDictationIfNeeded() |
| 2814 | } |
| 2815 | |
| 2816 | self.setActiveRecordingMode(.dictate) |
| 2817 | self.menuBarManager.setProcessing(true) |
| 2818 | NotchOverlayManager.shared.updateTranscriptionText("Reprocessing...") |
| 2819 | await Task.yield() |
| 2820 | |
| 2821 | var aiFallbackReason: String? |
| 2822 | var postProcessingModel: String? |
| 2823 | let appInfo = self.getCurrentAppInfo() |
| 2824 | let normalizedTranscribedText = ASRService.applySpokenPunctuationFormatting( |
| 2825 | transcribedText, |
| 2826 | appName: appInfo.name, |
| 2827 | bundleID: appInfo.bundleId, |
| 2828 | windowTitle: appInfo.windowTitle |
| 2829 | ) |
| 2830 | var finalText = normalizedTranscribedText |
| 2831 | let shouldUseAI = DictationAIPostProcessingGate.isConfigured(for: .primary, appBundleID: appInfo.bundleId) |
| 2832 | if shouldUseAI { |
| 2833 | postProcessingModel = self.currentDictationAIModelInfo( |
| 2834 | dictationSlot: .primary, |
| 2835 | appBundleID: appInfo.bundleId |
| 2836 | ).model |
| 2837 | do { |
| 2838 | finalText = try await self.processTextWithAI( |
| 2839 | normalizedTranscribedText, |
| 2840 | dictationSlot: .primary |
| 2841 | ) |
| 2842 | } catch { |
| 2843 | DebugLogger.shared.error( |
| 2844 | "AI reprocess failed, falling back to raw transcription: \(error.localizedDescription)", |
| 2845 | source: "ContentView" |
| 2846 | ) |
| 2847 | aiFallbackReason = error.localizedDescription |
| 2848 | NotificationService.showAIProcessingFallback(error: error.localizedDescription) |
| 2849 | finalText = normalizedTranscribedText |
| 2850 | } |
| 2851 | } |
| 2852 | |
| 2853 | NotchOverlayManager.shared.updateTranscriptionText("") |
| 2854 | |
| 2855 | finalText = ASRService.applyDictationLiteralFormatting( |
| 2856 | finalText, |
| 2857 | appName: appInfo.name, |
| 2858 | bundleID: appInfo.bundleId, |
| 2859 | windowTitle: appInfo.windowTitle |
| 2860 | ) |
| 2861 | finalText = ASRService.applyGAAVFormatting(finalText) |
| 2862 | let precedingText = SettingsStore.shared.needsDictationFormattingContext |
| 2863 | ? TypingService.textBeforeCursorInFocusedField() |
no test coverage detected