AVFoundation-avspeechsynthesizer文字转语音

AVSpeechSynthesizer 文字转语音

简单示例:

1
2
3
4
5

AVSpeechSynthesizer *synthesizer = [AVSpeechSynthesizer new];
AVSpeechUtterance * utterance = [[AVSpeechUtterance alloc] initWithString:@"需要转化的文字"];
//语音合成器会生成音频
[synthesizer speakUtterance:utterance];

指定声音:

1
2
3
//设置语言类别(不能被识别,返回值为nil)
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
utterance.voice = voiceType;

语速:

//设置语速快慢
utterance.rate *= 0.5;    

队列中插入语音

使用 https://github.com/quentinhayot/QHSpeechSynthesizerQueue