iosobjective-ciphoneavspeechsynthesizeronutterancecompleted

AVSpeechUtterance utterance voice in silent mode


I am using AVSpeechUtterance to Speak the given text. I am using the below code and works fine in 'iPhone Ringer Mode' but when I change the iPhone to 'Silent Mode' the utterance voice is getting mute. And when it is 'Silent Mode' I am unable to hear the utterance voice. What should I do to hear the utterance voice in 'Silent Mode'.

AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:@"Hello World"];
utterance.voice = [AVSpeechSynthesisVoice voiceWithLanguage:@"en-US"];
[utterance setRate:AVSpeechUtteranceMinimumSpeechRate];
[utterance setVolume:1];
[self.speechSynthesizer speakUtterance:utterance];

Solution

  • Add the below code before your code. You can write the same code in appDelegate also.

    NSError *setCategoryErr = nil;
    NSError *activationErr  = nil;
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:&setCategoryErr];
    [[AVAudioSession sharedInstance] setActive:YES error:&activationErr];