现在我通过从AVAudioUnitEQ录制文件来保存文件。
[mainEQ installTapOnBus:0 bufferSize:0 format:[mainEQ outputFormatForBus:0] block:^(AVAudioPCMBuffer *buf, AVAudioTime *when){
if(!recordIsGoing){
[mainEQ removeTapOnBus:0];
}
else{
[writeAudioFile writeFromBuffer:buf error:nil];
// NSLog(@"%lld", writeAudioFile.length);
}
}];
但是这种方法需要 事先文件播放 .有没有办法保存混合文件而不播放?
UPD:我可以得到AUAudioUnit.outputBusses[0]到mainEQ。现在的挑战是取出数据,并希望它们能成为我需要的。
已解决:此答案已解决问题 我可以使用 AVAudioEngine 读取文件、使用音频单元处理和写入文件,速度比实时更快吗?
我认为
您可以通过首先将数据转换为NSData并存储它来做到这一点。当您将其取回时,可以将其转换回来。
NSData *data = [NSKeyedArchiver archivedDataWithRootObject:buf];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"yourfilename.dat"];
// Save it into file system
[data writeToFile:dataPath atomically:YES];