iOS语音合成是iOS7推出的,不需要网络环境。
语音合成的主要的API如下:
1、AVSpeechUtterance,是语音合成的基本单位,它封装影响语音合成的需要的一些参数:语音、语调、语速和延迟等。
2、AVSpeechSynthesisVoice,是语音合成中的Voice对象,它主要包括语音和地区两个方面。
3、AVSpeechSynthesizer,语音合成器的管理类,通过speakUtterance:方法管理AVSpeechSynthesizer。
4、AVSpeechSynthesizerDelegate,是AVSpeechSynthesizer的委托协议。
牛刀小试:
(需要#import <AVFoundation/AVFoundation.h>)
AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init];
// synthesizer.delegate = self;
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"];
AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"湾湾是我们的"];
utterance.voice = voice;
utterance.rate = 0.15; //语速
utterance.volume = 1.0; //音量
[synthesizer speakUtterance:utterance];
语言:
zh-CN : 普通话
zh-HK : 粤语
zh-TW : 湾湾
en-AU, en-GB, en-IE, en-US, en-ZA : 英语
ar-SA : 阿拉伯(Arabic)
cs-CZ :捷克(Czech )
da-DK :丹麦(Danish)
nl-BE, nl-NL : 荷兰(Dutch)
fi-FI : 芬兰(Finnish)
fr-CA, fr-FR :法语(French)
de-DE :德语(German)
el-GR :希腊(Greek)
he-IL : 希伯来语(Hebrew)
hi-IN : 北印度语(Hindi)
hu-HU : 匈牙利语(Hungarian)
id-ID :印度尼西亚语(Indonesian)
it-IT : 意大利语(Italian)
ja-JP : 日语(Japanese)
ko-KR : 韩语(Korean)
no-NO : 挪威语(Norwegian)
pl-PL : 波兰语(Polish)
pt-BR, pt-PT : 葡萄牙语(Portuguese)
ro-RO : 罗马尼亚语(Romanian)
ru-RU : 俄语(Russian)
sk-SK : 斯洛伐克语(Slovak)
es-ES, es-MX : 西班牙语(Spanish)
sv-SE : 瑞典语(Swedish)
th-TH : 泰语(Thai)
tr-TR : 土耳其语(Turkish)
参考:
1、https://www.jianshu.com/p/32a3a55ae01a
2、http://www.cocoachina.com/ios/20160913/17558.html
网友评论