How to share or save Audio after Effects, like altering pitch or rate?

Basically, what i need here is that, after my app has recorded an audio, I have written code that alters its pitch and/or rate, And I use Activity View Controller, to share the audio from the app to other medias. But, what happens, when I share it is that, the "ORIGINAL RECORDED" audio is shared, instead of the audio that had "EFFECTS" to it like rate or pitch. So, I do i go about sharing (itd be awesome, if you could also tell me how to save then share) the audio.


EXAMPLE OF MY CODE:

//For fast rate playback

@IBAction func fasterAudio(sender: UIButton) {

audioEngine.reset()

audioPlayer.currentTime = 0

audioPlayer.rate = 1.75

audioPlayer.play()

}


//For higher Pitch

@IBAction func highPitchAudio(sender: UIButton) {

audioPlayer.stop()

audioEngine.stop()

audioEngine.reset()

audioPlayer.currentTime = 0

var audioPlayerNode = AVAudioPlayerNode()

audioEngine.attachNode(audioPlayerNode)

var changePitchEffect = AVAudioUnitTimePitch()

changePitchEffect.pitch = 1000

audioEngine.attachNode(changePitchEffect)

audioEngine.connect(audioPlayerNode, to: changePitchEffect, format: nil)

audioEngine.connect(changePitchEffect, to: audioEngine.outputNode, format: nil)

audioPlayerNode.scheduleFile(audioFile, atTime: nil, completionHandler: nil)

audioEngine.startAndReturnError(nil)

audioPlayerNode.play()

}

PLEASE TELL ME HOW I CAN SAVE AND/OR SHARE THE AUDIO AFTER IT HAS BEEN ALTERED??

Whenever, i share it through UIActivityViewController, the original "audioFile" is shared, how do i share the altered audio?

Replies

There's a good example of how to save the altered audio to a new file using AVAudioEngine here - "Using AVAudioEngine for Playback, Mixing and Recording": <https://developer.apple.com/library/ios/samplecode/AVAEMixerSample/Introduction/Intro.html >


The sample sets up two separate players into two different effects and allows you to record the resulting audio via a tap on the mixer. The end result is a new file containing the realtime processed audio, meaning, if you change the Volume/Pan of the players or the Wet/Dry mix of each effect, the results are recorded to the new AVAudioFile at a specified URL. The sample will also playback the recorded file so you can hear what it sounds like.


I don't know how this works out in your "sharing" scenario but if you have a new URL with the altered audio, I suspect you can share that pretty easily.

Thanks for the Reply!, its the third day i tried using the code from the link that you sent me, but there are two problems here, first off, the code on that link is written in OBJ-C, however, I have been successful in recording a playback to a new audio File, using:

audioplayernode.taponBus() ,and

newaudiofile.writefrombuffer

functions, however, the problem is that plain audio is recorded to the new audio. The audio that playsback had altered pitch and rate but the recorded file has a plain audio without pitch or rate alterations:(

This is the code that i am Using:


audioPlayerNode.installTapOnBus(0, bufferSize: (AVAudioFrameCount(audioPlayer.duration)), format: mixerAudioFile.processingFormat)

{

(buffer: AVAudioPCMBuffer!, time: AVAudioTime!) in

if (self.NEWAudioFile.length) < (self.audioFile.length){/

self.mixerAudioFile.writeFromBuffer(EffectsAudioFileBuffer, error: nil)

}else{

audioPlayerNode.removeTapOnBus(0)

println("REMOVED TAP ON BUS")

}

The sample is installing a tap on the main mixer when "recording". The mixer node is being fed by output of the effected audio and therefore what gets recorded to the file is the resultant mix. The sample uses 2 players and 2 effects but basically it's setting up the engine like this:


Player 1 -> Effect 1 - >

Main Mixer - > Output

Player 2 -> Effect 2 - > |

|

Tap off Main Mixer - > Audio File Output


Your code appears to be placing a tap on an "audioPlayerNode", thereby just recording the output of the player.


The fact that the sample is in Obj-C shouldn't make a difference.

i want to record my voice which was effected (reverb, echo). Can i make?