我试图改变音频的音高但不能保存受影响的音频。如何在后台保存受影响的音频?

时间:2016-08-29 10:29:27

标签: objective-c audio pitch avaudioengine avaudioplayernode

此方法过滤音频并改变音高但不保存在

的任何地方
new EasClientDeviceInformation().Id.ToString();

这里我可以创建音频文件,但音频中没有声音,任何人都可以帮助我摆脱这个 创建一个名为outputfile的新文件,但是当我播放该音频时,没有声音只是静音,会创建完整的音频,但没有声音

-(void)Pitch:(NSNumber*)pitch
{
 audioPlayerNode = [AVAudioPlayerNode new];
[self.audioEngine attachNode:audioPlayerNode];

AVAudioUnitTimePitch *timePitchEffect = [AVAudioUnitTimePitch new];
[self.audioEngine attachNode:timePitchEffect];
    timePitchEffect.pitch = [pitch floatValue];

[self.audioEngine connect:audioPlayerNode
                       to:timePitchEffect
                   format:nil];
[self.audioEngine connect:timePitchEffect
                       to:self.audioEngine.outputNode
                   format:nil];

[audioPlayerNode scheduleFile:self.audioFile
                       atTime:nil
            completionHandler:nil];

[self.audioEngine startAndReturnError:&audioEngineError];
 }

}

1 个答案:

答案 0 :(得分:0)

你应该替换



[audioPlayerNode installTapOnBus:0 bufferSize:8192  format:_audioFile.processingFormat block:^(AVAudioPCMBuffer *buffer, AVAudioTime *when) {
            NSLog(@"Buffer Size = %@",buffer);
            NSLog(@"when = %lld",when.sampleTime);
            NSLog(@"outputfile length = %lli",_outputFile.length);
            NSLog(@"input file length = %lld",_audioFile.length);
            if (_outputFile.length<=_audioFile.length)
            {
                NSError *error;

                [_outputFile writeFromBuffer:buffer error:&error];

                if (error)
                {
                    NSLog(@"writebuffererror =%@",error);
                }
            }
            else
            {
                NSError *error2;



                [audioPlayerNode removeTapOnBus:0];

                // player2 = [[AVAudioPlayer alloc] initWithContentsOfURL:[self testFilePathURL] error:&error2];
                //player2.delegate = self;

                NSLog(@"Pathththt = %@",[self testFilePathURL]);
                NSLog(@"error = %@",error2);
                [audioPlayerNode scheduleFile:_outputFile atTime:nil completionHandler:nil];


                [audioPlayerNode play];
                // [self toMp3];
            }

        }];
    }
&#13;
&#13;
&#13;

使用

此处输入表示audioEngine.inputnode

&#13;
&#13;
AVAudioInputNode *input = [audioEngine inputNode]; 
AVAudioFormat *format = [input outputFormatForBus: 0];

outputFile = [[AVAudioFile alloc] initForWriting:[self testFilePathURL] settings:recordSetting error:&error];
    if (error)
    {
        //  NSLog(@"outputFile error = %@",error);
         
    }
    else
    {
        //        dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
        //        {
        [input installTapOnBus:0 bufferSize:8091 format:format block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
            
            
            if (outputFile.length<audioFile.length)
            {
                
                NSError *error;
                [outputFile writeFromBuffer:buffer error:&error];
                if (error)
                {
                    NSLog(@"writebuffererror =%@",error);
                    

                }
            }
            else
            {
                
                activityMainView.hidden=YES;
                
                [input removeTapOnBus:0];
                
                //  [self savingAudioFile];
                
                
                //_doneButtonImageView.image=[UIImage imageNamed:@"save"];
                [self doneButtonClick:nil];
                NSError *error2;
                NSLog(@"Pathththt = %@",[self testFilePathURL]);
                NSLog(@"error = %@",error2);
                
               
                
            }
            
            
            
        }];
        
        
         
        //     });
        
        
    }
&#13;
&#13;
&#13;