You can try something like this to make AVSpeechSynthesizer speak the text variable:
let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: text)
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
synthesizer.speak(utterance)
You should probably put let synthesizer = AVSpeechSynthesizer()
In the struct ContentView: View
and the rest of the code in the function.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: