iOS 13.2 crashes when speaking with AVSpeechSynthesizer

Originator:bsudekum
Number:rdar://23423423423423333 Date Originated:Oct 2
Status:Closed Resolved:True
Product:iOS Product Version:iOS
Classification:Bug Reproducible:Yes
 
When calling `AVSpeechSynthesizer.speak(string:)` the app crashes. This is only occurring on iOS 13.2. Stack trace:

2019-10-07 13:15:43.631368-0700 SpeakExample[52041:5057604] *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <AXSpeechManager 0x600003b78fc0> for the key path "audioSessionCategory" from <AXSpeechManager 0x600003b78fc0> because it is not registered as an observer.'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff23bef05e __exceptionPreprocess + 350
	1   libobjc.A.dylib                     0x00007fff50cb6b20 objc_exception_throw + 48
	2   Foundation                          0x00007fff25707751 -[NSObject(NSKeyValueObserverRegistration) _removeObserver:forProperty:] + 601
	3   Foundation                          0x00007fff25707b5f -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:] + 74
	4   Foundation                          0x00007fff25707a8c -[NSObject(NSKeyValueObserverRegistration) removeObserver:forKeyPath:context:] + 177
	5   libAXSpeechManager.dylib            0x00007fff4e495366 -[AXSpeechManager handleAudioSessionObservers:] + 139
	6   libAXSpeechManager.dylib            0x00007fff4e494c68 -[AXSpeechManager _updateAuxiliarySession:] + 37
	7   libAXSpeechManager.dylib            0x00007fff4e494c0d -[AXSpeechManager _activeAudioRouteChanged:] + 135
	8   libAXSpeechManager.dylib            0x00007fff4e494b4d -[AXSpeechManager init] + 476
	9   AXSpeechImplementation              0x0000000104c8c7ac -[AVSpeechSynthesizer(Implementation) prepareSpeechManager] + 59
	10  AXSpeechImplementation              0x0000000104c8c740 -[AVSpeechSynthesizer(Implementation) init] + 76
	11  SpeakExample                        0x00000001026392f3 $sSo19AVSpeechSynthesizerCABycfcTO + 19
	12  SpeakExample                        0x0000000102638c3f $sSo19AVSpeechSynthesizerCABycfC + 31
	13  SpeakExample                        0x0000000102638b00 $s12SpeakExample14ViewControllerC14viewWillAppearyySbF + 160
	14  SpeakExample                        0x0000000102638d1c $s12SpeakExample14ViewControllerC14viewWillAppearyySbFTo + 60
	15  UIKitCore                           0x00007fff47333ded -[UIViewController _setViewAppearState:isAnimating:] + 661
	16  UIKitCore                           0x00007fff47334509 -[UIViewController __viewWillAppear:] + 115
	17  UIKitCore                           0x00007fff4723ed5e __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.465 + 1280
	18  UIKitCore                           0x00007fff47244bf6 +[UIPresentationController _scheduleTransition:] + 79
	19  UIKitCore                           0x00007fff4723e5f6 -[UIPresentationController runTransitionForCurrentState] + 1716
	20  UIKitCore                           0x00007fff4723b72a -[UIPresentationController _presentWithAnimationController:interactionController:target:didEndSelector:] + 1060
	21  UIKitCore                           0x00007fff479ddb62 -[UIWindow addRootViewControllerViewIfPossible] + 391
	22  UIKitCore                           0x00007fff479dd128 -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 232
	23  UIKitCore                           0x00007fff479de1e5 -[UIWindow _setHidden:forced:] + 362
	24  UIKit                               0x0000000104896a6a -[UIWindowAccessibility _orderFrontWithoutMakingKey] + 84
	25  UIKitCore                           0x00007fff479f1591 -[UIWindow _mainQueue_makeKeyAndVisible] + 42
	26  UIKitCore                           0x00007fff47bf92b1 -[UIWindowScene _makeKeyAndVisibleIfNeeded] + 202
	27  UIKitCore                           0x00007fff46f37f47 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1405
	28  UIKitCore                           0x00007fff479a283e -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1018
	29  UIKitCore                           0x00007fff479a2b80 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 304
	30  UIKitCore                           0x00007fff47512369 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
	31  FrontBoardServices                  0x00007fff3677d3c5 -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 442
	32  FrontBoardServices                  0x00007fff367a365c __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102
	33  FrontBoardServices                  0x00007fff36787ea5 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
	34  FrontBoardServices                  0x00007fff367a32ed __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355
	35  libdispatch.dylib                   0x0000000102960d60 _dispatch_client_callout + 8
	36  libdispatch.dylib                   0x0000000102963cd1 _dispatch_block_invoke_direct + 300
	37  FrontBoardServices                  0x00007fff367c9502 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
	38  FrontBoardServices                  0x00007fff367c91f0 -[FBSSerialQueue _queue_performNextIfPossible] + 441
	39  FrontBoardServices                  0x00007fff367c96ff -[FBSSerialQueue _performNextFromRunLoopSource] + 22
	40  CoreFoundation                      0x00007fff23b52101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
	41  CoreFoundation                      0x00007fff23b5202c __CFRunLoopDoSource0 + 76
	42  CoreFoundation                      0x00007fff23b5185c __CFRunLoopDoSources0 + 268
	43  CoreFoundation                      0x00007fff23b4c50f __CFRunLoopRun + 1263
	44  CoreFoundation                      0x00007fff23b4bcf6 CFRunLoopRunSpecific + 438
	45  GraphicsServices                    0x00007fff38655bb0 GSEventRunModal + 65
	46  UIKitCore                           0x00007fff479a646c UIApplicationMain + 1621
	47  SpeakExample                        0x0000000102639bab main + 75
	48  libdyld.dylib                       0x00007fff51b3cc39 start + 1
	49  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

To reproduce:

Create a new project with Xcode 11.2 and iOS 13.2:

1. Import AVFoundation
2. Run the following code:

let synth = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "hello")
synth.speak(utterance)

Comments

This was fixed in ios 13.2 beta 2.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!