How to record audio on iPhone

I want to record audio using iphone (<2 minutes) and save it in a file. I looked at SpeakHere, but it bothers me. What classes do I use? What delegate methods do I create?

Thanks!

+3
source share
3 answers

I agree, SpeakHere is not a good starting point for exploring the iPhone.

IPhone audio uses two concepts. AudioQueues and AudioSessions. If you want to write to a file, you will need to create one AudioSession, activate a session, and create an AudioInputQueue and AudioOutputQueue.

Link to AudioQueues (certainly the part you'll deal with most):

http://developer.apple.com/iphone/library/documentation/MusicAudio/Conceptual/AudioQueueProgrammingGuide/Introduction/Introduction.html

AudioSessions:

http://developer.apple.com/iphone/library/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html

AudioSession, . , , :

  • - AudioInterrupt. , .
  • , . , AudioStreamBasicDescripion.
  • AudioQueue AudioQueueNewInput . . , , , , .
  • , AudioQueueBuffers . , 2. , .
  • AudioSessionSetActive ();
  • AudioQueueStart AudioQueue.

, API.

, .

[EDIT]

, , . AudioQueue, AudioQueueNewOutput, API .

.

+5

AudioQueues . AVAudioRecorder.

+2

This code is for audio recording

Remember to add AVFoundation and AudioToolBox Framework

NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
        [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
        [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
        [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent:@"filename.caf"]];
NSLog(@"Using File called: %@",recordedTmpFile);

recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:nil];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
+2
source

All Articles