0

私はNSTemporaryDirectory()で音声を録音したユーザーの声を録音したいという点で1つのアプリを開発していますが、記録の連合の後、その録音された.cafファイルをデータベースに保存し、データベースからそのファイルを取得して再生したいと考えていますファイルだから助けて...私はこのようにしています...

-(IBAction)recordbutton:(id)sender
{
    if(toggle)
    {

        toggle = NO;
        [btnStart setImage:[UIImage imageNamed:@"stopbtn.png"] forState:UIControlStateNormal];
        label1.text = @"Speak now";

        dotimageview.image = [UIImage imageNamed:@"record_dot.png"];
        timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(hideLabel:) userInfo:nil repeats:YES];

        btnPlay.enabled = toggle;
        btnPlay.hidden = !toggle;

        //Begin the recording session.
        //Setup the dictionary object with all the recording settings that this 
        //This is a good resource: http://www.totodotnet.net/tag/avaudiorecorder/
        NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
        [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
        [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
        [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

        //Now that we have our settings we are going to instanciate an instance of our recorder instance.
        //Generate a temp file for use by the recording.
        //This sample was one I found online and seems to be a good choice for making a tmp file that
//      recordedTmpFile = [NSURL fileURLWithPath:[NSTemporaryDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"%.0f.%@", [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"caf"]]];

        recordedTmpFile = [NSURL fileURLWithPath:[NSHomeDirectory() stringByAppendingPathComponent: [NSString stringWithFormat: @"%.0f.%@", [NSDate timeIntervalSinceReferenceDate] * 1000.0, @"caf"]]];

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

        //Setup the recorder to use this file and record to it.
        recorder = [[ AVAudioRecorder alloc] initWithURL:recordedTmpFile settings:recordSetting error:&error];

        //Use the recorder to start the recording.
        [recorder setDelegate:self];
        [recorder prepareToRecord];

        //Start the actual Recording
        [recorder record];
        //There is an optional method for doing the recording for a limited time see 
        //[recorder recordForDuration:(NSTimeInterval) 29];

    }
    else
    {
        toggle = YES;
        label1.text = @"";
        btnPlay.enabled = toggle;
        btnPlay.hidden = !toggle;

        // stop the timer
        [timer invalidate];
        timer = nil;
        dotimageview.hidden = YES;
        label1.text = @"Listen";
        self.navigationItem.rightBarButtonItem.enabled = YES;

        NSLog(@"Using File called: %@",recordedTmpFile);
        NSString *soundFile = [NSString stringWithFormat:@"%@",recordedTmpFile];
        NSLog(@"str === %@",soundFile);

        //Stop the recorder.
        [recorder stop];


    }

}
4

1 に答える 1

0

ファイルを一時フォルダーからユーザーのドキュメント領域に移動し、ファイル名のみをSQLiteに保存することを検討してください。SQLiteはバイナリブロブストアとして設計されていません。SQLiteに大きなバイナリを保存することで、メモリ使用量の問題を回避できます。

于 2012-11-14T13:16:57.753 に答える