为什么 AudioKit 的 AKMicrophoneTracker 不能在物理 iOS 设备上工作?

Why doesn't AudioKit's AKMicrophoneTracker work on a physical iOS device?

当我在物理设备上使用 AudioKit 的 AKMicrophoneTracker 时,频率和幅度始终都是 0。但在 playground 和 iOS 模拟器中,它运行完美。

这是一个粗略的例子:

class AppDelegate: UIResponder, UIApplicationDelegate {

    let tracker = AKMicrophoneTracker()

    func application(_ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        // start the tracker and show frequency information
        tracker.start()
        Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true, block: { _ in
            print(tracker.frequency)
            print(tracker.amplitude)
        })
    }

}

我已经重置了我的物理设备的隐私权限,iOS 正确地提示我允许访问麦克风。即使我允许麦克风访问,它仍然不起作用。

如何让 AKMicrophoneTracker 实际读取这些值?

我正在使用 AudioKit 4.0.3。使用时按预期工作:

使用时无效:

我最初 post 将其编辑为 a bug on AudioKit's GitHub issue tracker。但是,Aure(项目维护者)鼓励我在这里 post。

以下在 7+、6s 上对我有用:

在 AppDelegate 中:

import UIKit
import AudioKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let tracker = AKMicrophoneTracker()



func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    // start the tracker and show frequency information
    tracker.start()
    Timer.scheduledTimer(withTimeInterval: 0.5, repeats: true, block: { _ in
        print(self.tracker.frequency)
        print(self.tracker.amplitude)
    })


    return true
}
...

info.plist

...
<key>NSMicrophoneUsageDescription</key>
<string>WE need your microfone to contact the aliens</string>
...

是正确的——他的代码运行完美。我的具体问题似乎是由我认为我在测试期间禁用的其他一些 AudioKit 功能引起的。相当于 运行:

AudioKit.output = AKMixer()
AudioKit.start()

AKMicrophoneTracker 初始化之后。这导致了我遇到的 AKMicrophoneTracker 问题。

看起来这可能是 AudioKit 中的一个错误。我在 Github 上打开了 issue #1142