AVSpeechSynthesizer is broken on iOS 17 in Xcode 15

When you initialize AVSpeechSynthesizer as View prorety in SwiftUI project in Xcode 15 with iOS 17 simulator, you get some comments in console:

Failed to get sandbox extensions
Query for com.apple.MobileAsset.VoiceServicesVocalizerVoice failed: 2
#FactoryInstall Unable to query results, error: 5
Unable to list voice folder
Query for com.apple.MobileAsset.VoiceServices.GryphonVoice failed: 2
Unable to list voice folder
Unable to list voice folder
Query for com.apple.MobileAsset.VoiceServices.GryphonVoice failed: 2
Unable to list voice folder

When you try to run utterance inside a Button as synthesizer.speak(AVSpeechUtterance(string: "iOS 17 broke TextToSpeech")), you get endless stream of warnings that repeaths on and on in console like this:

AddInstanceForFactory: No factory registered for id <CFUUID 0x60000024f200> F8BB1C28-BAE8-11D6-9C31-00039315CD46
Cannot find executable for CFBundle 0x600003b2cd20 </Library/Developer/CoreSimulator/Volumes/iOS_21A328/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.0.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/TextToSpeechMauiSupport.framework> (not loaded)
Failed to load first party audio unit from TextToSpeechMauiSupport.framework
Could not instantiate audio unit. Error=Error Domain=NSOSStatusErrorDomain Code=-3000 "(null)"
Could not instantiate audio unit. Error=Error Domain=NSOSStatusErrorDomain Code=-3000 "(null)"
Could not instantiate audio unit. Error=Error Domain=NSOSStatusErrorDomain Code=-3000 "(null)"
Could not instantiate audio unit. Error=Error Domain=NSOSStatusErrorDomain Code=-3000 "(null)"
Could not instantiate audio unit. Error=Error Domain=NSOSStatusErrorDomain Code=-3000 "(null)"
Couldn't find audio unit for request SSML Length: 40, Voice: [AVSpeechSynthesisProviderVoice 0x600002127e30] Name: Samantha, Identifier: com.apple.voice.compact.en-US.Samantha, Supported Languages (
    "en-US"
), Age: 0, Gender: 0, Size: 0, Version: (null)
VoiceProvider: Could not start synthesis for request SSML Length: 40, Voice: [AVSpeechSynthesisProviderVoice 0x600002127e30] Name: Samantha, Identifier: com.apple.voice.compact.en-US.Samantha, Supported Languages (
    "en-US"
), Age: 0, Gender: 0, Size: 0, Version: (null), converted from tts request [TTSSpeechRequest 0x600003709680] iOS 17 broke TextToSpeech language: en-US footprint: compact rate: 0.500000 pitch: 1.000000 volume: 1.000000
Failed to speak request with error: Error Domain=TTSErrorDomain Code=-4010 "(null)". Attempting to speak again with fallback identifier: com.apple.voice.compact.en-US.Samantha

CPU is under pressure (more than 100%). AVSpeechSynthesizer doesn't speak. All works fine on iOS 16.

The code of View:

import SwiftUI
import AVFoundation

struct ContentView: View {
    let synthesizer = AVSpeechSynthesizer()
    
    var body: some View {
        VStack {
            Button {
                synthesizer.speak(AVSpeechUtterance(string: "iOS 17 broke TextToSpeech"))
            } label: {
                Text("speak")
            }
            .buttonStyle(.borderedProminent)

        }
        .padding()
    }
}

#Preview {
    ContentView()
}

On the real device nothing at all happened.

The same happens to my production app. I have so much crashes related to TextToSpeach and iOS 17. What's going on?

For whatever reason I'm not getting e-mail notifications when people reply in this thread even though I'm "following it." Weird.

I'm a little confused by all the manually downloading voice stuff. I don't particularly care that much that speech synthesis isn't working in the simulator (although it would be nice if it did...like it use to). I noticed, on device, that speech synthesis just randomly seems to stop working since the release of iOS 17. Incorrect behavior includes:

-Jumping around to random ranges of the speech string at random points. -Speech synthesis simply stops speaking at certain points of some speech strings.

When synthesizing short amounts of text (a couple of words) it usually "works" but the inconsistent behavior seems to match the idea that there are possibly memory management issues going on under the covers. I haven't checked on iOS 17.2 to see if it's fixed. Nothing in the release notes say anything about it. The API is basically unusable. My TSI got closed with a no workaround available message and my bug report has not received a reply.

Sooo....they seem to be in no rush to fix it. I was going to release my app in just a few days before they broke it and put me on hold. Investigating alternatives. Feels like I got burned. I imagine all the devs who already have a released app using AVSpeechSynthesizer must feel really burned.

In iOS 17.2 the address sanitizer crash seems to be fixed and also in the field I don't see TTS related crashes anymore. Have anyone seen some functional problems (like stopping speaking of long texts) on iOS 17.2?

@And0Austria Thanks for sharing that info. I'll have to give AVSpeechSynthesizer another try on iOS 17.2 now and see. It would be nice (if they did fix it) if they included that information in the release notes and/or updated some of our bug reports but if it's fixed that'll be good enough....

This is a frustrating bug that has been around in various incarnations since iOS 15. I hold no hope that Apple will ever fix. Have resorted to 3rd part TTS services as not able to rely on this for mission critical application features. Sadly they cost money, but I don't see any real alternative. On the plus side, the voices are about a million time better than the broken/garbage ones that are supposedly part of the AVFoundation framework.

Godspeed.

Got Xcode 15.3 Beta with iOS 17.2 fixes the problem

It probably a silly question but did you set Category?

try? AVAudioSession.sharedInstance().setCategory(.playback)

I have the exactly error like this. But after setting AVAudioSession category, the issue is gone

AVSpeechSynthesizer is broken on iOS 17 in Xcode 15
 
 
Q