音声録音データを取得する方法を誰か教えてもらえますか? 複数の録音ファイルを異なるデータで保存したい。私がしているのは、 url 、ディレクトリパスにアクセスして名前を変更することですが、結果として、それらは異なる名前で保存されますが、異なるデータでは保存されません.すべてのファイルは、私が録音した最後のサウンドと同じものを再生しています.
ソースコード:-
- (IBAction) startRecording
{
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
[audioSession setMode:AVAudioSessionModeVoiceChat 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];
// We can use kAudioFormatAppleIMA4 (4:1 compression) or kAudioFormatLinearPCM for nocompression
[recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
// We can use 44100, 32000, 24000, 16000 or 12000 depending on sound quality
[recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey];
// We can use 2(if using additional h/w) or 1 (iPhone only has one microphone)
[recordSetting setValue:[NSNumber numberWithInt: 1] forKey:AVNumberOfChannelsKey];
[recordSetting setObject:[NSNumber numberWithInt:12800] forKey:AVEncoderBitRateKey];
[recordSetting setObject:[NSNumber numberWithInt:16] forKey:AVLinearPCMBitDepthKey];
[recordSetting setObject:[NSNumber numberWithInt: AVAudioQualityMax] forKey: AVEncoderAudioQualityKey];
recorderFilePath = [NSString stringWithFormat:@"%@/My Sound.caf",DOCUMENTS_FOLDER];
url = [NSURL fileURLWithPath:recorderFilePath];
err = nil;
recorder = [[AVAudioRecorder alloc] initWithURL:url settings:recordSetting error:&err];
soundData = [[NSData alloc] initWithContentsOfURL: url];
NSLog(@"soundData:%@",soundData);
NSLog(@"url:%@",url);
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];
return;
}
//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];
}
// start recording
[recorder recordForDuration:(NSTimeInterval) 60];
Tag=30;
}
- (IBAction)saveRecording
{
if([recordingNameTextField.text isEqualToString: @""])
{
[alertView setMessage:@"Recording File Name not set.\n\n"];
[alertView show];
}
else
{
recorderFilePath = [NSString stringWithFormat:@"%@/My Sound.caf",DOCUMENTS_FOLDER];
NSLog(@"%@",recorderFilePath);
NSLog(@"%@",url);
renameString =[NSString stringWithFormat:@"%@/%@.caf",DOCUMENTS_FOLDER,recordingNameTextField.text];
NSLog(@"%@",renameString);
url2 = [NSURL fileURLWithPath:renameString];
NSLog(@"%@",url2);
NSFileManager *fm = [NSFileManager defaultManager];
NSError *renameError;
[fm moveItemAtURL:url toURL:url2 error:&renameError];
[recordingFile checkAndCreateDatabase];
[recordingFile addRecord:1 andname:recordingNameTextField.text];
[recordingFile readDatabase];
recordingNameTextField.text = @"";
NSLog(@"Text Field: %@",recordingNameTextField.text);
saveRecording.userInteractionEnabled=NO;
}
助けてください。ありがとう:)