当我在物理设备上使用AudioKit的AKMicrophoneTracker时,频率和幅度始终都是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) }) } }
我重置了物理设备的隐私权限,iOS正确地提示我允许麦克风访问.即使我允许麦克风访问,它仍然无法正常工作.
如何让AKMicrophoneTracker实际读取这些值?
我正在使用AudioKit 4.0.3.使用时,它按预期工作:
>我的Mac上的AudioKit游乐场
>运行iOS 11.1的模拟器iPhone 7 Plus
使用时不起作用:
>运行iOS 11.1.1的物理iPhone 7 Plus(也适用于iOS 11.1)
我最初发布的是a bug on AudioKit’s GitHub issue tracker.但是,Aure(项目维护者)鼓励我在这里发帖.
解决方法
以下是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,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> ...