2
votes

I have set up a simple graph, using AVAudioEngine, to simply take the default input node's data and put it in the headphones (audio monitoring) - this should simply make your headphones replicate whatever it hears through the microphone and it does, the background noise is redirected right into your ears, when running this app, however, there is one problem: it will always take the built-in mic's input, even if an external mic is plugged into the iPad.

AVAudioSession tells me, that the input should be using the external microphone (through [[AVAudioSession sharedInstance] currentRoute]) and if I record audio with AVAudioRecorder, it does use that input, however not AVAudioEngine, it sticks to the built-in mic. Am I doing something wrong? Is there a setting I missed?

1
I would like to specify, that this external mic is connected through a lightning adaptor - external microphones through the normal jack work well.Lehel Medves

1 Answers

3
votes

Try setting the preferred Input to the external mic:

    //get all avaialable Inputs
    var listOfInputs = AVAudioSession.sharedInstance().availableInputs
    println(listOfInputs)

    //pick which one you want (change index)
    var availableInput: AVAudioSessionPortDescription = listOfInputs[0] as AVAudioSessionPortDescription

    //set the Preffered Input
     AVAudioSession.sharedInstance().setPreferredInput(availableInput, error: nil)

Careful though, this is without error handling for simplicities sake. You will want to offer a default option if your external mic is unplugged or not available.