我设法设置了AVAudiorecorder来制作录音,但是我想将录音保存在文档目录中以便以后收听。我试过这个:
- (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)avrecorder successfully:(BOOL)flag{
ButtonStopRecording.hidden = YES;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"audioFile.ext"]; // Where ext is the audio format extension you have recorded your sound
[avrecorder.data writeToFile:filePath atomically:YES];
}
但
中有错误avrecorder.data
我该如何解决这个问题?
答案 0 :(得分:0)
AVAudioRecorder
没有数据属性。您只需要在初始化AVAudioRecorder
时设置保存录制音频的位置。设置录像机时,只需将其设置到文档目录即可。
答案 1 :(得分:0)
尝试使用
访问该文件avrecorder.url
假设您在开始record
像这样......
NSString *temnpVoiceFile = [NSString pathWithComponents:[NSArray arrayWithObjects:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject], @"tempVoice.caf", nil]];
// We need to update the file generator
NSURL *soundFileURL = [NSURL fileURLWithPath:temnpVoiceFile];
NSError *error = nil;
// Instantiate an audio recorder.
self.audioRecorder = [[[AVAudioRecorder alloc] initWithURL:soundFileURL settings:_recordSettings error:&error] autorelease];
NSAssert1(!error, @"error creating audio file = %@", error);
BOOL fileSuccess = [_audioRecorder prepareToRecord];
NSAssert(fileSuccess, @"audio recorder could not be prepared.");
[_audioRecorder record];
如果您需要更多信息,请与我们联系。
答案 2 :(得分:0)
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"audioFile.ext"]; // Where ext is the audio format extension you have recorded your sound
NSData *data=[NSData dataWithContentsOfURL:avrecorder.url];
[data writeToFile:soundFilePath atomically:YES];
[data writeToFile:filePath atomically:YES];
我认为这会对你有所帮助。