Strange crash in iOS AudioToolboxCore when using AVSpeechSynthesizer in iOS 16

I'm getting Crashlytics crashes from some my users, deep in the Apple code:

Crashed: AXSpeech
EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x00000007ec54b360

0  libobjc.A.dylib                0x3c9c objc_retain_x8 + 16
1  AudioToolboxCore               0x99580 auoop::RenderPipeUser::~RenderPipeUser() + 112
2  AudioToolboxCore               0xe6090 -[AUAudioUnit_XPC internalDeallocateRenderResources] + 92
3  AVFAudio                       0x90a0 AUInterfaceBaseV3::Uninitialize() + 60
4  AVFAudio                       0x4cbe0 AVAudioEngineGraph::PerformCommand(AUGraphNodeBaseV3&, AVAudioEngineGraph::ENodeCommand, void*, unsigned int) const + 768
5  AVFAudio                       0x56b0c AVAudioEngineGraph::_Uninitialize(NSError**) + 132
6  AVFAudio                       0x7834 AVAudioEngineImpl::Stop(NSError**) + 388
7  AVFAudio                       0x636c -[AVAudioEngine dealloc] + 52
8  TextToSpeech                   0x30674 _TTSNameForVoiceInformation + 20864
9  libobjc.A.dylib                0x20a4 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
10 libobjc.A.dylib                0x6e00 objc_destructInstance + 80
11 libobjc.A.dylib                0x104fc _objc_rootDealloc + 80
12 TextToSpeech                   0x2d2f4 _TTSNameForVoiceInformation + 7680
13 TextToSpeech                   0x496c TTSVocalizerCopyURLForFallbackResource + 8540
14 TextToSpeech                   0x26094 TTSSpeechUnitTestingMode + 5548
15 libAXSpeechManager.dylib       0x108b0 -[AXSpeechManager .cxx_destruct] + 192
16 libobjc.A.dylib                0x20a4 object_cxxDestructFromClass(objc_object*, objc_class*) + 116
17 libobjc.A.dylib                0x6e00 objc_destructInstance + 80
18 libobjc.A.dylib                0x104fc _objc_rootDealloc + 80
19 libAXSpeechManager.dylib       0x5298 -[AXSpeechManager dealloc] + 268
20 Foundation                     0x3b8a4 __NSThreadPerformPerform + 272
21 CoreFoundation                 0xd3208 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 28
22 CoreFoundation                 0xdf864 __CFRunLoopDoSource0 + 176
23 CoreFoundation                 0x646c8 __CFRunLoopDoSources0 + 244
24 CoreFoundation                 0x7a1c4 __CFRunLoopRun + 828
25 CoreFoundation                 0x7f4dc CFRunLoopRunSpecific + 612
26 Foundation                     0x420c4 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 212
27 libAXSpeechManager.dylib       0x13390 -[AXSpeechThread main] + 552
28 Foundation                     0x5b634 __NSThread__start__ + 716
29 libsystem_pthread.dylib        0x16b8 _pthread_start + 148
30 libsystem_pthread.dylib        0xb88 thread_start + 8

It's most likely related to my use of AVSpeechSynthesizer. I do change some of the utterance fields, including the voice that's being used (which is set to a value from speechVoices()).

UtilAudioIos_tts = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance
utterance.voice = AVSpeechSynthesisVoice(identifier: voice.voiceCode)
utterance.volume = volume
utterance.pitchMultiplier = pitch
utterance.rate = rate
UtilAudioIos_tts!.speak(utterance)

By coincidence or not, the following sometimes appears in the device log:

2023-05-30 20:35:29.948078+0100 <appname>[466:12882] [catalog] Unable to list voice folder

and also, sometimes:

2023-05-30 20:37:35.345933+0100 <appname>[466:13298] [catalog] Query for com.apple.MobileAsset.VoiceServices.VoiceResources failed: 2
2023-05-30 20:37:35.360854+0100 rehearserfree[466:13433] [AXTTSCommon] MauiVocalizer: 11006 (Can't compile rule): regularExpression=\Oviedo(?=, (\x1b\\pause=\d+\\)?Florida)\b, message=unrecognized character follows \, characterPosition=1
2023-05-30 20:37:35.363163+0100 <appname>[466:13433] [AXTTSCommon] MauiVocalizer: 16038 (Resource load failed): component=ttt/re, uri=, contentType=application/x-vocalizer-rettt+text, lhError=88602000
2023-05-30 20:37:35.363182+0100 <appname>[466:13433] [AXTTSCommon] Error loading rules: 2147483648

All of these crashes have been on the various versions of iOS 16.

Edit: I can't reproduce the crash myself - it's just some (not all) app users. The log entries above appear locally on my device (with no crash) but I can't see the logs of the users who have the crashes.

Any idea what this might be caused by, or how to go about tracking the problem down?

Hi! Same here:

Exception Type: EXC_BAD_ACCESS (SIGSEGV) Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000bc229be00 Exception Codes: 0x0000000000000001, 0x0000000bc229be00

Termination Reason: SIGNAL 11 Segmentation fault: 11 Terminating Process: exc handler [1505]

Thread 19 name: Thread 19 Crashed:

0 libobjc.A.dylib 0x000000018395be48 objc_retain_x8 + 16

1 AudioToolboxCore 0x0000000197b6c06c auoop::RenderPipeUser::~RenderPipeUser() + 112 (AUOOPRenderPipePool.mm:400)

2 AudioToolboxCore 0x0000000197bd3308 -[AUAudioUnit_XPC internalDeallocateRenderResources] + 92 (AUAudioUnit_XPC.mm:904)

3 AVFAudio 0x00000001a488087c AUInterfaceBaseV3::Uninitialize() + 60 (AUInterface.mm:524)

4 AVFAudio 0x00000001a48bd144 AVAudioEngineGraph::PerformCommand(AUGraphNodeBaseV3&, AVAudioEngineGraph::ENodeCommand, void*, unsigned int) const + 772 (AVAudioEngineGraph.mm:3317)

5 AVFAudio 0x00000001a48c71d8 AVAudioEngineGraph::_Uninitialize(NSError**) + 132 (AVAudioEngineGraph.mm:1469)

6 AVFAudio 0x00000001a487f184 AVAudioEngineImpl::Stop(NSError**) + 396 (AVAudioEngine.mm:1081)

7 AVFAudio 0x00000001a487dc58 -[AVAudioEngine dealloc] + 52 (AVAudioEngine.mm:76)

8 TextToSpeech 0x00000001abff61a0 -[TTSSynthesisProviderAudioEngine .cxx_destruct] + 104 (TTSSynthesisProviderAudioEngine.m:82)

See here https://developer.apple.com/forums/thread/732335, I also see plenty of crashes especially since iOS 16.5, seems to be even worse on iOS 17. Please give feedback on feedbackassistant.apple.com, it's really frustrating.

Strange crash in iOS AudioToolboxCore when using AVSpeechSynthesizer in iOS 16
 
 
Q