Currently I am developing an iOS app that records the screen with Replaykit and at the same time record the user from the front camera in a given time. I receive the audio from the screen recording and the front camera's audio is disabled. I would like to check the person's voice level during the screen and front camera recording. I believe that I already am using the microphone channel and for the screen recording. When I start screen recording I also start audio level checker but I can not see any value it always shows me -160. I don't know should I change the audio recorder settings dictionary or AVAudioSession category-mode. My recorder settings is like this:
settings = [
AVFormatIDKey : NSNumber(value: kAudioFormatLinearPCM),
AVSampleRateKey : 44100.0,
AVNumberOfChannelsKey : 2,
AVLinearPCMBitDepthKey : 16,
AVLinearPCMIsBigEndianKey : false,
AVLinearPCMIsFloatKey : false,
]
and my session
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try session.setMode(AVAudioSessionModeVideoRecording)
try session.setActive(true)
try session.overrideOutputAudioPort(.speaker)
}catch{
print("unable to set session")
return
}
also update parameters function in a timer callback
@objc private func checkAudioLevels() {
recorder.updateMeters()
print("Peak power0:\(recorder.peakPower(forChannel: 0))")
print("Average power0:\(recorder.averagePower(forChannel: 0))")
print("Peak power1:\(recorder.peakPower(forChannel: 1))")
print("Average power1:\(recorder.averagePower(forChannel: 1))")
print("Peak power2:\(recorder.peakPower(forChannel: 2))")
print("Average power2:\(recorder.averagePower(forChannel: 2))")
if recorder.peakPower(forChannel: 2) < -150{
levelCounter += 1 // timer fires every one second and if the user's audio is less than -150 it adds levelCounter 1 and if it reaches 10 which means no voice for 10 seconds it sends the warning to delegate.
}else{
levelCounter = 0
}
if levelCounter > 10{
self.delegate?.shouldShowWarning(true)
}
}
The problem is with all the peak and average power in all the channels, I only receive -160. So , I think I should change something in settings dictionary or AVAudioSession. My questions is that if it is possible to record the screen with audio and at the same time record an audio separately.