PROGRAMMING CODE/SWIFT

[UIkit] 음성출력예제

daye_ 2023. 6. 12. 20:45

 

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)
    }