【问题标题】:Speech Synthesizer Pause Speaking returns true but doesn't pause text语音合成器暂停说话返回 true 但不暂停文本
【发布时间】:2020-06-13 21:33:46
【问题描述】:

所以我试图让我的语音合成器暂停,但由于某种原因,它没有暂停。我是初学者,所以我一直在尝试一些事情,但似乎无法弄清楚为什么。如果有人能告诉我出了什么问题,将不胜感激。

停止按钮似乎工作正常

    @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
    }


【问题讨论】:

    标签: swift avspeechsynthesizer avspeechutterance


    【解决方案1】:

    好的,看来这是一个典型的初学者错误,发送的事件分配错误

    我觉得有趣的部分是,即使停止按钮有同样的问题,它似乎也能正常工作。

    发生这种情况是因为我在为其分配新目标之前没有检查此页面就复制了我的发言按钮。所以这是一个教训。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-30
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多