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

Joh*_*ore 5 ios swift audiokit

当我AKMicrophoneTracker在物理设备上使用AudioKit时,频率和幅度始终都是0.但是在游乐场和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)
        })
    }

}
Run Code Online (Sandbox Code Playgroud)

我重置了物理设备的隐私权限,iOS正确地提示我允许麦克风访问.即使我允许麦克风访问,它仍然无法正常工作.

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

我正在使用AudioKit 4.0.3.使用时,它按预期工作:

  • Mac上的AudioKit游乐场
  • 运行iOS 11.1的模拟器iPhone 7 Plus

使用时不起作用:

  • 运行iOS 11.1.1的物理iPhone 7 Plus(也适用于iOS 11.1)

我最初在AudioKit的GitHub问题跟踪器上发布了这个错误.但是,Aure(项目维护者)鼓励我在这里发帖.

RLo*_*llo 6

以下是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
}
...
Run Code Online (Sandbox Code Playgroud)

info.plist中

...
<key>NSMicrophoneUsageDescription</key>
<string>WE need your microfone to contact the aliens</string>
...
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


Joh*_*ore 0

Ercell0 的答案是正确的——他的代码运行完美。我的具体问题似乎是由其他一些 AudioKit 功能引起的,我认为我在测试过程中禁用了这些功能。这相当于运行:

AudioKit.output = AKMixer()
AudioKit.start()
Run Code Online (Sandbox Code Playgroud)

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

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