Creating a list of voices available by locale

I'm trying to create a list that users can pick for the voice they want to use in my app. The code below works for US but if I change my locale settings to any other country, it fails to load any available voices even though I have downloaded other for other countries..

func voices() -> [String] {

         AVSpeechSynthesisVoice.speechVoices().filter { $0.language == NSLocale.current.voiceLanguage }.map { $0.name }

          

        // AVSpeechSynthesisVoice.speechVoices().map { $0.name }

    }

If I list all voices available, I can select the voices for other countries that are loaded.

Answered by cleevans in 760497022

Looks like this is working as of Ventura!

Do you have an extension on NSLocale that implements NSLocale.current.voiceLanguage? If so could you include that as well?

Very sorry, I did not see this reply until today:

import Foundation

extension Locale {

var voiceLanguage: String {
    (languageCode ?? "") + "-" + (regionCode ?? "")
}

}

Accepted Answer

Looks like this is working as of Ventura!

Creating a list of voices available by locale
 
 
Q