I am using AVSpeechSynthesizer for text-to-speech in my app. Is it possible to stop the playback in the middle, e.g. if the user hits a stop button?
Asked
Active
Viewed 5,835 times
2 Answers
15
Looking at the Documentation for AVSpeechSynthesizer, you need to call -[AVSpeechSynthesizer pauseSpeakingAtBoundary:]
to stop speaking, and, then -[AVSpeechSynthesizer continueSpeaking]
to continue speaking again afterwards.
You can choose to pause speaking right away (AVSpeechBoundaryImmediate
), or, at the end of the current word (AVSpeechBoundaryWord
).
-
Hello, I can't Stop on any button tapped, I want to stop it when cancel button pressed. I tried as below: if(av_speechSynthesizer.isSpeaking || av_speechSynthesizer){ do something } – Er.Shreyansh Shah Nov 05 '14 at 11:35
-
3Instead of "pauseSpeakingAtBoundary:" use [AVSpeechSynthesizer stopSpeakingAtBoundary:AVSpeechBoundaryImmediate]; – Er.Shreyansh Shah Nov 05 '14 at 11:41
9
In swift:
synthesizer.stopSpeaking(at: .immediate)
or
synthesizer.stopSpeaking(at: .word)

Hemang
- 26,840
- 19
- 119
- 186