Do we have any ways to get sound from text?
For example, we have:
let str = "Hello English" .
I want to get sound system from that text.
Do we have any ways to get sound from text?
For example, we have:
let str = "Hello English" .
I want to get sound system from that text.
As Ravy Chheng answered, this uses the built-in AVFoundation library to initialize basic text-to speak function. For more information, check out the documentation by 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)
}