fix: audiomanager fix
This commit is contained in:
@@ -25,10 +25,11 @@ class AudioManager: NSObject, ObservableObject {
|
|||||||
|
|
||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
NotificationCenter.default.addObserver(self,
|
NotificationCenter.default.addObserver(forName: .AVAudioEngineConfigurationChange,
|
||||||
selector: #selector(handleAudioEngineConfigurationChange),
|
object: audioEngine,
|
||||||
name: .AVAudioEngineConfigurationChange,
|
queue: .main) { [weak self] _ in
|
||||||
object: audioEngine)
|
self?.handleAudioEngineConfigurationChange()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
@@ -260,7 +261,7 @@ class AudioManager: NSObject, ObservableObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processAudioBuffer(_ buffer: AVAudioPCMBuffer, converter: AVAudioConverter, targetFormat: AVAudioFormat, source: AudioSource) {
|
private func processAudioBuffer(_ buffer: AVAudioPCMBuffer, converter: AVAudioConverter, targetFormat: AVAudioFormat, source: AudioSource) {
|
||||||
var processBuffer = buffer
|
let processBuffer = buffer
|
||||||
|
|
||||||
// Convert to target format (16kHz int16 mono) in a single step – AVAudioConverter will handle resampling and downmixing
|
// Convert to target format (16kHz int16 mono) in a single step – AVAudioConverter will handle resampling and downmixing
|
||||||
let outputFrameCapacity = AVAudioFrameCount(Double(processBuffer.frameLength) * targetFormat.sampleRate / processBuffer.format.sampleRate)
|
let outputFrameCapacity = AVAudioFrameCount(Double(processBuffer.frameLength) * targetFormat.sampleRate / processBuffer.format.sampleRate)
|
||||||
@@ -385,6 +386,11 @@ class AudioManager: NSObject, ObservableObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func handleAudioEngineConfigurationChange() {
|
||||||
|
print("🔔 Audio engine configuration changed - restarting mic")
|
||||||
|
restartMicrophone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - SCStreamDelegate & SCStreamOutput
|
// MARK: - SCStreamDelegate & SCStreamOutput
|
||||||
@@ -426,8 +432,3 @@ extension CMSampleBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func handleAudioEngineConfigurationChange(_ notification: Notification) {
|
|
||||||
print("🔔 Audio engine configuration changed - restarting mic")
|
|
||||||
restartMicrophone()
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user