简体   繁体   English

使用 Audiokit v5 实现麦克风分析

[英]Implementing microphone analysis with Audiokit v5

I need to run my app which uses AudioKit as one of its libraries in Xcode 12 so I can prepare it for the upcoming iOS 14 release, since Xcode 12 contains all the changes to classes that need to be adopted by me.我需要运行我的应用程序,它在 Xcode 12 中使用 AudioKit 作为其库之一,以便我可以为即将发布的 iOS 14 版本做好准备,因为 Xcode 12 包含我需要采用的所有类更改。

However the current stable release of 4.10.1 does not compile in Xcode 12. I then tried to install the latest v5-develop version 5.0.b1 and that compiles successfully, however the API went through significant changes -> AudioKit.output for example is deprecated.然而,4.10.1 的当前稳定版本不能在 Xcode 12 中编译。然后我尝试安装最新的 v5-develop 版本 5.0.b1 并成功编译,但是 API 经历了重大变化 -> AudioKit.output例如是已弃用。 I was unable to find any documentation regarding these changes.我找不到有关这些更改的任何文档。 I reckon that is because it is still in beta.我认为这是因为它仍处于测试阶段。

I previously used this code I have taken from their microphone analysis example:我以前使用过从他们的麦克风分析示例中获取的代码:

func setup(completion: @escaping TaskHandler) {
    // Setup the microphone
    AKSettings.audioInputEnabled = true
    mic = AKMicrophone()
    tracker = AKFrequencyTracker(mic)
    silence = AKBooster(tracker, gain: 0)

    // Start the audio engine
    AudioKit.output = silence
    do {
        try AudioKit.start()
        completion(true, nil)
    } catch {
        completion(false, ErrorMessage.microphoneFailedToStart)
        AKLog("AudioKit did not start!")
    }
}

and then I access the amplitude and frequency like this:然后我像这样访问幅度和频率:

timer?.setEventHandler(handler: {
        let currentAmp = self.tracker.amplitude
        let currentFreq = self.tracker.frequency
        // ... some processing here
}

In the new version I dug around in Xcode and found and tried to get AKMicrophoneTrackerEngine to work and I got it to compile and run:在新版本中,我在 Xcode 中挖掘并发现并尝试让AKMicrophoneTrackerEngine工作,我让它编译并运行:

let engine = AKMicrophoneTrackerEngine()

func setup(completion: @escaping TaskHandler) {
    engine.start()
    completion(true, nil)
}

// ..later in code

timer?.setEventHandler(handler: {
        let currentAmp = self.engine.amplitude
        let currentFreq = self.engine.frequency
        // ... some processing here
}

However the frequency (and possibly amplitude) are slightly off.然而,频率(以及可能的幅度)略微偏离。 Playing a 1000Hz test tone using 4.10.1 produced exactly 1000 as an output but my new approach produces a value around 918.使用 4.10.1 播放一个 1000Hz 的测试音,输出正好是 1000,但我的新方法产生了大约 918 的值。

Can anyone guide me to a piece of documentation or advise me how to implement the same functionality using the new API?任何人都可以指导我查看文档或建议我如何使用新 API 实现相同的功能?

Thank you.谢谢你。

https://github.com/AudioKit/AudioKit/issues/2267 the issue should be fixed by updating to AudioKit 4.11.1 pod 'AudioKit' , '~> 4.11.1' . https://github.com/AudioKit/AudioKit/issues/2267应该通过更新到 AudioKit 4.11.1 pod 'AudioKit' , '~> 4.11.1'来解决该问题。 This version successfully compiles in Xcode 12. You also need to replace all AudioKit instances with AKManager for example: AudioKit.output = ... with AKManager.output = ...此版本在 Xcode 12 中成功编译。您还需要将所有AudioKit实例替换为AKManager例如: AudioKit.output = ...AKManager.output = ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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