0
我使用AVAudioRecorder錄製音頻,目前錄製10秒,音頻錄製成功,將其保存在本地目錄中,現在10秒的音頻需要1.8 MB的內存,我可以減少這個音頻文件的內存嗎?我使用下面的代碼來記錄音頻。AVAudioRecoder,減少錄製的音頻文件內存
-(void)viewWillAppear:(BOOL)animated{
NSArray *dirPaths;
NSString *docsDir;
dirPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
docsDir = [dirPaths objectAtIndex:0];
NSString *soundFilePath = [docsDir stringByAppendingPathComponent:@"sound.caf"];
path_audio = soundFilePath;
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithInt:AVAudioQualityMin],AVEncoderAudioQualityKey,
[NSNumber numberWithInt:16],AVEncoderBitRateKey,
[NSNumber numberWithInt: 2],AVNumberOfChannelsKey,
[NSNumber numberWithFloat:44100.0],AVSampleRateKey,nil];
NSError *error = nil;
audioRecorder = [[AVAudioRecorder alloc]initWithURL:soundFileURL settings:recordSettings error:&error];
if(!audioRecorder){
NSLog(@"recorder: %@ %d %@", [error domain], [error code], [[error userInfo] description]);
UIAlertView *alert =
[[UIAlertView alloc] initWithTitle: @"Warning" message: [error localizedDescription] delegate: nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
return;
}
if (error)
{
NSLog(@"error: %@", [error localizedDescription]);
}
else {
[self recordAudio];
}
}
-(void) recordAudio
{
if (!audioRecorder.recording)
{
audioRecorder.delegate=self;
[audioRecorder recordForDuration:10];
}
}
任何答案應該感激。