We are providing the ability to speak text in our app using AVSpeechSynthesizer .
Stop the AVSpeechSynthesizer at random I get a crash like the screenshot below.
What causes this error to occur?
It happens occasionally during testing, but it doesn't go away even if I fix it in various ways.
Is this a bug in iOS or is there something I need to fix or add?
If a crash occurs, the message below is also displayed in the log window during debugging.
[AXTTSCommon] _BeginSpeaking: speech cancelled error: Error Domain=TTSErrorDomain Code=-4005 "(null)"
[AXTTSCommon] _BeginSpeaking: couldn't begin playback
TTS Create Code
let utterance = AVSpeechUtterance(string: playText)
if Singletone.sharedInstance().ttsIdentifier != nil {
utterance.voice = AVSpeechSynthesisVoice(identifier: Singletone.sharedInstance().ttsIdentifier!)
}
else {
utterance.voice = AVSpeechSynthesisVoice(language: "en-US")
}
utterance.rate = 0.4
utterance.pitchMultiplier = 1.0
utterance.preUtteranceDelay = -1.0
utterance.postUtteranceDelay = -1.0
utterance.volume = 1.0
if self.synthesizer == nil {
self.synthesizer = AVSpeechSynthesizer()
self.synthesizer!.delegate = self
}
self.synthesizer!.speak(utterance)
TTS Stop Code
self.synthesizer!.stopSpeaking(at: .immediate)
self.synthesizer!.delegate = nil
self.synthesizer = nil