【问题标题】:Enable audio input AudioKit v5启用音频输入 AudioKit v5
【发布时间】:2021-10-13 06:30:45
【问题描述】:

我正在尝试将应用程序从 AudioKit v4 迁移到 v5,并且很难找到有关迁移的文档,并且在 Cookbook 中找不到这些文档。以前我们可以通过 AKSettings 设置 defaultToSpeaker 和 audioInputEnabled。现在,这些属性都消失了,我找不到如何替换它们。

v4:

AKSettings.audioInputEnabled = true
AKSettings.defaultToSpeaker = true

有谁知道新版本如何设置这些参数?非常感谢任何反馈!

【问题讨论】:

    标签: ios flutter avaudioplayer audiokit


    【解决方案1】:

    纳扎里,

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

    如果这对你有用,请告诉我。

    保重, 标记

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-20
      • 1970-01-01
      • 2018-02-25
      相关资源
      最近更新 更多