Speech Synthesizer Pause Speaking returns true but doesn't pause text

169 Views Asked by At

so I'm trying to get my speech synthesiser to pause, but for some reason, it's not pausing. I'm a beginner so I've been trying a few things but can't seem to figure out why. Would appreciate if someone can show me what went wrong.

The stop button seems to work fine

    @IBAction func speak(_ sender: UIButton) {
        if !speechSynthesizer.isSpeaking {
            let speechUtterence = AVSpeechUtterance(string: texts.text)
            speechUtterence.rate = rate // 0.0 - 1.0
            speechUtterence.pitchMultiplier = pitch // 0.5 - 2.0 (Default: 1.0)
            speechUtterence.volume = volume // 0.0 - 1.0 (Default: 1.0)

            speechSynthesizer.speak(speechUtterence)
        } else {
            speechSynthesizer.continueSpeaking()
        }
        animateActionButtonAppearance(true) //show Speak Button
    }

    @IBAction func pauseSpeech(_ sender: UIButton) {
        print(speechSynthesizer.pauseSpeaking(at: .word))
        print("pause")

        animateActionButtonAppearance(false) //hide SpeakButton
    }

    @IBAction func stopSpeech(_ sender: UIButton) {
        speechSynthesizer.stopSpeaking(at: .immediate)

        animateActionButtonAppearance(false) //hide SpeakButton
    }


1

There are 1 best solutions below

0
On BEST ANSWER

Okay, so it appears this is a typical beginner mistake where the sent event was assigned wrongly

enter image description here

The part I find interesting is, even though the stop button has the same problem, it appears to be working.

And this happened caused I duplicated my speak button without checking this page before assigning new targets for it. So that's a lesson learned.