On iOS 16 beta, the following code is crashing:
AVSpeechSynthesisVoice(language: "en-US")!
with the following error code:
Fatal error: Unexpectedly found nil while unwrapping an Optional value
It worked fine before and I’m not seeing any API change.
Does anyone know what could be going on?
2
Answers
It seems like Apple missed to add voice libraries to iOS 16 betas. Below code returns nil.
Which should return the list of available voices. I filed a bug, you should also.
I believe you are experiencing this in the simulator, but not on actual devices – correct? The reason is that for iOS 16, the devices in the Xcode simulator do not come with any built-in voices, whereas they always used to.
As a result,
AVSpeechSynthesisVoice.speechVoices()
returns[]
, andAVSpeechSynthesisVoice(language: "en-US")
returnsnil
.To solve this, simply download one or more voices to the simulated device you are compiling to. To do that, on the device go to
Settings > Accessibility > Spoken Content > Voices > English
, select a voice, and download it.