我们有没有办法从文本中获取声音?
例如,我们有:
let str = "Hello English" .
我想从该文本中获取声音系统。
正如 Ravy Chheng 回答的那样,这使用内置的 AVFoundation 库来初始化基本的文本朗读功能。有关更多信息,请查看 Apple 的文档:https : //developer.apple.com/reference/avfoundation/avspeechsynthesizer
import AVFoundation
func playSound(str: String) {
let speechSynthesizer = AVSpeechSynthesizer()
let speechUtterance = AVSpeechUtterance(string: str)
speechSynthesizer.speak(speechUtterance)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句