AVSpeechSynthesizer

iOS中的AVSpeechSynthesizer可以很轻松的实现实现文本到语音的功能,基本代码如下:

self.speechSynthesizer = [[AVSpeechSynthesizeralloc] init];AVSpeechUtterance*utterance = [AVSpeechUtterancespeechUtteranceWithString:@"FlyElephant"];AVSpeechSynthesisVoice*voiceType = [AVSpeechSynthesisVoicevoiceWithLanguage:@"en-US"];utterance.voice = voiceType;//设置语速utterance.rate *=0.5;//设置音量utterance.volume =0.6;[self.speechSynthesizer speakUtterance:utterance];

AVSpeechUtterance可以设置对应的语言,如果设置的语言不能识别文本不能生成语音播放,苹果支持的语言如下:

Arabic (ar-SA)

Chinese (zh-CN, zh-HK, zh-TW)

Czech (cs-CZ)

Danish (da-DK)

Dutch (nl-BE, nl-NL)

English (en-AU, en-GB, en-IE, en-US, en-ZA)

Finnish (fi-FI)

French (fr-CA, fr-FR)

German (de-DE)

Greek (el-GR)

Hebrew (he-IL)

Hindi (hi-IN)

Hungarian (hu-HU)

Indonesian (id-ID)

Italian (it-IT)

Japanese (ja-JP)

Korean (ko-KR)

Norwegian (no-NO)

Polish (pl-PL)

Portuguese (pt-BR, pt-PT)

Romanian (ro-RO)

Russian (ru-RU)

Slovak (sk-SK)

Spanish (es-ES, es-MX)

Swedish (sv-SE)

Thai (th-TH)

Turkish (tr-TR)

以上就是苹果支持的语言编码,当然你也可以通过speechVoices遍历对应的语言编码:

NSArray *voice = [AVSpeechSynthesisVoice speechVoices]; for (AVSpeechSynthesisVoice *voiceModel in voice) { NSLog(@"FlyElephant-%@",voiceModel); }

作者:FlyElephant

链接:https://www.jianshu.com/p/85ffa7a7859a

來源:

著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

你可能感兴趣的:(AVSpeechSynthesizer)