AVSpeechSynthesizer CRASH with certain voices under iOS 14.2+

Starting with iOS 14.2, AVSpeechSynthesizer will crash when it has a delegate assigned which implements the method, speechSynthesizer(_:willSpeakRangeOfSpeechString:utterance:).

The mere presence of the above method in the delegate will cause a crash BUT ONLY WITH CERTAIN VOICES. For example the default voice crashes while the enhanced voice, Alex does not.

I've created a simple project (which I've submitted through Feedback Assistant) with two buttons which demonstrates how one voice will cause a crash while another will not.

This breaks critical functionality of my app and my customers are not happy.

Any help with this would be much appreciated!


Any help with this would be much appreciated!

Better show your code to get help.
Can you share the feedback ID that you filed?

Can you share the feedback ID that you filed?


Thank you for the reply. Feedback ID is FB8976882.

I've reproduced this bug on several iOS devices and simulators using 14.2, 14.3 and 14.4 beta.
Watching this bug as I think I've seen it myself. Thanks for writing up the report and narrowing it to the willSpeakRangeOfSpeechString delegate. That may be prove helpful.
I'm seeing a crash on AVSpeechSynthesizer as well - it *just* started yesterday, on January 20th. I didn't put out an app update recently and there haven't been any recent iOS updates, either, so it's unclear why this class would just randomly start crashing all of a sudden.

I've filed my bug report as FB8977390.

I'm attaching the relevant stack trace below. OP, is this the same crash you are seeing?

Exception Type: EXCBADACCESS (SIGSEGV)
Exception Subtype: KERNINVALIDADDRESS at 0x0000000143794089
VM Region Info: 0x143794089 is not in any region. Bytes after previous region: 295050 Bytes before following region: 442231
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
MALLOCLARGE 143700000-14374c000 [ 304K] rw-/rwx SM=PRV
  • --> GAP OF 0xb4000 BYTES

MALLOC
SMALL 143800000-144000000 [ 8192K] rw-/rwx SM=PRV

Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [21347]
Triggered by Thread: 13

Thread 13 name: com.apple.TextToSpeech.SpeechThread
Thread 13 Crashed:
0 TextToSpeech 0x00000001a7ca6e4c TTSCreateDecryptedDataFromEncryptedData + 168
1 TextToSpeech 0x00000001a7ca6e6c TTSCreateDecryptedDataFromEncryptedData + 200
2 TextToSpeechBundleSupport 0x00000001b0b5d674 -[TTSVocalizer loadResource:mimeType:resourceURL:supportsAccurateWordCallbacks:] + 424
3 TextToSpeechBundleSupport 0x00000001b0b5aa34 -[TTSSpeechServerInstance loadVoiceResource:voiceResource:] + 484
4 TextToSpeechBundleSupport 0x00000001b0b5a510 -[TTSSpeechServerInstance
initializeSpeechEngine:] + 1852
5 TextToSpeechBundleSupport 0x00000001b0b5a794 -[TTSSpeechServerInstance initializeSpeech:] + 56
6 TextToSpeechBundleSupport 0x00000001b0b57c10 -[TTSSpeechServerInstance
processCurrentRequest:] + 64
7 TextToSpeechBundleSupport 0x00000001b0b58e44 -[TTSSpeechServerInstance handleSpeechThread] + 1552
8 TextToSpeechBundleSupport 0x00000001b0b57bc0
SpeechThread + 48
9 libsystempthread.dylib 0x00000001d30e5b40 pthreadstart + 320
10 libsystem
pthread.dylib 0x00000001d30ee768 thread_start + 8

OP, is this the same crash you are seeing?

looks the same, yes.

it seems to be limited to iOS 14.2+ but I also just started hearing reports about it early on the 20th.


Hi

I have this on production, 1k crashes every day.  Unfortunately, I can't reproduce it on my device.  Can you please tell me how to reproduce this? I am desperately looking for some workaround to this problem.
I am also getting this issue as well. Attached my stack trace below:

