본문 바로가기
PROGRAMMING CODE/SWIFT

[UIkit] 음성출력예제

by daye_ 2023. 6. 12.

 

let speechSynth = AVSpeechSynthesizer()

@IBAction func sayName(_ sender: Any) { //UI요소
        let name: String = nameField.text ?? ""
        let message: String = "안녕하세요, \(name)님"
        helloLabel.text = message
        
        var utterance = AVSpeechUtterance(string: message)
        speechSynth.speak(utterance)
    }