本文使用AVSpeechSynthesizer和AVSpeechUtterance两个类来完成语音朗读文字功能。
需要:
- 为项目添加
AVFoundation框架 - 导入头文件
import AVFoundation
实例代码:
import UIKit
import AVFoundation
class ViewController: UIViewController {
var synthesizer:AVSpeechSynthesizer?
var utterance:AVSpeechUtterance?
@IBAction func clickMe(sender: AnyObject) {
var content:String = "你好,我是ricky,欢迎学习iOS开发!"
if synthesizer!.speaking{
synthesizer!.stopSpeakingAtBoundary(AVSpeechBoundary.Immediate)
}else{
utterance = AVSpeechUtterance(<

最低0.47元/天 解锁文章
4761

被折叠的 条评论
为什么被折叠?



