When has the AVSpeechSynthesizer finished reading?

I have a Speech Synthesizer which reads the content of my TableView to the User, if the Speech Synthesizer speaks I want to display a pause symbol and if the Speech Synthesizer does not speak- in case of finished reading or stopped by user or did not start reading at all- I want to display a play symbol. This is what I tried but now the button image does not change at all.
Code Block
@IBAction func didTapPlay(_ sender: Any) {
        if instance.isSpeaking {
            instance.stopSpeaking(at: .word)
            play.setImage(UIImage.init(systemName: "play.fill"), for: .normal)
        }
        else{
            changeOutputString(command: "read")
            play.setImage(UIImage.init(systemName: "pause"), for: .normal)
            stillSpeaking()
        }
    }
    func stillSpeaking(){
        var goingon = true
        while goingon {
            if instance.isSpeaking{
                play.setImage(UIImage.init(systemName: "pause"), for: .normal)
                goingon = false
                }
            Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false){_ in
                print("still waiting")
            }
        }
        play.setImage(UIImage.init(systemName: "play.fill"), for: .normal)
    }

Answered by OOPer in 672414022
I do not understand what you are trying to do with your stillSpeaking. Generally, looping like while goingon ... does not make sense in GUI code.

When you want to detect the AVSpeechSynthesizer finished reading, you implement speechSynthesizer(_:didFinish:) of AVSpeechSynthesizerDelegate.

Please show all the relevant code, if you cannot make it by yourself.
Accepted Answer
I do not understand what you are trying to do with your stillSpeaking. Generally, looping like while goingon ... does not make sense in GUI code.

When you want to detect the AVSpeechSynthesizer finished reading, you implement speechSynthesizer(_:didFinish:) of AVSpeechSynthesizerDelegate.

Please show all the relevant code, if you cannot make it by yourself.
I simply worked with an extension and it works fine, thank you!
When has the AVSpeechSynthesizer finished reading?
 
 
Q