为备忘,直接上代码
AVSpeechUtterance *utt = [AVSpeechUtterance speechUtteranceWithString:@"明天晚上吃啥"];
NSArray *voices = [AVSpeechSynthesisVoice speechVoices];
NSLog(@"%@", voices); //打印所有语言
AVSpeechSynthesisVoice *voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-HK"]; //粤语测试
utt.voice = voice;
AVSpeechSynthesizer *speech = [[AVSpeechSynthesizer alloc] init];
[speech speakUtterance:utt];
类需要引用 AVFoundation 框架。
网友评论