title: iPhone - How to convert .caf audio files into .aac?
body: <p>I am working on audio recording. I am able to record my audio in caf (Core audio format).i followed this tutorial <a href="http://www.techotopia.com/index.php/Recording_Audio_on_an_iPhone_with_AVAudioRecorder_%28iOS_4%29" rel="nofollow">Recording Audio on an iPhone with AVAudioRecorder</a>. Now I don't  want to record sound in .aac format directly, I need to convert recorded .caf audio file into .aac audio file... any idea how to do this?</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;AVFoundation/AVFoundation.h&gt;
  
  @interface recordViewController : UIViewController
      &lt;AVAudioRecorderDelegate, AVAudioPlayerDelegate&gt;
  {
      AVAudioRecorder *audioRecorder;
      AVAudioPlayer *audioPlayer;
      UIButton *playButton;
      UIButton *recordButton;
      UIButton *stopButton;
  }
  @property (nonatomic, retain) IBOutlet UIButton *playButton;
  @property (nonatomic, retain) IBOutlet UIButton *recordButton;
  @property (nonatomic, retain) IBOutlet UIButton *stopButton;
  -(IBAction) recordAudio;
  -(IBAction) playAudio;
  -(IBAction) stop;
  @end
  
  #import "recordViewController.h"
  
  @implementation recordViewController
  @synthesize playButton, stopButton, recordButton;
  
  
  - (void)viewDidLoad {
  [super viewDidLoad];
  playButton.enabled = NO;
  stopButton.enabled = NO;
  
  NSArray *dirPaths;
  NSString *docsDir;
  
  dirPaths = NSSearchPathForDirectoriesInDomains(
      NSDocumentDirectory, NSUserDomainMask, YES);
  docsDir = [dirPaths objectAtIndex:0];
  NSString *soundFilePath = [docsDir
     stringByAppendingPathComponent:@"sound.caf"];
  
  NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
  
  NSDictionary *recordSettings = [NSDictionary 
          dictionaryWithObjectsAndKeys:
          [NSNumber numberWithInt:AVAudioQualityMin],
          AVEncoderAudioQualityKey,
          [NSNumber numberWithInt:16], 
          AVEncoderBitRateKey,
          [NSNumber numberWithInt: 2], 
          AVNumberOfChannelsKey,
          [NSNumber numberWithFloat:44100.0], 
          AVSampleRateKey,
          nil];
  
  NSError *error = nil;
  
  audioRecorder = [[AVAudioRecorder alloc]
                initWithURL:soundFileURL
                settings:recordSettings
                error:&amp;error];
  
  if (error)
  {
         NSLog(@"error: %@", [error localizedDescription]);
  
  } else {
         [audioRecorder prepareToRecord];
  }
  }
  -(void) recordAudio
  {
   if (!audioRecorder.recording)
   {
           playButton.enabled = NO;
           stopButton.enabled = YES;
           [audioRecorder record];
   }
  }
  -(void)stop
  {
  stopButton.enabled = NO;
  playButton.enabled = YES;
  recordButton.enabled = YES;
  
  if (audioRecorder.recording)
  {
          [audioRecorder stop];
  } else if (audioPlayer.playing) {
          [audioPlayer stop];
  }
  }
  -(void) playAudio
  {
  if (!audioRecorder.recording)
  {
     stopButton.enabled = YES;
     recordButton.enabled = NO;
  
      if (audioPlayer)
            [audioPlayer release];
      NSError *error;
  
      audioPlayer = [[AVAudioPlayer alloc] 
      initWithContentsOfURL:audioRecorder.url                                    
      error:&amp;error];
  
      audioPlayer.delegate = self;
  
      if (error)
            NSLog(@"Error: %@", 
            [error localizedDescription]);
      else
            [audioPlayer play];
  }
  }
  
   -(void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)flag
   {
      recordButton.enabled = YES;
      stopButton.enabled = NO;
   }
  
   -(void)audioPlayerDecodeErrorDidOccur:(AVAudioPlayer *)player error:(NSError *)error
   {
      NSLog(@"Decode Error occurred");
   }
  
   -(void)audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag
   {
   }
  
   -(void)audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error
   {
      NSLog(@"Encode Error occurred");
   }
  @end
  </code></pre>