I was able to resolve the same issue. Thank you very much!
I wrote the following codes.
struct LessonView: View {
// "let synthesizer = AVSpeechSynthesizer()" should be written here. If you write A in the
// text2speech function,
// synthesizer.speak(utterance) is not worked.
let synthesizer = AVSpeechSynthesizer()
func text2speech() {
// If you write A in the text2speech function, synthesizer.speak(utterance) is not worked.
// let synthesizer = AVSpeechSynthesizer()
let utterance = AVSpeechUtterance(string: "This is a pen.")
utterance.voice = AVSpeechSynthesisVoice(language: "en-GB")
utterance.rate = 0.52
self.synthesizer.speak(utterance)
}
var body: some View {
Button(action : {
text2speech()
}){
LessonButtonView(iconName: "play.circle.fill", labelText: "Play")
}
}
}
However, the issue happens on simulator with iOS 16. But on physical devices, it works as expected.