所以我试图让我的语音合成器暂停,但由于某种原因,它没有暂停。我是初学者,所以我一直在尝试一些事情,但似乎无法弄清楚为什么。如果有人能告诉我出了什么问题,将不胜感激。
停止按钮似乎工作正常
@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
}