1

データを記録するために実装したものを添付しています。フォーマットで保存し.wavていますが、私の問題は、ファイルのサイズが大きすぎることです (つまり、10 秒間で 86kb かかります)。5 分 300kb のサイズが必要です。たくさんの方法があります、私を助けてくれませんか?

- (IBAction) startRecording
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *err = nil;
    [audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
    if(err){
        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        return;
    }
    [audioSession setActive:YES error:&err];
    err = nil;
    if(err){
        NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        return;
    }


recordSetting = [[NSMutableDictionary alloc] init];
    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatLinearPCM] forKey:AVFormatIDKey];
[recordSetting setValue:[NSNumber numberWithFloat:8000.0] forKey:AVSampleRateKey];
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
    [recordSetting setValue:[NSNumber numberWithInt:8] forKey:AVLinearPCMBitDepthKey];
    [recordSetting setValue:[NSNumber numberWithBool:NX_BigEndian == NXHostByteOrder()] forKey:AVLinearPCMIsBigEndianKey];
    [recordSetting setValue:[NSNumber numberWithBool:0] forKey:AVLinearPCMIsFloatKey];
recorderFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"abc.wav"] ;

    NSLog(@"recorderFilePath: %@",recorderFilePath);

    NSURL *url = [NSURL fileURLWithPath:recorderFilePath];


    err = nil;

    NSData *audioData = [NSData dataWithContentsOfFile:[url path] options: 0 error:&err];
    if(audioData)
    {
        NSFileManager *fm = [NSFileManager defaultManager];
        [fm removeItemAtPath:[url path] error:&err];
    }

    err = nil;
    recorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
    if(!recorder){
        NSLog(@"recorder: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
        UIAlertView *alert =
        [[UIAlertView alloc] initWithTitle: @"Warning"
                                   message: [err localizedDescription]
                                  delegate: nil
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
        [alert show];
        }

    //prepare to record
    [recorder setDelegate:self];
    [recorder prepareToRecord];
    recorder.meteringEnabled = YES;

    BOOL audioHWAvailable = audioSession.inputIsAvailable;
    if (! audioHWAvailable) {
        UIAlertView *cantRecordAlert =
        [[UIAlertView alloc] initWithTitle: @"Warning"
                                   message: @"Audio input hardware not available"
                                  delegate: nil
                         cancelButtonTitle:@"OK"
                         otherButtonTitles:nil];
        [cantRecordAlert show];

        return;
    }

    [recorder record];
 currentTimeUpdateTimer = [NSTimer scheduledTimerWithTimeInterval:0.5
                                                              target:self selector:@selector(updateAudioDisplay)
                                                            userInfo:NULL repeats:YES];


}

よろしくお願いします。

4

1 に答える 1

1

フォーマット ID をkAudioFormatAppleIMA4またはkAudioFormatMPEG4AACに変更します。これらは、より小さいサイズのオーディオ ファイルを生成します。コメントで述べたように、WAV は非圧縮オーディオ形式です。そのため、オーディオ ファイルのサイズは非常に大きくなります。

于 2013-03-06T13:36:45.797 に答える