perf: faster recording start time

This commit is contained in:
Beingpax 2025-03-12 14:47:43 +05:45
parent 19142522bd
commit c148acefbd

View File

@ -197,23 +197,10 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate {
self.recordedFile = file
self.transcriptionStartTime = Date()
await ActiveWindowService.shared.applyConfigurationForCurrentApp()
if let enhancementService = self.enhancementService,
enhancementService.isEnhancementEnabled &&
enhancementService.useScreenCaptureContext {
await enhancementService.captureScreenContext()
Task.detached(priority: .background) {
await self.performBackgroundTasks()
}
if let currentModel = self.currentModel, self.whisperContext == nil {
do {
try await self.loadModel(currentModel)
} catch {
await MainActor.run {
self.messageLog += "Error preloading model: \(error.localizedDescription)\n"
}
}
}
} catch {
self.messageLog += "\(error.localizedDescription)\n"
self.isRecording = false
@ -227,6 +214,26 @@ class WhisperState: NSObject, ObservableObject, AVAudioRecorderDelegate {
}
}
private func performBackgroundTasks() async {
if let currentModel = self.currentModel, self.whisperContext == nil {
do {
try await self.loadModel(currentModel)
} catch {
await MainActor.run {
self.messageLog += "Error preloading model: \(error.localizedDescription)\n"
}
}
}
await ActiveWindowService.shared.applyConfigurationForCurrentApp()
if let enhancementService = self.enhancementService,
enhancementService.isEnhancementEnabled &&
enhancementService.useScreenCaptureContext {
await enhancementService.captureScreenContext()
}
}
private func requestRecordPermission(response: @escaping (Bool) -> Void) {
#if os(macOS)
response(true)