ios – convert AVAudioPCMBuffer data to audio in AVAudioEngine()


I am trying to get audio of microphone as a byte Array and then I want to convert AVAudioPCMBuffer data to audio and play it, how to convert AVAudioPCMBuffer data to audio? and is this best method to convert AVAudioPCMBuffer data audio

let audioEngine  = AVAudioEngine()
func getAudio() {
    let inputNode = audioEngine.inputNode
    var error: NSError?
    let bus = 0
    
    inputNode.installTap(onBus: bus, bufferSize: 2048, format: inputNode.inputFormat(forBus: bus)) {
        (buffer: AVAudioPCMBuffer!, time: AVAudioTime!) -> Void in
        print(buffer)
    }
    
    audioEngine.prepare()
    do {
        try audioEngine.start()
    } catch {
        print("Can't start the engine: \(error)")
    }
    
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img