Audiokit: mic = AKMicrophone() throws error

Created on 12 Nov 2018  路  6Comments  路  Source: AudioKit/AudioKit

I have MacOS 10.14.1, Xcode 10.0, and the latest version of AudioKit. I was trying out the microphone analysis (https://audiokit.io/examples/MicrophoneAnalysis/) but I keep on getting an error. I used breakpoints and found that the error is on the line mic = AKMicrophone()

My full error is below:
2018-11-12 08:33:12.710625-0500 iOSTuner[2068:118072] [avae] AVAEInternal.h:70:_AVAE_Check: required condition is false: [AVAudioIONodeImpl.mm:911:SetOutputFormat: (format.sampleRate == hwFormat.sampleRate)] 2018-11-12 08:33:12.717135-0500 iOSTuner[2068:118072] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'required condition is false: format.sampleRate == hwFormat.sampleRate' *** First throw call stack: ( 0 CoreFoundation 0x0000000106b1429b __exceptionPreprocess + 331 1 libobjc.A.dylib 0x0000000105517735 objc_exception_throw + 48 2 CoreFoundation 0x0000000106b14022 +[NSException raise:format:arguments:] + 98 3 AVFAudio 0x0000000109b4389c _Z19AVAE_RaiseExceptionP8NSStringz + 156 4 AVFAudio 0x0000000109b8095b _Z11_AVAE_CheckPKciS0_S0_b + 323 5 AVFAudio 0x0000000109bbd207 _ZN17AVAudioIONodeImpl15SetOutputFormatEmP13AVAudioFormat + 349 6 AVFAudio 0x0000000109b547eb _ZN18AVAudioEngineGraph8_ConnectEP19AVAudioNodeImplBaseS1_jjP13AVAudioFormat + 1653 7 AVFAudio 0x0000000109bc4f3a _ZN17AVAudioEngineImpl7ConnectEP11AVAudioNodeS1_mmP13AVAudioFormat + 194 8 AVFAudio 0x0000000109bc4fa1 -[AVAudioEngine connect:to:format:] + 83 9 iOSTuner 0x00000001046b2fe4 $S8AudioKit12AKMicrophoneCACycfc + 916 10 iOSTuner 0x00000001046b305f $S8AudioKit12AKMicrophoneCACycfcTo + 15 11 iOSTuner 0x00000001044827ff $S8iOSTuner14ViewControllerC11viewDidLoadyyF + 175 12 iOSTuner 0x0000000104482a24 $S8iOSTuner14ViewControllerC11viewDidLoadyyFTo + 36 13 UIKitCore 0x0000000111074781 -[UIViewController loadViewIfRequired] + 1186 14 UIKitCore 0x0000000111074be0 -[UIViewController view] + 27 15 UIKitCore 0x0000000111155ee3 -[UIWindow addRootViewControllerViewIfPossible] + 122 16 UIKitCore 0x00000001111565fe -[UIWindow _setHidden:forced:] + 294 17 UIKitCore 0x000000011116982d -[UIWindow makeKeyAndVisible] + 42 18 UIKitCore 0x000000011093f12c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4595 19 UIKitCore 0x0000000110944527 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1623 20 UIKitCore 0x00000001111e6e3e __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 866 21 UIKitCore 0x00000001111e3403 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153 22 UIKitCore 0x00000001111e6a7b -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 233 23 UIKitCore 0x00000001111e7435 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1085 24 UIKitCore 0x00000001111a4b31 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 795 25 UIKitCore 0x00000001111a47db -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 435 26 UIKitCore 0x00000001111e992c __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 584 27 UIKitCore 0x00000001111ea256 _performActionsWithDelayForTransitionContext + 100 28 UIKitCore 0x00000001111e968b -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 221 29 UIKitCore 0x00000001111e2aa1 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392 30 UIKitCore 0x0000000110942d46 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515 31 UIKitCore 0x0000000110974856 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 357 32 FrontBoardServices 0x00000001100dcdda -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448 33 FrontBoardServices 0x00000001100e7f43 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 271 34 FrontBoardServices 0x00000001100e763a __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53 35 libdispatch.dylib 0x0000000107e1e63e _dispatch_client_callout + 8 36 libdispatch.dylib 0x0000000107e21bb4 _dispatch_block_invoke_direct + 301 37 FrontBoardServices 0x000000011011c3c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30 38 FrontBoardServices 0x000000011011c080 -[FBSSerialQueue _performNext] + 457 39 FrontBoardServices 0x000000011011c660 -[FBSSerialQueue _performNextFromRunLoopSource] + 45 40 CoreFoundation 0x0000000106a77b31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 41 CoreFoundation 0x0000000106a773a3 __CFRunLoopDoSources0 + 243 42 CoreFoundation 0x0000000106a71a4f __CFRunLoopRun + 1263 43 CoreFoundation 0x0000000106a71221 CFRunLoopRunSpecific + 625 44 GraphicsServices 0x000000010bce51dd GSEventRunModal + 62 45 UIKitCore 0x0000000110946115 UIApplicationMain + 140 46 iOSTuner 0x00000001044846f7 main + 71 47 libdyld.dylib 0x0000000107e94551 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

My code is as follows:
`//
// ViewController.swift
// iOSTuner
//
// Created by Jerry Qian on 11/3/18.
// Copyright 漏 2018 Jerry Qian. All rights reserved.
//

import UIKit
import AudioKit

class ViewController: UIViewController {

@IBOutlet weak var frequencyLabel: UILabel!

var mic: AKMicrophone!
var tracker: AKFrequencyTracker!
var silence: AKBooster!

override func viewDidLoad() {
    super.viewDidLoad()

    AKSettings.audioInputEnabled = true
    mic = AKMicrophone()
    tracker = AKFrequencyTracker(mic)
    silence = AKBooster(tracker, gain: 0)

}

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    AudioKit.output = silence
    do {
        try AudioKit.start()
    } catch {
        AKLog("AudioKit did not start!")
    }

    Timer.scheduledTimer(timeInterval: 0.1,
                         target: self,
                         selector: #selector(ViewController.updateUI),
                         userInfo: nil,
                         repeats: true)

}

@objc func updateUI() {
    frequencyLabel.text = String(format: "%0.1f", tracker.frequency)
}

}`

I don't know what to do, and how to fix it. Any help would be appreciated.

Most helpful comment

I have the same question

All 6 comments

Its probably just a problem with your Mac's microphone set to 48K inside audio midi setup. We're working to make the mic's sample rate unimportant to AudioKit, but changing it back to 44.1K should make this go away.

I am actually experiencing this same crash on the simulator. I have attached my internal mic's settings:

screen shot 2018-11-15 at 6 08 49 am

What about the simulator's hardware settings?
image

It crashes no matter what I select in the simulator hardware settings.

@mnearents I did faced similar stuff and tried your settings, did not worked.
I then connected a microphone, it worked.

I have the same question

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trevor-sonic picture trevor-sonic  路  6Comments

minayko picture minayko  路  4Comments

bluenucleus picture bluenucleus  路  5Comments

dddx80 picture dddx80  路  3Comments

NadirBertolasi picture NadirBertolasi  路  10Comments