2 Replies
      Latest reply on Nov 29, 2016 3:22 AM by ferasOS
      ferasOS Level 1 Level 1 (0 points)

        is it possible to extract the data in a buffer as an array? I have saved an audiofile into an buffer and now would like o extract the data. The code is:

        import UIKit import AVFoundation

        //importing audio

        let audioFileURL = Bundle.main.url(forResource: "Morning", withExtension: "wav")

        let audioFile = try AVAudioFile(forReading: audioFileURL!)

        //extract information

        var audioFileFormat = audioFile.fileFormat

        var audioFilePFormat = audioFile.processingFormat

        var audioFileLength = audioFile.length

        var audioFrameCount = UInt32(audioFile.length)

        var audioFileChannels = audioFile.fileFormat.channelCount

        var audioFileSamplingRate = audioFile.fileFormat.sampleRate

        // insert into buffer

        let audioBuffer = AVAudioPCMBuffer(pcmFormat: audioFilePFormat, frameCapacity: AVAudioFrameCount(audioFileLength))

        try audioFile.read(into: audioBuffer, frameCount: AVAudioFrameCount(audioFileLength))