Volume issue when Voice Processing IO is used

I just filed a bug report with Apple, but I wanted to post here in case people had input about this. I would love to hear that there is just some assumption or logic that I am messing up.

When an AVAudioEngine with voice processing io enabled is running, all other audio sources within the app that are started later will have low volume (seemingly not routed to the speakers?). After either setting the AVAudioSession category to .playAndRecord or overriding the AVAudioSession output route to speaker, the volume corrects itself (output seems to route to the speakers now).

The exact reproduction steps in the code can be broken down as follows. Make sure you have record permissions:

  1. Create an AVAudioEngine
  2. Access each engine's .mainMixerNode
  3. Create an AVPlayer with some audio file (This is also reproducible with AVAudioPlayer and AVAudioEngine)
  4. Configure the session with the following: AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .videoChat, options: [.defaultToSpeaker]) (Note that I'm setting .defaultToSpeaker)
  5. Activate the session with AVAudioSession.sharedInstance().setActive(true)
  6. Enable voice processing on the engine with the following: try! engine.outputNode.setVoiceProcessingEnabled(true)
  7. Start engine with the following: try! engine.start()
  8. Start the AVPlayer and note the volume. You may need to increase the system volume to hear what you're playing.
  9. You can call either of the following and the audio from the AVPlayer will fix its volume:
  • AVAudioSession.sharedInstance().setCategory(AVAudioSession.sharedInstance().category)
  • AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)
  1. Note that the volume instantly raises
  2. If you were to have another audio source (AVAudioPlayer, AVPlayer, AVAudioEngine), that is started after step 9, you would need to repeat step 9 again.

Obviously, this is not ideal and can cause some very unexpected volume changes for end users.

This was reproducible on iOS 13.6, 15.7, and 16.2.1 (latest).

If anyone has ideas as to how to prevent this or work around it other than the workaround demonstrated here, I'm all ears.

My VoIP app has the same issues. Regarding your step 9, there are some other ways for me to increase the volume.:

AVAudioSession.sharedInstance().overrideOutputAudioPort(.none)
AVAudioSession.sharedInstance().overrideOutputAudioPort(.speaker)

or the user changes the output to the receiver and then switches to the speaker (without using .defaultToSpeaker).

I think when using .playAndRecord, all sounds will be played with a low volume. Additionally, the Voice Processing IO can further decrease or increase the volume. So, there are three different cases when it comes to volume:

  • Low when using .playAndRecord only
  • Lowest when using Voice Processing IO
  • Highest after step 9

I tried using Remote I/O and my sound always plays at a stable low volume. I can easily fix this issue by changing the sound file. However, I encountered a bigger problem - the volume during conversation is very low. So, I have decided to abandon this solution.

To conclude, my main objective is to achieve a stable volume in Voice Processing IO.

I'm experiencing the same problem and after much experimenting, came to be using the same workaround as the original poster. I'm glad it's not just me. Following this issue in the hopes of a solution in the future.

I'm wondering if the OP or anyone else found a way of detecting if the audio has changed to be quiet/loud. The category/mode/options all stay the same and there doesn't seem to be an overrideOutputAudioPort property on AVAudioSession. I'm trying to detect if it has changed, and if it has, trigger the fix to return audio to normal volume.

I think the volume is being manipulated at a lower level than we really have access to, at least for AVPlayer and AVAudioPlayer.

Hi @SpencerAirtime, just wondering if Apple's responded re. your bug report?

I'm seeing an identical issue when using PitchTap from Audiokit, so again it's related to microphone input and processing the audio. Sadly with the suggested work arounds PitchTap stops working.

i am facing the same issue does anyone got any reply from apple?

Volume issue when Voice Processing IO is used
 
 
Q