I want to record audio inside an app using the iPhone mike when the user taps a button and when they stop the recording by tapping the same button it is saved in the documents directory. Think I have it pretty well but I'm not sure how to save it to the documents directory.
Here is my code;
Can anyone help me out I have looked on line but there isn't much that I can find, but maybe I'm searching wrong.
Here is my code;
Code:
// I set up the button
-(IBAction)recordAudio:(id)sender;{
NSLog(@"recordAudio");
recorder = nil;
if ( isNotRecording){
isNotRecording=NO;
[record setTitle:@"Record Greeting" forState:UIControlStateNormal];
[recorder setDelegate:self];
[recorder prepareToRecord];
[recorder record];
}
else{
isNotRecording = YES;
[record setTitle:@"Stop Recording" forState:UIControlStateNormal];
[recorder stop];
}
//I start the audio session
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryRecord error:nil];
//I find the path to the documents directory and name the file after what is put into a textfield and append it with .AAC
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [documentPaths objectAtIndex:0];
NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[[self imageNameTextField]text]];
fullPath = [fullPath stringByAppendingFormat:@".AAC"];
//set settings for audio file
NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
if(recordEncoding==ENC_AAC){
[recordSettings setObject:[NSNumber numberWithInt:kAudioFormatMPEG4AAC]forKey:AVFormatIDKey];
[recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
[recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
[recordSettings setObject:[NSNumber numberWithInt:6400] forKey:AVEncoderBitRateKey];
[recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];
}
//here's where I get lost!
NSURL *url = [NSURL fileURLWithPath:fullPath];
NSError *error = nil;
recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
}
Can anyone help me out I have looked on line but there isn't much that I can find, but maybe I'm searching wrong.
Last edited: