之前以为很难,其实超简单的~! 几行代码就可以搞定 ^_^
NSString *speech = @"花都真的好热啊!"; // 你想设备读出来的文字 AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc] init]; AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:speech]; utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"zh-CN"]; // 设置朗读的语言(有多种口音,国语北京腔是zh-CN,国语台湾腔是zh-TW,粤语是zh-HK,美式英语是en-US) utterance.rate = 0.1; // 设置语速 utterance.pitchMultiplier = 1; // 设置语调(0.5 - 2.0),默认为1.0 utterance.volume = 1.0; // 设置音量(0.0 - 1.0),默认为1.0 [synthesizer speakUtterance:utterance];
Done!
时间: 2024-10-20 05:41:45