我想使用iOS 7新的语音合成API,我的应用程序本地化为法语&英语,德语,日语等我想要设置语言代码来阅读文本。如何获取语言代码?
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-ZA"];
答案 0 :(得分:19)
您可以设置以下语言之一:
for (AVSpeechSynthesisVoice *voice in [AVSpeechSynthesisVoice speechVoices]) {
NSLog(@" %@", voice.language);
}
或使用默认语言环境:
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Localized -text"];
utterance.rate = AVSpeechUtteranceMinimumSpeechRate; // Tell it to me slowly
[synthesizer speakUtterance:utterance];
更新
这是支持语言的列表:
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
答案 1 :(得分:3)
SWIFT 3更新:
import AVFoundation
(查看语言代码):
for voice in (AVSpeechSynthesisVoice.speechVoices()){
print(voice.language)
}
然后:
let speakTalk = AVSpeechSynthesizer()
let speakMsg = AVSpeechUtterance(string: "Hello World, I can speak")
speakMsg.voice = AVSpeechSynthesisVoice(language: "en-US")
speakMsg.pitchMultiplier = 1.2
speakMsg.rate = 0.5
speakTalk.speak(speakMsg)