我已經改變了音頻的時候選擇了瀝青小球在球場一個應用程序,我現在用的installTapOnBus
到保存文件的背景音頻文件,但這個方法被invocated後,我因此只按間距按鈕音頻的一部分被保存,我想保存整個音頻無論何時選擇了瀝青小球,有沒有什麼辦法保存
此方法用於播放音頻
-(void)playAudio
{
NSError *err = nil;
audioEngine = [[AVAudioEngine alloc] init];
AudioFileplayer = [[AVAudioPlayerNode alloc] init];
pitch = [[AVAudioUnitTimePitch alloc] init];
reverb = [[AVAudioUnitReverb alloc] init];
[audioEngine stop];
[AudioFileplayer stop];
[audioEngine reset];
file = [[AVAudioFile alloc] initForReading:[NSURL URLWithString:[self filePath]] error:&err];
[audioEngine attachNode:AudioFileplayer];
[audioEngine attachNode:pitch];
[audioEngine attachNode:reverb];
[audioEngine connect:AudioFileplayer to:reverb format:nil];
[audioEngine connect:reverb to:pitch format:nil];
[audioEngine connect:pitch to:audioEngine.outputNode format:nil];
[reverb loadFactoryPreset:AVAudioUnitReverbPresetLargeRoom2];
[AudioFileplayer scheduleFile:file atTime:nil completionHandler:^{
AudioFileplayer = nil;
}];
[audioEngine prepare];
[audioEngine startAndReturnError:&err];
if (err != nil) {
NSLog(@"An error occured");
}
[AudioFileplayer play];
}
這種方法保存音調影響音頻
-(void)saveEffectedAudioToFolder
{
NSError *error;
if (audioEngine) {
pitchEffect.pitch = 1000;
AVAudioFormat * commonFormat = [[AVAudioFormat alloc] initWithCommonFormat:AVAudioPCMFormatFloat32 sampleRate:44100 channels:2 interleaved:NO];
//
AVAudioFile *outputFile = [[AVAudioFile alloc] initForWriting:[NSURL URLWithString:[self filePath1]] settings:commonFormat.settings error:&error];
//
if (error) {
NSLog(@"Error is 1 %@",[error localizedDescription]);
}
[pitchEffect installTapOnBus:0 bufferSize:4096 format:commonFormat block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when)
{
if (outputFile.length < file.length)
{//Let us know when to stop saving the file, otherwise saving infinitely
NSError *error;
NSAssert([outputFile writeFromBuffer:buffer error:&error], @"error writing buffer data to file, %@", [error localizedDescription]);
}else{
audioEngine = nil;
[pitchEffect removeTapOnBus:0];//if we dont remove it, will keep on tapping infinitely
}
}
];
}
}
任何解決辦法是helful
你有ANS? –
@ S.Karthik不可以,我可以將編輯後的文件保存在文檔目錄中。但是,我必須通過整個音頻與編輯的間距發揮到保存文件,我想這樣做是在後臺沒有播放音頻 –
我也一樣.... –