iOS朗读

来源:互联网 发布:数据库的结构搭建 编辑:程序博客网 时间:2024/04/27 22:05

1. 导入 #import<AVFoundation/AVFoundation.h>

声明两个属性
@property(nonatomic,strong)AVSpeechSynthesizer* speechSynthesizer; // 合成器
@property(nonatomic,strong)AVSpeechUtterance* speechUtterance; // 合成器所说的内容

// 在viewDidLoad中初始化一次
self.speechSynthesizer= [[AVSpeechSynthesizeralloc]init];

开始阅读:
- (void)startRead {
   
 self.speechUtterance= [[AVSpeechUtterancealloc]initWithString:@“这里是朗读的内容, 从前有座山, 山上有座庙"];   
  [self.speechSynthesizer speakUtterance:self.speechUtterance];
}

0 0