Question

Today I'm very exited about the speech synthesis function is available in iOS7.

I want to select the male voice(default in OSX, called alex).

I don't know what's the BCP-47 code for him, and BTW how to get the full list of all voice code

Was it helpful?

Solution 2

Here's how to get the BCP-47 codes of the available voices:

for (AVSpeechSynthesisVoice *voice in [AVSpeechSynthesisVoice speechVoices]) {
    NSLog(@"%@", voice.language);
}

Alex's locale is "English - United States" (en-US), as you can see in the Dictation & Speech control panel on OS X. (Click "Customize..." in the "System Voice" drop down.)

OTHER TIPS

iOS 8 added Hebrew, no new languages were added in iOS 9 to 12:

ar-SA       Arabic      Saudi Arabia
cs-CZ       Czech       Czech Republic
da-DK       Danish      Denmark
de-DE       German      Germany
el-GR       Modern Greek        Greece
en-AU       English     Australia
en-GB       English     United Kingdom
en-IE       English     Ireland
en-US       English     United States
en-ZA       English     South Africa
es-ES       Spanish     Spain
es-MX       Spanish     Mexico
fi-FI       Finnish     Finland
fr-CA       French      Canada
fr-FR       French      France
he-IL       Hebrew      Israel
hi-IN       Hindi       India
hu-HU       Hungarian       Hungary
id-ID       Indonesian      Indonesia
it-IT       Italian     Italy
ja-JP       Japanese        Japan
ko-KR       Korean      Republic of Korea
nl-BE       Dutch       Belgium
nl-NL       Dutch       Netherlands
no-NO       Norwegian       Norway
pl-PL       Polish      Poland
pt-BR       Portuguese      Brazil
pt-PT       Portuguese      Portugal
ro-RO       Romanian        Romania
ru-RU       Russian     Russian Federation
sk-SK       Slovak      Slovakia
sv-SE       Swedish     Sweden
th-TH       Thai        Thailand
tr-TR       Turkish     Turkey
zh-CN       Chinese     China
zh-HK       Chinese     Hong Kong
zh-TW       Chinese     Taiwan

edit: Here is how to print the above in Swift:

func printLanguages() {
    AVSpeechSynthesisVoice.speechVoices().forEach { (voice) in
        let language = Locale.current.localizedString(forLanguageCode: voice.language)!
        let components = Locale.components(fromIdentifier: voice.language)
        let country = Locale.current.localizedString(forRegionCode: components["kCFLocaleCountryCodeKey"]!)!
        print("\(voice.language) \t \(language) \t\t \(country)")
    }
}

You need to import AVFoundation

As of iOS 7.1 there are 36 voices for the following BCP-47 codes:

ar-SA
cs-CZ
da-DK
de-DE
el-GR
en-AU
en-GB
en-IE
en-US
en-ZA
es-ES
es-MX
fi-FI
fr-CA
fr-FR
hi-IN
hu-HU
id-ID
it-IT
ja-JP
ko-KR
nl-BE
nl-NL
no-NO
pl-PL
pt-BR
pt-PT
ro-RO
ru-RU
sk-SK
sv-SE
th-TH
tr-TR
zh-CN
zh-HK
zh-TW
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top