我正在尝试向 iOS 上的用户播放自定义消息。我想知道的只是一条简单的消息,上面写着“Hello World”。有没有办法将字符串传递给 AVFoundation
并让系统播放它?另外,我正在寻找 Swift 中的答案是可能的。
最佳答案
AVSpeechSynthesizer
可以做到这一点:
import UIKit
import AVFoundation
class ViewController: UIViewController {
let speechSynthesizer = AVSpeechSynthesizer()
override func viewDidLoad() {
super.viewDidLoad()
speechSynthesizer.speakUtterance(AVSpeechUtterance(string: "Hello World!"))
}
}
关于iOS 音频视频自定义消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39254185/