user_lion user_lion - 23 days ago 21
iOS Question

AVSpeechSynthesizer in background mode

I can't get the iOS 7

AVSpeechSynthesizer
to work when my iOS app is in background mode. I have added the "App plays audio" key to the app's supported background modes, but I still can't get it to work.

I have also investigated the possibility of creating an
AVMutableCompositionTrack
, with an
AVSpeechSynthesizer
utterance, and then somehow play it with a player that would be able to run in the background - but with no luck.

Did anyone have better luck than me in using
AVSpeechSynthesizer
in the background?

Answer
  1. You must set "Audio and AirPlay" in background modes.
  2. You have to configure the audio session:
    NSError *error = NULL;
    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayback error:&error];
    if(error) {
        // Do some error handling
    }
    [session setActive:YES error:&error];
    if (error) {
        // Do some error handling
    }
Comments