sabius
sabius

Reputation: 784

Combining 2 audio files is Swift

I am trying to combine 2 audio files.

The main problem is that audio files are lossless .flac files.

I tried creating AVMutableComposition, then creating 2 AVURLAsset for each audio and use AVAssetExportSession to combine the audio files and it works, but the main problem in this case is that AVAssetExportSession doesn't support exporting to .flac and supports .m4a which is lossy compression and not suitable in my case.

Can anyone suggest how to get .flac audio files ?

Upvotes: -1

Views: 392

Answers (1)

sabius
sabius

Reputation: 784

I solved my problem and if someone is wondering, here is the solution:

Instead of AVAssetExportSession, I used AVAudioEngine, but for that to work you will have to connect at least 1 AVAudioPlayerNode to it. Then create 2 AVAudioFile from the audio files that want to combine and schedule them to play on connected AVAudioPlayerNode one after another. After that AVAudioPCMBuffer is needed to render frames manually in a while loop and store it on disk on some sort of a container (I used .mov temporary file for this). After everything is done you can just rename the file to a correct .flac file and it will work.

Upvotes: 0

Related Questions