Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop AVSpeechSynthesizer playback in the middle?

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?

like image 352
Jason Avatar asked Nov 19 '13 06:11

Jason


2 Answers

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).

like image 147
zadr Avatar answered Oct 22 '22 22:10

zadr


In swift:

synthesizer.stopSpeaking(at: .immediate)

or

synthesizer.stopSpeaking(at: .word)
like image 8
Hemang Avatar answered Oct 22 '22 23:10

Hemang