Code Block
OS Version: iOS 14.3 (18C66)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: BUS_NOOP at 0x000000011a400000
Crashed Thread: 37
Application Specific Information:
appendBytes:length: > appendData: > containsString: > countByEnumeratingWithState:objects:count: > dataUsingEncoding: > JBOs > path >
Attempted to dereference garbage pointer 0x11a400000.
Thread 37 Crashed:
0 TextToSpeech 0x340a12688 TTSCreateDecryptedDataFromEncryptedData
1 TextToSpeechBundleSupport 0x351d36b88 -[TTSVocalizer loadResource:mimeType:resourceURL:supportsAccurateWordCallbacks:]
2 TextToSpeechBundleSupport 0x351d34188 -[TTSSpeechServerInstance _loadVoiceResource:voiceResource:]
3 TextToSpeechBundleSupport 0x351d33c80 -[TTSSpeechServerInstance _initializeSpeechEngine:]
4 TextToSpeechBundleSupport 0x351d33f00 -[TTSSpeechServerInstance _initializeSpeech:]
5 TextToSpeechBundleSupport 0x351d3149c -[TTSSpeechServerInstance _processCurrentRequest:]
6 TextToSpeechBundleSupport 0x351d32630 -[TTSSpeechServerInstance _handleSpeechThread]
7 TextToSpeechBundleSupport 0x351d31450 _SpeechThread
8 libsystem_pthread.dylib 0x393d15b38 _pthread_start

Same issue, here is the crash report




My crash report is below. My hypothesis, based on the error having to do with decrypting encrypted data, is that a certificate or key expired someplace, and iOS's voice library can no longer decode certain voice files. But that really doesn't explain why it is so intermittent.

Code Block
CrashReporter Key: 890f4575948bc41c861ae0f37928bcdd912bd0d3
Hardware Model: iPhone10,5
Process: dvxapp
Identifier: com.davinix.dvxapp
Version: 1.7.0
Role: Foreground
OS Version: iOS 14.3
Exception Type: EXC_BAD_ACCESS
EXC_BAD_ACCESS: Attempted to dereference garbage pointer 0x11f600000.
0 TextToSpeech _TTSCreateDecryptedDataFromEncryptedData
1 TextToSpeechBundleSupport -[TTSVocalizer loadResource:mimeType:resourceURL:supportsAccurateWordCallbacks:]
2 TextToSpeechBundleSupport -[TTSSpeechServerInstance _loadVoiceResource:voiceResource:]
3 TextToSpeechBundleSupport -[TTSSpeechServerInstance _initializeSpeechEngine:]
4 TextToSpeechBundleSupport -[TTSSpeechServerInstance _initializeSpeech:]
5 TextToSpeechBundleSupport -[TTSSpeechServerInstance _processCurrentRequest:]
6 TextToSpeechBundleSupport -[TTSSpeechServerInstance _handleSpeechThread]
7 TextToSpeechBundleSupport SpeechThread
8 libsystem_pthread.dylib pthread_start


Edited to add: I was able to resolve this by removing the willSpeakRangeOfSpeechString method from my speech synthesizer delegate, which fortunately I didn't use for anything.

To those trying to reproduce, try using the com.apple.ttsbundle.sirimaleen-US_compact (Aaron) or com.apple.ttsbundle.Samantha-compact (Samantha) voice, which gave me the most consistent crashes.
After removing the speech synthesizer's delegate, I haven't been able to reproduce. So that seems to be the workaround for now, if your app doesn't rely on the functionality in the delegate. (It breaks an animation for me, but I'd rather lose that than have the app crash all the time.)

I agree that it must be something with a certificate expiring (or at least something along those lines) - that would explain why it randomly cropped up out of nowhere.
Yes, removing the delegate callback will resolve the crash (although will disable functionality which I understand is undesirable). Another workaround would be to use one of the MacinTalk voices (this is only for en-US). Fred is preinstalled, and users can also download Alex and Victoria in Settings.

Otherwise, there isn't much you can do to mitigate this issue on your end. It is an asset issue though so an OTA update should resolve this without an app update required from any developer.

an OTA update should resolve this without an app update required


Thank you for the information. Will iOS 14.4 have a fix for this bug or will we have to wait until iOS 14.5? 

It is an asset issue though so an OTA update should resolve this without an app update required from any developer.

Any idea when the update will be available? My app depends on this functionality.


I have a major app update scheduled to go live on January 28th, will the OTA update be pushed out before then? Or should I resubmit with the workaround to ensure there are no crashes on launch day?
AVSpeechSynthesizer CRASH with certain voices under iOS 14.2+
 
 
Q