Search code examples
iosswiftswiftuiios15

How do you enable mic mode in new iOS 15?


With the new iOS version there's a new mic mode that i need to enable on my app. However i don't see any example in Google or in YouTube. If someone can help me in showing how to enable mic mode in new iOS 15, would be great help.

Thankyou. enter image description here


Solution

  • From my testing, it doesn't seem possible to set the microphone mode to standard, voice isolation or wide spectrum programmatically. Though you might be able to get what the microphone mode value is. However, using these steps, you can allow your users to set it up by themselves:

    1. You have to first make sure you setVoiceProcessingEnabled and set isVoiceProcessingAGCEnabled to true.
    let audioSession = AVAudioSession.sharedInstance()
    do {
        try? audioSession.setCategory(.playAndRecord, mode: .videoRecording, options: .allowBluetooth)
        try? audioSession.setActive(true)
    
        let node = audioEngine.inputNode
        node.isVoiceProcessingAGCEnabled = true
        node.isVoiceProcessingBypassed = false
        node.isVoiceProcessingInputMuted = false
        try? node.setVoiceProcessingEnabled(true)
    ...
    
    1. After that, you can set a button to be tapped that runs this code while the microphone is actively in use
    AVCaptureDevice.showSystemUserInterface(.microphoneModes)
    

    Then the user is able to make a change to either wideSpectrum or voiceIsolation. Without following step 1, you will get an error message saying that the Microphone mode cannot be changed