Hello guys, how can I use the speak() API of AVSpeechSynthesizer when I turn off my iPhone?

Hello, I have struggled to resolve issue above question.

I could speak utterance when I turn on my iPhone, but when my iPhone goes to background mode(turn off iPhone), It doesn't speak any more.

I think it is possible to play audio or speak utterance because I can play music on background status in youtube.

Any help please??

Replies

Hey there! AVSpeechSynthesizer obeys the same rules as other audio being played back by your app. As such, the shared audio session for your app needs to be set up to allow for background audio. See the following document for details:

https://developer.apple.com/library/archive/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/AudioSessionBasics/AudioSessionBasics.html