My iOS app provides AVSpeechSynthesizer
support in multiple languages (not just the device's current language).
In Settings->General->Accessibility->Speech->Voices->Spanish
, the user can set a preferred voice to either "Spanish (Spain)" or "Spanish (Mexico)" (which correspond to es-ES and es-MX, respectively).
Similarly with Portuguese (pt-PT, pt-BR), French (fr-FR, fr-CA), etc.
If one of my users wants to have my app speak a Spanish phrase, how can I determine which of the available Spanish voices the user has selected in Settings?
I tested [AVSpeechSynthesisVoice speechVoices]
to see whether the ordering of the voices changes when user preferences changes, but the answer appeared to be no. [AVSpeechSynthesisVoice voiceWithLanguage:]
requires the full language-locale string, so passing in "es" gets you nil even though two Spanish voices are available by default.
I scanned through all the keys in [NSUserDefaults standardUserDefaults]
, but there's nothing relevant there. And I've looked through the UIAccessibility
documentation without finding what I need.
The approach the works for me is as follows:
I've tested in on English, of which there are many variants. It returns the voice that the user has selected in Settings as their preferred voice for their current locale.