Optimize recorder startup by backgrounding media controls

This commit is contained in:
Beingpax 2025-09-12 10:14:10 +05:45
parent 53d1507a53
commit 2a4f48ac0d
2 changed files with 8 additions and 10 deletions

View File

@ -76,15 +76,7 @@ class Recorder: NSObject, ObservableObject, AVAudioRecorderDelegate {
UserDefaults.standard.set(String(currentDeviceID), forKey: "lastUsedMicrophoneDeviceID")
hasDetectedAudioInCurrentSession = false
// Coordinate media control and system audio sequentially for better reliability
await playbackController.pauseMedia()
// Small delay to allow media command to process before muting system audio
try? await Task.sleep(nanoseconds: 100_000_000) // 100ms
_ = await mediaController.muteSystemAudio()
let deviceID = deviceManager.getCurrentDevice()
if deviceID != 0 {
do {
@ -114,6 +106,12 @@ class Recorder: NSObject, ObservableObject, AVAudioRecorderDelegate {
throw RecorderError.couldNotStartRecording
}
Task { [weak self] in
guard let self = self else { return }
await self.playbackController.pauseMedia()
_ = await self.mediaController.muteSystemAudio()
}
audioLevelCheckTask?.cancel()
audioMeterUpdateTask?.cancel()

View File

@ -6,7 +6,7 @@ class DictionaryContextService {
private init() {}
private let predefinedWords = "VoiceInk, chatGPT, GPT-4o, GPT-5-mini, Kimi-K2, GLM V4.5, Claude, Claude 4 sonnet, Claude opus, ultrathink, Vibe-coding, groq, cerebras, gpt-oss-120B, Wispr flow, deepseek, gemini-2.5, Veo 3, elevenlabs, Kyutai"
private let predefinedWords = "VoiceInk, chatGPT, GPT-4o, GPT-5-mini, Kimi-K2, GLM V4.5, Claude, Claude 4 sonnet, Claude opus, ultrathink, Vibe-coding, groq, cerebras, gpt-oss-120B, deepseek, gemini-2.5, Veo 3, elevenlabs, Kyutai"
func getDictionaryContext() -> String {
var allWords: [String] = []