系统自带的语音合成

为备忘,直接上代码

    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 框架。

原文地址:https://www.cnblogs.com/shenhongbang/p/5521832.html