您的位置:首页 > 移动开发 > IOS开发

AVFoundation的文本到语音-NSSpeechSynthesizer

2015-10-29 11:15 489 查看

二、IOS- AVFoundation的文本到语音

1、NSSpeechSynthesizer

NSSpeechSynthesizer实例完成了文本到语音的工作。

2、NSSpeechUtterance

NSSpeechUtterance的实例是语音内容。

2.1、初始化

NSSpeechUtterance *utterance = [[NSSpeechUtterance alloc] initWithString:@"语音的内容"];

2.2、常用属性

2.2.1、rate(float)

语音内容播发的速率,该值介于AVSpeechUtteranceMinimumSpeechRate和AVSpeechUtteranceMaximumSpeechRate之间,及0.0到1.0之间。

2.2.2、pitchMultiplier(float)

语音内容播发的音调,该值一般介于0.5(低语调)和2.0(高音调)之间。

2.2.3、postUtteranceDelay(NSTimeInterval)

播放下一句语句之前的暂停时间。

2.2.4、voice(AVSpeechSynthesisVoice)

语音内容播发的语言。AVSpeechSynthesisVoice的一个实例,可以通过类方法+ (nullableAVSpeechSynthesisVoice
*)voiceWithLanguage:(nullableNSString *)languageCode;获取语音实例,可以通过类方法+ (NSArray<AVSpeechSynthesisVoice
*> *)speechVoices;获取所支持语言类型。

3、将NSSpeechUtterance添加到NSSpeechSynthesizer

NSSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizeralloc]
init];

AVSpeechUtterance *utterance =  [[AVSpeechUtterancealloc]
initWithString:self.speechStrings[i]];

utterance.voice = [AVSpeechSynthesisVoicevoiceWithLanguage:@"en-US"];

utterance.rate =0.5f;

utterance.pitchMultiplier =0.8f;

utterance.postUtteranceDelay =0.1f;

[synthesizer
speakUtterance:utterance];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息