Optimize Recorder performance and logging
This commit is contained in:
parent
073fa0e701
commit
b0cab253d0
@ -448,7 +448,7 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 123;
|
||||
CURRENT_PROJECT_VERSION = 125;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"VoiceInk/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = V6J6A3VWY2;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
@ -463,7 +463,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 14.0;
|
||||
MARKETING_VERSION = 1.23;
|
||||
MARKETING_VERSION = 1.25;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.prakashjoshipax.VoiceInk;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
@ -481,7 +481,7 @@
|
||||
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "Apple Development";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
CURRENT_PROJECT_VERSION = 123;
|
||||
CURRENT_PROJECT_VERSION = 125;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"VoiceInk/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = V6J6A3VWY2;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
@ -496,7 +496,7 @@
|
||||
"@executable_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 14.0;
|
||||
MARKETING_VERSION = 1.23;
|
||||
MARKETING_VERSION = 1.25;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = com.prakashjoshipax.VoiceInk;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
|
||||
@ -46,8 +46,6 @@ class Recorder: ObservableObject {
|
||||
} catch {
|
||||
logger.error("❌ Failed to restart recording after device change: \(error.localizedDescription)")
|
||||
}
|
||||
} else {
|
||||
logger.warning("⚠️ No file URL available to restart recording after device change.")
|
||||
}
|
||||
}
|
||||
isReconfiguring = false
|
||||
@ -64,14 +62,11 @@ class Recorder: ObservableObject {
|
||||
}
|
||||
|
||||
func startRecording(toOutputFile url: URL) async throws {
|
||||
logger.notice("▶️ startRecording called for: \(url.lastPathComponent)")
|
||||
|
||||
deviceManager.isRecordingActive = true
|
||||
|
||||
Task {
|
||||
_ = await mediaController.muteSystemAudio()
|
||||
}
|
||||
|
||||
Task {
|
||||
await mediaController.muteSystemAudio()
|
||||
}
|
||||
let deviceID = deviceManager.getCurrentDevice()
|
||||
if deviceID != 0 {
|
||||
do {
|
||||
@ -79,20 +74,10 @@ class Recorder: ObservableObject {
|
||||
} catch {
|
||||
logger.warning("⚠️ Failed to configure audio session for device \(deviceID), attempting to continue: \(error.localizedDescription)")
|
||||
}
|
||||
} else {
|
||||
logger.warning("⚠️ No input device found (deviceID is 0). Attempting to record with default.")
|
||||
}
|
||||
|
||||
engine = AVAudioEngine()
|
||||
|
||||
guard let engine = self.engine else {
|
||||
logger.error("❌ AVAudioEngine is nil after creation attempt.")
|
||||
await mediaController.unmuteSystemAudio()
|
||||
stopRecording()
|
||||
throw RecorderError.couldNotStartRecording
|
||||
}
|
||||
|
||||
let inputNode = engine.inputNode
|
||||
let inputNode = engine!.inputNode
|
||||
let inputFormat = inputNode.outputFormat(forBus: 0)
|
||||
|
||||
let whisperSettings: [String: Any] = [
|
||||
@ -115,8 +100,7 @@ class Recorder: ObservableObject {
|
||||
do {
|
||||
file = try AVAudioFile(forWriting: url, settings: whisperSettings)
|
||||
} catch {
|
||||
logger.error("❌ Failed to create audio file: \(error.localizedDescription)")
|
||||
await mediaController.unmuteSystemAudio()
|
||||
logger.error("Failed to create audio file: \(error.localizedDescription)")
|
||||
stopRecording()
|
||||
throw RecorderError.couldNotStartRecording
|
||||
}
|
||||
@ -181,11 +165,9 @@ class Recorder: ObservableObject {
|
||||
}
|
||||
|
||||
do {
|
||||
try engine.start()
|
||||
logger.notice("✅ Recording engine started successfully.")
|
||||
try engine!.start()
|
||||
} catch {
|
||||
logger.error("❌ Failed to start audio engine: \(error.localizedDescription)")
|
||||
await mediaController.unmuteSystemAudio()
|
||||
stopRecording()
|
||||
throw RecorderError.couldNotStartRecording
|
||||
}
|
||||
@ -199,10 +181,6 @@ class Recorder: ObservableObject {
|
||||
engine = nil
|
||||
}
|
||||
|
||||
if wasRunning {
|
||||
logger.notice("⏹️ Recording stopped.")
|
||||
}
|
||||
|
||||
audioMeter = AudioMeter(averagePower: 0, peakPower: 0)
|
||||
engine?.inputNode.removeTap(onBus: 0)
|
||||
file = nil
|
||||
@ -245,4 +223,4 @@ class Recorder: ObservableObject {
|
||||
struct AudioMeter: Equatable {
|
||||
let averagePower: Double
|
||||
let peakPower: Double
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user