Cody Weaver Cody Weaver - 3 months ago 22
Swift Question

iOS Audio Video custom messages

I am trying to play a custom message to a User on iOS. Just a simple message that will say "Hello World" is all I am wondering. Is there a way to pass a string to

AVFoundation
and have the system play that? Also, I am looking for an answer in Swift is possible.

Answer

AVSpeechSynthesizer can do that:

import UIKit
import AVFoundation

class ViewController: UIViewController {
    let speechSynthesizer = AVSpeechSynthesizer()

    override func viewDidLoad() {
        super.viewDidLoad()

        speechSynthesizer.speakUtterance(AVSpeechUtterance(string: "Hello World!"))
    }
}
Comments