iOS - AVSpeechSynthesizer 暂停和继续说话问题
iOS - AVSpeechSynthesizer pause and continueSpeaking issue
macOS: Mojave 10.14.4 beta
iOS: 12.2 beta
Xcode: 10.2 beta
我正在使用 AVSpeechSynthesizer
但下面的代码没有从暂停的地方恢复。
// The pause functionality works fine
if (synth.isSpeaking) {
synth.pauseSpeaking(at: AVSpeechBoundary.word)
}
// But continueSpeaking always starting from the beginning.
if (synth.isPaused) {
synth.continueSpeaking();
}
如何从我离开的地方继续?有什么我想念的吗?
我执行了以下代码来检查您的问题(在 Mojave 10.14.4
、iOS 12.2
、Xcode 10.2.1
和 swift 5.0
下进行的测试):
class SpeechSynthesis: UIViewController {
var synthesizer = AVSpeechSynthesizer()
var playQueue = [AVSpeechUtterance]()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
for i in 1...10 {
let stringNb = "number " + String(i) + " of the speech synthesizer."
let utterance = AVSpeechUtterance(string: stringNb)
playQueue.append(utterance)
}
for utterance in playQueue {
synthesizer.speak(utterance)
}
}
@IBAction func pauseButton(_ sender: UIButton) {
if (synthesizer.isSpeaking == true) {
if (synthesizer.pauseSpeaking(at: .immediate) == true) {
print("PAUSE")
} else {
print("P.R.O.B.L.E.M. when pausing.")
}
}
}
@IBAction func resumeButton(_ sender: UIButton) {
if (synthesizer.isPaused == true) {
if (synthesizer.continueSpeaking() == true) {
print("CONTINUE")
} else {
print("P.R.O.B.L.E.M. when resuming.")
}
}
}
}
我注意到边界 .word
的另一个问题在触发时并不总是暂停,但是当此 约束更改为 .immediate
时,一切都是从暂停处恢复。
然而,当它很少在边界 .word
处暂停时,它也会从它暂停的地方 always resumes。
我不知道你的问题出在哪里,但是通过上面提到的配置和这个代码片段,语音合成器从它暂停的地方恢复。
macOS: Mojave 10.14.4 beta
iOS: 12.2 beta
Xcode: 10.2 beta
我正在使用 AVSpeechSynthesizer
但下面的代码没有从暂停的地方恢复。
// The pause functionality works fine
if (synth.isSpeaking) {
synth.pauseSpeaking(at: AVSpeechBoundary.word)
}
// But continueSpeaking always starting from the beginning.
if (synth.isPaused) {
synth.continueSpeaking();
}
如何从我离开的地方继续?有什么我想念的吗?
我执行了以下代码来检查您的问题(在 Mojave 10.14.4
、iOS 12.2
、Xcode 10.2.1
和 swift 5.0
下进行的测试):
class SpeechSynthesis: UIViewController {
var synthesizer = AVSpeechSynthesizer()
var playQueue = [AVSpeechUtterance]()
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
for i in 1...10 {
let stringNb = "number " + String(i) + " of the speech synthesizer."
let utterance = AVSpeechUtterance(string: stringNb)
playQueue.append(utterance)
}
for utterance in playQueue {
synthesizer.speak(utterance)
}
}
@IBAction func pauseButton(_ sender: UIButton) {
if (synthesizer.isSpeaking == true) {
if (synthesizer.pauseSpeaking(at: .immediate) == true) {
print("PAUSE")
} else {
print("P.R.O.B.L.E.M. when pausing.")
}
}
}
@IBAction func resumeButton(_ sender: UIButton) {
if (synthesizer.isPaused == true) {
if (synthesizer.continueSpeaking() == true) {
print("CONTINUE")
} else {
print("P.R.O.B.L.E.M. when resuming.")
}
}
}
}
我注意到边界 .word
的另一个问题在触发时并不总是暂停,但是当此 约束更改为 .immediate
时,一切都是从暂停处恢复。
然而,当它很少在边界 .word
处暂停时,它也会从它暂停的地方 always resumes。
我不知道你的问题出在哪里,但是通过上面提到的配置和这个代码片段,语音合成器从它暂停的地方恢复。