AVAudioSession
is only the very first step to getting iOS to recognize that your app wants to do something with the mic. I'm assuming by "print" you mean visually or appending the audio data to a file.
If you are looking to record audio to a file you could use the AVAudioRecorder
class:
//What are our output settings?
NSMutableDictionary *recordSetting = [[NSMutableDictionary alloc] init];
[recordSetting setValue:[NSNumber numberWithInt:kAudioFormatMPEG4AAC] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];
// Create the recorder where recorder is declared as a property of the class & outputFileURL is an NSURL to a file path you want to record to
recorder = [[AVAudioRecorder alloc] initWithURL:outputFileURL settings:recordSetting error:NULL];
recorder.delegate = self;
[recorder prepareToRecord];
// Tell the system you are going to use the mic
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:0 error:nil];
[session setActive:YES error:nil];
// Start recording
[recorder record];
---------------------------------
//When you are done call:
[recorder stop];
NSURL *savedFileURL = recorder.url;
If you want to use CoreAudio so that you could get each buffer and decide what to do with it your going to have to take a step back and learn the structure of CoreAudio. CoreAudio allows you to be more flexible about the routing and the design of your audio system. It can't be explained in one post but if you are going that way one method to get data from the mic is to:
Create an AudioUnit
from an AudioComponent
(Type: kAudioUnitType_Output
, Subtype: kAudioUnitSubType_RemoteIO
)
Enable IO on the audioUnit
Set the kAudioUnitProperty_StreamFormat
property of the audioUnit to an AudioStreamBasicDescription
(most likely PCM format)
Intercept data using AURenderCallbackStruct