1

My iOS10 app does Text to Speech and Speech recognition. It pauses audio from other apps while this happens, and notifies the other when ASR/TTS is over so they can resume their audio. Everything works PERFECT on iPhone5 and 6.

The problem is with iPhone7s: the volume of spoken phrases is very low at first, and louder towards the end of phrases. Why?

I will provide some of my code just in case, because this seems like an iOS bug.

Audio session code:

-(AVAudioSessionCategoryOptions)indigoAudioBehaviorOptions:(AVAudioSession *)s{
    AVAudioSessionCategoryOptions audioIOoptions = [s categoryOptions];
    audioIOoptions |= AVAudioSessionCategoryOptionDefaultToSpeaker;
    audioIOoptions |= AVAudioSessionCategoryOptionAllowBluetooth;
    audioIOoptions |= AVAudioSessionCategoryOptionAllowBluetoothA2DP;
    return audioIOoptions;
}
-(void)notifyIOSthatOtherAppsCanResumeAudioPlayback{
    NSError *err;
    [myAudioSession setActive: NO
                  withOptions: AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation
                        error: &err];
    if(err!=nil){
        NSLog(@"audioIsFreeNotificationForIOS ERROR: %@",err.description);
    }
}


myAudioSession = [AVAudioSession sharedInstance];
NSError *err;
[myAudioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions: [self indigoAudioBehaviorOptions:indigoAudioSession] error:&err];

Text to Speech code:

nativeVocalizer = [[AVSpeechSynthesizer alloc] init];
nativeVocalizer.delegate = self;
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc] initWithString:stringToSpeak];
[utterance setVoice:[AVSpeechSynthesisVoice voiceWithLanguage:lang]];
[nativeVocalizer speakUtterance:utterance];
Josh
  • 6,251
  • 2
  • 46
  • 73

1 Answers1

0

This might happen due to the active audio session AVAudioSession mode.

The only mode where this behavior was not occurring for me was when using mode AVAudioSessionModeMeasurement.

Nicolas S
  • 5,325
  • 3
  • 29
  • 36