簡體   English   中英

啟用音頻輸入 AudioKit v5

[英]Enable audio input AudioKit v5

我正在嘗試將應用程序從 AudioKit v4 遷移到 v5,但我很難找到有關遷移的文檔,而且我在 Cookbook 中找不到這些文檔。 以前我們可以通過 AKSettings 設置 defaultToSpeaker 和 audioInputEnabled。 現在,這些屬性不見了,我找不到如何替換它們。

v4:

AKSettings.audioInputEnabled = true
AKSettings.defaultToSpeaker = true

有誰知道新版本如何設置這些參數? 任何反饋都非常感謝!

納扎里,

在 AudioKit 5 中,以下是我設置音頻輸入參數的方法:

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.")
    }
    
}

請讓我知道這是否適合您。

保重,馬克

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM