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.

Accepted Reply

Looks like this is working as of Ventura!

Replies

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 ?? "")
}

}

Looks like this is working as of Ventura!