Hi there,
I didn't use ShazamKit, just audio & mixer nodes but I got the same crash required condition is false: IsFormatSampleRateAndChannelCountValid(format)
I follow your article https://developer.apple.com/documentation/shazamkit/matching-audio-using-the-built-in-microphone but still didn't work.
The problem is that issue only reported on crashlytics from my user and I can't reproduce on my device.
Fatal Exception: com.apple.coreaudio.avfaudio
0 CoreFoundation 0x2d5fc __exceptionPreprocess
1 libobjc.A.dylib 0x31244 objc_exception_throw
2 CoreFoundation 0x17a6e0 -[NSException initWithCoder:]
3 AVFAudio 0x634d8 AUGraphNodeBaseV3::CreateRecordingTap(unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer)
4 AVFAudio 0x112624 AVAudioEngineImpl::InstallTapOnNode(AVAudioNode*, unsigned long, unsigned int, AVAudioFormat*, void (AVAudioPCMBuffer*, AVAudioTime*) block_pointer)
5 AVFAudio 0xe7fa0 -[AVAudioNode installTapOnBus:bufferSize:format:block:]
6 Runner 0x1b2f8 closure #1 in SpeechController.initializeAudioInputEngine() + 1269 (SpeechController.swift:1269)
7 Runner 0x11c28 partial apply for thunk for @callee_guaranteed () -> () + 573 (AssetController.swift:573)
8 Runner 0x15160 thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>)
9 libdispatch.dylib 0x3fa8 _dispatch_client_callout
10 libdispatch.dylib 0x137fc _dispatch_lane_barrier_sync_invoke_and_complete
11 Runner 0x1aec8 SpeechController.initializeAudioInputEngine() + 1235 (SpeechController.swift:1235)
12 Runner 0x1f750 SpeechController.applicationWillEnterForeground() + 1923 (SpeechController.swift:1923)
13 Runner 0x13e6c AppDelegate.applicationWillEnterForeground(_:) + 133 (AppDelegate.swift:133)
14 Runner 0x13ee0 @objc AppDelegate.applicationWillEnterForeground(_:) (<compiler-generated>)
15 UIKitCore 0x3f24d0 -[UIApplication _sendWillEnterForegroundCallbacks]
16 UIKitCore 0x3eeb84 __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke_2
17 UIKitCore 0x24f5e4 _UIScenePerformActionsWithLifecycleActionMask
18 UIKitCore 0x3ef00c __101-[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]_block_invoke
19 UIKitCore 0x3eed1c -[_UISceneLifecycleMultiplexer _performBlock:withApplicationOfDeactivationReasons:fromReasons:]
20 UIKitCore 0x1b5834 -[_UISceneLifecycleMultiplexer _evalTransitionToSettings:fromSettings:forceExit:withTransitionStore:]
21 UIKitCore 0x1b5554 -[_UISceneLifecycleMultiplexer uiScene:transitionedFromState:withTransitionContext:]
22 UIKitCore 0x1b500c __186-[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]_block_invoke
23 UIKitCore 0x1b41b4 +[BSAnimationSettings(UIKit) tryAnimatingWithSettings:fromCurrentState:actions:completion:]
24 UIKitCore 0x1b37ec _UISceneSettingsDiffActionPerformChangesWithTransitionContextAndCompletion
25 UIKitCore 0x1b349c -[_UIWindowSceneFBSSceneTransitionContextDrivenLifecycleSettingsDiffAction _performActionsForUIScene:withUpdatedFBSScene:settingsDiff:fromSettings:transitionContext:lifecycleActionType:]
26 UIKitCore 0x24f394 __64-[UIScene scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke.229
27 UIKitCore 0x24ece4 -[UIScene _emitSceneSettingsUpdateResponseForCompletion:afterSceneUpdateWork:]
28 UIKitCore 0x246708 -[UIScene scene:didUpdateWithDiff:transitionContext:completion:]
29 UIKitCore 0x245ee8 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:]
30 FrontBoardServices 0xc290 __76-[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.146
31 FrontBoardServices 0x9834 -[FBSScene _callOutQueue_coalesceClientSettingsUpdates:]
32 FrontBoardServices 0x7090 -[FBSScene updater:didUpdateSettings:withDiff:transitionContext:completion:]
33 FrontBoardServices 0x1f868 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke_2
34 FrontBoardServices 0x1f4c8 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:]
35 FrontBoardServices 0xa510 __94-[FBSWorkspaceScenesClient _queue_updateScene:withSettings:diff:transitionContext:completion:]_block_invoke
36 libdispatch.dylib 0x3fa8 _dispatch_client_callout
37 libdispatch.dylib 0x79f0 _dispatch_block_invoke_direct
Here is my code:
var engine = AVAudioEngine()
let mixer = AVAudioMixerNode()
let soundNode = AVAudioPlayerNode()
let speechNode = AVAudioPlayerNode()
engine.attach(mixer)
engine.connect(mixer, to: engine.outputNode, format: nil)
// Add the sound effects and looping node players
engine.attach(soundNode)
engine.connect(soundNode, to: mixer, format: nil)
let speechFormat = AVAudioFormat.init(
standardFormatWithSampleRate: 32000, channels: 1)
engine.attach(speechNode)
engine.connect(speechNode, to: mixer, format: speechFormat)
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory( AVAudioSession.Category.playAndRecord, mode: mode, options: [.defaultToSpeaker, .allowBluetooth])
try audioSession.setPreferredSampleRate(micSampleRate)
try audioSession.setActive(true)
try engine.inputNode.setVoiceProcessingEnabled(true)
try engine.outputNode.setVoiceProcessingEnabled(true)
engine.inputNode.removeTap(onBus: kBus)
// buffer needs to be 100ms for good latency
engine.inputNode.installTap(
onBus: kBus,
bufferSize: UInt32(inputFormat!.sampleRate * kBufferDuration),
format: inputFormat!
) { buffer, _ in
guard self.microphoneEnabled, !self.appInBackground else {
self.recognize(buffer: buffer)
}
Can you look at is there anything wrong with my code?
Thank you!
Topic:
Media Technologies
SubTopic:
Audio
Tags: