AVAudioRecorder records silence

We have application using PTT Framework to record audio messages when app is backgrounded. Right now we are using AVAudioRecorder for that purpose. And problem is one specific user has frequent issue - recorded audio contains only silence. I've checked almost everything I can imagine but didn't find any possible reason of issue.

Conditions:

  1. AVAudioRecorder uses following configuration:

[ AVEncoderAudioQualityKey: AVAudioQuality.low.rawValue, AVFormatIDKey : kAudioFormatMPEG4AAC, AVNumberOfChannelsKey: 1, AVSampleRateKey: 16000.0 ]

  1. App waits both didBeginTransmitting and didActivate audioSession from PTChannelManager (audio session has playback category at that moment)
  2. App does AVAudioSession category change to playAndRecord
  3. App gets routeChangeNotification with categoryChange and category = playAndRecord
  4. There is no any interruption notifications from AVAudioSession during recording
  5. There is no any error notification from AVAudioRecorder

Any idea what exactly I do wrong? Is there anything else I should check?

Thanks in advance.

P.S. it looks like recording audio with AudioUnit has the same issue, but let's exclude it from question atm for simplicity.

We have application using PTT Framework to record audio messages when app is backgrounded. Right now we are using AVAudioRecorder for that purpose.

FYI, I'm not certain this will actually work correctly. Just like CallKit, the PTT framework needs to handle audio session activation so that it can modify the audio session configuration and then activate the session "itself". That model doesn't really work with a high level API like AVAudioRecorder.

And problem is one specific user has frequent issue - recorded audio contains only silence. I've checked almost everything I can imagine but didn't find any possible reason of issue.

In terms of this being one user, the thing I would look at here is what other audio hardware or software might be involved, as the simplest explanation is that he's recording silence because that's what he underlying audio route is sending.

Finally, in the sequence here:

  1. App waits both didBeginTransmitting and didActivate audioSession from PTChannelManager (audio session has playback category at that moment)
  2. App does AVAudioSession category change to playAndRecord
  3. App gets routeChangeNotification with categoryChange and category = playAndRecord
  4. There is no any interruption notifications from AVAudioSession during recording
  5. There is no any error notification from AVAudioRecorder

I'm not sure how specific that sequence was, but you should be configuring your session early as possible and specifically before "didActivate". Once the session is activated, it's already to late.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

FYI, I'm not certain this will actually work correctly. Just like CallKit, the PTT framework needs to handle audio session activation so that it can modify the audio session configuration and then activate the session "itself". That model doesn't really work with a high level API like AVAudioRecorder.

App creates AVAudioRecorder only after didActivate and switch to playAndRecord category. Do you mean AVAudioRecorder can alter some way Audio Session even in that case?

but you should be configuring your session early as possible and specifically before "didActivate". Once the session is activated, it's already to late.

Do you mean app should set playAndRecord category before didActivate? But when? After didBeginTransmitting and before didActivate, right?

AVAudioRecorder records silence
 
 
Q