0

アプリのマイクでオーディオを録音して、ドキュメントディレクトリに保存しようとしています

これが私のコードです。

//I set up my button and recorder
-(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];
    }

    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryRecord error:nil];
    //I get the path to the Documents Directory
    NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *documentsDirectory = [documentPaths objectAtIndex:0];
//I name the file with the text that is entered into the textfield
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[[self imageNameTextField]text]];
// I add extension .m4a to the file so it will be recognized as a audio file
     fullPath = [fullPath stringByAppendingFormat:@".m4a"];
  //I establish the setting I want the audio to have 
    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];
    }
//I give the url path
     NSURL *url = [NSURL fileURLWithPath:fullPath];
    NSError *error = nil;
//I allocate memory for the recording with the setting at the path
    recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];
       }

残念ながら、これは機能していません。誰かがそれを見て、私がどこで間違っているのかを見ることができますか?

4

1 に答える 1