[ios] Configure audio session once with AVAudioSessionModeVoicePrompt

The audio session is once configured during initialisation and then each time a
audio session is set active. This commit configures the audio session only once
when the app is started. In addition, it sets AVAudioSessionModeVoicePrompt,
which is recommended for apps that use text-to-speech.

Signed-off-by: Fabian Wüthrich <me@fabwu.ch>
This commit is contained in:
Fabian Wüthrich 2024-08-17 12:52:48 -05:00 committed by Alexander Borsuk
parent afe8090982
commit 01fa5cad4f

View file

@ -101,10 +101,11 @@ using Observers = NSHashTable<Observer>;
NSError * err = nil;
if (![[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
withOptions:AVAudioSessionCategoryOptionMixWithOthers |
AVAudioSessionCategoryOptionDuckOthers
mode:AVAudioSessionModeVoicePrompt
options:AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers |
AVAudioSessionCategoryOptionDuckOthers
error:&err]) {
LOG(LWARNING, ("[ setCategory]] error.", [err localizedDescription]));
LOG(LWARNING, ("Couldn't configure audio session: ", [err localizedDescription]));
}
// Set initial StreetNamesTTS setting
@ -240,18 +241,11 @@ using Observers = NSHashTable<Observer>;
stopSession();
return;
} else {
AVAudioSessionMode mode = AVAudioSessionModeDefault;
if ([MWMCarPlayService shared].isCarplayActivated) {
mode = AVAudioSessionModeVoicePrompt;
}
if (![[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
mode:mode
options:
AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers |
AVAudioSessionCategoryOptionDuckOthers
error:nil] ||
![[AVAudioSession sharedInstance] setActive:YES error:nil])
NSError * err = nil;
if (![[AVAudioSession sharedInstance] setActive:YES error:&err]) {
LOG(LWARNING, ("Couldn't activate audio session: ", [err localizedDescription]));
return;
}
for (NSString * notification in turnNotifications)
[self speakOneString:notification];