Search code examples
iosinputmicrophoneavaudiorecorderavaudiosession

Ignore microphone input with AVAudioRecorder and AVAudioSessionCategoryPlayAndRecord


I'm developing an iPad app with multiple AVAudioPlayer's and one AVAudioRecorder. The idea is to play the sound of the principal AvAudioPlayer like background music and touching different buttons play the sound of the others AVAudioPlayers to mix with the background music. The mixed music will be recorded by the AVAudioRecorder.

For that I implemented and AVAudioSession with category AVAudioSessionCategoryPlayAndRecord and create and AVAudioRecorder object with this settings:

NSDictionary *recordSetting = [NSDictionary dictionaryWithObjectsAndKeys:
                               [NSNumber numberWithInt:kAudioFormatAppleIMA4], AVFormatIDKey,
                               [NSNumber numberWithInt:AVAudioQualityHigh], AVEncoderAudioQualityKey,
                               [NSNumber numberWithInt:16], AVEncoderBitRateKey,
                               [NSNumber numberWithInt: 2], AVNumberOfChannelsKey,
                               [NSNumber numberWithFloat:44100.0], AVSampleRateKey,
                                nil];

Everything works fine, but the input of microphone it's recorded too, and that is not ok for me.

The ask is, how can I ignore/replace/eliminate the microphone input in my recording process?

I google for a long time and search on Apple documentation for AVAudioSession categories and modes, AVAudioRecorder settings, and nothing works for me.

I also search for mute microphone, but I read that is not possible on iOS devices.

Thanks in advance for your help and sorry for my faults writing english.


Solution

  • The AVAudioRecorder API is only for recording from the microphone.

    For creating audio files of any sounds an app makes, the app has to do the audio mixing in software (a mixer Audio Unit, or your own DSP code), and then compress, if needed, and save the resulting audio stream.