AVSpeechSynthesizer语音合成

586 阅读1分钟

记录一下

    self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init];AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"FlyElephant"];AVSpeechSynthesisVoice *voiceType = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];utterance.voice = voiceType;//设置语速utterance.rate *= 0.5;//设置音量utterance.volume = 0.6;[self.speechSynthesizer speakUtterance:utterance];


  //以上就是苹果支持的语言编码,当然你也可以通过speechVoices遍历对应的语言编码:
     
   NSArray *voice = [AVSpeechSynthesisVoice speechVoices]; for (AVSpeechSynthesisVoice *voiceModel in voice) { NSLog(@"FlyElephant-%@",voiceModel); }