0

My apologies if this is a duplicate to my previous question, but this is driving me a bit batty.

In trying to figure out where the iPhone Simulator is storing files I used the Speak Here project to record my voice and save it to a file. Since the simulator is able to playback the recording there must be a file somewhere, but it is impossible for me to find. I have tried everything including using the terminal command locate (after using sudo /usr/libexec/locate.updatedb). Any help? enter image description here

Community
  • 1
  • 1
Eric Brotto
  • 53,471
  • 32
  • 129
  • 174

2 Answers2

0

The SpeakHere app stores the recorded file in the temporary directory. You can find out the path and its contents with this code:

    NSString *tempPath = NSTemporaryDirectory();
    NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tempPath error:nil];
    NSLog(@"tempPath: %@", tempPath);
    NSLog(@"dirContents: %@", dirContents);

In the iOS Simulator this path will be something like /var/folders/eQ/eQdXXQoxFHmxhq85pgNA+++++TI/-Tmp-/ but on the device this is a subdirectory in your app dir. like /private/var/mobile/Applications/965A9EEF-7FBA-40F4-8A42-FE855A719D52/tmp/.

Felix
  • 35,354
  • 13
  • 96
  • 143
-1

#define DOCUMENTS_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]

-(void) startRecording { [self stopPlaying];

NSLog(@"startRecording");
[audioRecorder release];
audioRecorder = nil;

// Init audio with record capability
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:nil];

NSMutableDictionary *recordSettings = [[NSMutableDictionary alloc] initWithCapacity:10];
if(recordEncoding == ENC_PCM)
{
    [recordSettings setObject:[NSNumber numberWithInt: kAudioFormatLinearPCM] forKey: AVFormatIDKey];
    [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
    [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsBigEndianKey];
    [recordSettings setObject:[NSNumber numberWithBool:NO] forKey:AVLinearPCMIsFloatKey];   
}
else
{
    NSNumber *formatObject;

    switch (recordEncoding) {
        case (ENC_AAC): 
            formatObject = [NSNumber numberWithInt: kAudioFormatMPEG4AAC];
            break;
        case (ENC_ALAC):
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleLossless];
            break;
        case (ENC_IMA4):
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
            break;
        case (ENC_ILBC):
            formatObject = [NSNumber numberWithInt: kAudioFormatiLBC];
            break;
        case (ENC_ULAW):
            formatObject = [NSNumber numberWithInt: kAudioFormatULaw];
            break;
        default:
            formatObject = [NSNumber numberWithInt: kAudioFormatAppleIMA4];
    }

    [recordSettings setObject:formatObject forKey: AVFormatIDKey];
    [recordSettings setObject:[NSNumber numberWithFloat:44100.0] forKey: AVSampleRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:2] forKey:AVNumberOfChannelsKey];
    [recordSettings setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
    [recordSettings setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
    [recordSettings setObject:[NSNumber numberWithInt: AVAudioQualityHigh] forKey: AVEncoderAudioQualityKey];
}

NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
// getting an NSInteger
NSInteger recordID = [prefs integerForKey:@"recordID"];
//NSLog(@"---- %d",recordID);

//NSString *recordFileName = [NSString stringWithFormat:@"%@/record%d.caf", [[NSBundle mainBundle] resourcePath], recordID];
NSString *recordFileName = [NSString stringWithFormat:@"%@/record%d.caf", DOCUMENTS_FOLDER, recordID];

NSURL *url = [NSURL fileURLWithPath:recordFileName];

//NSLog(@"path -- %@",DOCUMENTS_FOLDER);

NSError *error = nil;
audioRecorder = [[ AVAudioRecorder alloc] initWithURL:url settings:recordSettings error:&error];

if ([audioRecorder prepareToRecord] == YES){
    [audioRecorder record];
}else {
    int errorCode = CFSwapInt32HostToBig ([error code]); 
    NSLog(@"Error: %@ [%4.4s])" , [error localizedDescription], (char*)&errorCode);
}
NSLog(@"recording");

[recordSettings release];

}

-(void) stopRecording { NSLog(@"stopRecording"); [audioRecorder stop]; NSLog(@"stopped"); }

Chetan Bhalara
  • 10,326
  • 6
  • 32
  • 51
  • AudioFileURLCreateWithURL error -50 which I couldn't find in the reference: http://developer.apple.com/library/ios/#documentation/MusicAudio/Reference/AudioFileConvertRef/Reference/reference.html – Eric Brotto Apr 14 '11 at 11:21