Reputation: 2229
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:
It does not work when using:
I originally posted this as a bug on AudioKit's GitHub issue tracker. However, Aure (the project maintainer) encouraged me to post here instead.
Upvotes: 6
Views: 639
Reputation: 2229
Ercell0's answer is correct--his code works perfectly. My specific problem appears to have been caused by some other AudioKit functionality which I thought I had disabled during testing. It was equivalent to running:
AudioKit.output = AKMixer()
AudioKit.start()
after the AKMicrophoneTracker
initialization. This caused the AKMicrophoneTracker
problem I was experiencing.
It looks like this might be a bug in AudioKit. I've opened issue #1142 on Github.
Upvotes: 0
Reputation: 2329
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>
...
Upvotes: 6