Search code examples
iosswiftaudiokit

Create an empty blank audio file of a specific duration in AudioKit


In my project, I am using AudioKit to play beats. I want to create an empty audio file of the same length of the main beat. and and whatever starting point I choose within the duration of the main beat. it will start recording from that point and will end when the main beat is stopped. override the previously recorded part with the newly recorded file. can I achieve with this an empty audio file at the start. Please guide.


Solution

  • In a documentation you can find info about silent file: https://github.com/FT-BOYS/SoundMix/blob/master/AudioKit/Common/Internals/Audio%20File/AKAudioFile%2BUtilities.swift

    To create file you can provide just the number of samples to generate (equals length in seconds multiplied by sample rate). It would look something like this:

    let file = try! AKAudioFile.silent(samples: sampleRate * seconds)