Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the BCP-47 voice codes available for iOS 7 AVSpeechSynthesisVoice?

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

like image 365
mko Avatar asked Dec 15 '13 01:12

mko


2 Answers

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

like image 85
tagy22 Avatar answered Sep 28 '22 00:09

tagy22


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.)

like image 24
jonahb Avatar answered Sep 28 '22 01:09

jonahb