سؤال

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?

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

In swift:

synthesizer.stopSpeaking(at: .immediate)

or

synthesizer.stopSpeaking(at: .word)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top