Post

Replies

Boosts

Views

Activity

Reply to iOS 15 - AVSpeechSynthesizerDelegate didCancel not getting called
I am still experiencing this in iOS 18.1 using Xcode 16. Feedback filed: FB15164652 See the following sample project: import SwiftUI import AVFoundation class Synthesizer: NSObject, AVSpeechSynthesizerDelegate { let avSpeechSynthesizer = AVSpeechSynthesizer() override init() { super.init() avSpeechSynthesizer.delegate = self } func play() { let utterance = AVSpeechUtterance(string: "Hello world, this is a long string of many words many words many words many words many words") avSpeechSynthesizer.speak(utterance) } func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didStart utterance: AVSpeechUtterance) { print("didStart \(utterance)") DispatchQueue.main.asyncAfter(deadline: .now() + 2) { [weak self] in self?.avSpeechSynthesizer.stopSpeaking(at: .word) } } func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) { print("didFinish \(utterance)") } func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didCancel utterance: AVSpeechUtterance) { print("didCancel \(utterance)") } } struct ContentView: View { @State private var synthesizer = Synthesizer() var body: some View { Button("Play") { synthesizer.play() } } }
Sep ’24