Search code examples
iosavspeechsynthesizer

How to get difference language code for iOS 7 AVSpeechUtterance text to speech?


I want to use iOS 7 new speech synthezis API, and my application is localized in french & english,german,japanese,etc.i want set language code to read text.How to get language code?

utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-ZA"];

Solution

  • You can set one of the bellow language:

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

    or use default locale:

    AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Localized -text"];
     utterance.rate = AVSpeechUtteranceMinimumSpeechRate; // Tell it to me slowly
    [synthesizer speakUtterance:utterance];
    

    update

    this is the list with the supported languages:

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