2

I'm trying to add a feature to my app where I can record audio from the phone's built-in microphone and then playback that audio through the phone's speakers at the same time.

Firstly, I want to know if this is possible through AudioKit?

Secondly, if it's possible, which playground/examples projects in AudioKit can I look through for reference on how to do this?

I know it's possible to record the audio to a file and then play that back and I saw it in the Recorder example project, but what I wanted was a real-time playback.

Would appreciate any guidance or help you can give me for this.

1 Answers1

5

For any app that uses the device microphone, you need to add the NSMicrophoneUsageDescription key to Info.plist. Once that's taken care of you just route the microphone through the effects, and set the output to the end of the chain.

import UIKit
import AudioKit

class ViewController: UIViewController {

    var microphone = AKMicrophone()
    var reverb = AKReverb()

    override func viewDidLoad() {
        super.viewDidLoad()

        microphone >>> reverb
        AudioKit.output = reverb
        AKSettings.ioBufferDuration = 0.002 // Optional, set this to decrease latency
        AudioKit.start()
    }
}
dave234
  • 4,465
  • 1
  • 12
  • 28