简体   繁体   中英

Enable audio input AudioKit v5

I am trying to migrate an app from AudioKit v4 to v5 and I am having a hard time finding documentation on the migration, and I can't find these in the Cookbook. Previously we could set defaultToSpeaker and audioInputEnabled through AKSettings. Now, these properties are gone and I can't find how can I replace them.

v4:

AKSettings.audioInputEnabled = true
AKSettings.defaultToSpeaker = true

Does anyone know how these parameters can be set with the new version? Any feedback is highly appreciated!

Nazarii,

In AudioKit 5, here's how I set up my audio input parameters:

import AudioKit
import AVFoundation

class Conductor {
    
    static let sharedInstance = Conductor()
    
    // Instantiate the audio engine and Mic Input node objects
    let engine = AudioEngine()
    var mic: AudioEngine.InputNode!
    
    // Add effects for the Mic Input.
    var delay: Delay!
    var reverb: Reverb!
    let mixer = Mixer()
    
    // MARK: Initialize the audio engine settings.
    
    init() {
        
        // AVAudioSession requires the AVFoundation framework to be imported in the header.
        
        do {
            Settings.bufferLength = .medium
            try AVAudioSession.sharedInstance().setPreferredIOBufferDuration(Settings.bufferLength.duration)
            try AVAudioSession.sharedInstance().setCategory(.playAndRecord,
                                        options: [.defaultToSpeaker, .mixWithOthers, .allowBluetoothA2DP])
            try AVAudioSession.sharedInstance().setActive(true)
        } catch let err {
            print(err)
        }
        
        // The audio signal path with be:
        // input > mic > delay > reverb > mixer > output
                
        // Mic is connected to the audio engine's input...
        
        mic = engine.input

        // Mic goes into the delay...
        
        delay = Delay(mic)
        delay.time = AUValue(0.5)
        delay.feedback = AUValue(30.0)
        delay.dryWetMix = AUValue(15.0)
        
        // Delay output goes into the reverb...
        
        reverb = Reverb(delay)
        reverb.loadFactoryPreset(.largeHall2)
        reverb.dryWetMix = AUValue(0.4)
        
        // Reverb output goes into the mixer...

        mixer.addInput(reverb)
        
        // Engine output is connected to the mixer.
        engine.output = mixer
        
        // Uncomment the following method, if you don't want to Start and stop the audio engine via the SceneDelegate.
        // startAudioEngine()

    }
    
    // MARK: Start and stop the audio engine via the SceneDelegate
    
    func startAudioEngine() {
        do {
            print("Audio engine was started.")
            try engine.start()
        } catch {
            Log("AudioKit did not start! \(error)")
        }
    }

    func stopAudioEngine() {
        engine.stop()
        print("Audio engine was stopped.")
    }
    
}

Please let me know if this works for you.

Take care, Mark

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM