Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When I use AudioKit's AKMicrophoneTracker on a physical device, the the frequency and amplitude are always both 0. But in the playground and in the iOS simulator, it works perfectly.

Here's a rough example:

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)
        })
    }

}

I've reset my physical device's privacy permissions, and iOS is correctly prompting me to allow microphone access. It still doesn't work even though I'm allowing microphone access.

How can I get AKMicrophoneTracker to actually read these values?

I'm using AudioKit 4.0.3. It works as expected when using:

  • the AudioKit playground on my Mac
  • a simulator iPhone 7 Plus running iOS 11.1

It does not work when using:

  • A physical iPhone 7 Plus running iOS 11.1.1 (and also occurs on iOS 11.1)

I originally posted this as a bug on AudioKit's GitHub issue tracker. However, Aure (the project maintainer) encouraged me to post here instead.

like image 823
John Ellmore Avatar asked Nov 20 '17 22:11

John Ellmore


1 Answers

The following worked for me on 7+, 6s:

In 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>
...

enter image description here

like image 136
RLoniello Avatar answered Sep 19 '22 17:09

RLoniello