简体   繁体   中英

AVAudioRecorder : Can we record without saving into file?

I am wondering is there any way we can record audio in an iOS app so that it don't get saved into any file because my file size is getting into GBs.

Thanks!!

If You are recording audio that means you have to save it somewhere, because it must need some space otherwise how you can record ?

You can use NSTemporaryDirectory to save your file like,

    NSString *folderPath = NSTemporaryDirectory();



    NSString *soundFilePath = [folderPath
                               stringByAppendingPathComponent:[NSString stringWithFormat: @"%.0f%@", [NSDate timeIntervalSinceReferenceDate] *1000.0, @"audio.caf"]];

    NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];

    NSLog(@"Using File called: %@",soundFileURL);

    audioRecorder = [[ AVAudioRecorder alloc] initWithURL:soundFileURL settings:recordSetting error:&error];
    [audioRecorder setDelegate:self];
    [audioRecorder prepareToRecord];

Above is the code snippet so that you get idea!

ios automatically clears NSTemporaryDirectory when needed so it is not point of worry for you. And yes you have to store recorded audio somewhere if you want it for permanent!

You can create your own directory that can be work as temp directory that you can clear manually where needed! (create directory in document directory record file there and clear it when your task will be completed)

But you can't record without storing it!

Imagine you could -- would it be better? Keeping GBs of data in RAM?.. Sounds bad.

If you want to keep your disk space free, what you could do is:

1) Save small part of data into file (ie 20 MB?)

2) Send this file to backend and delete it from disk on completion

3) Repeat process until you finish recording

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM