From 01fa5cad4f99eb56d2ce492657407855acdd13ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20W=C3=BCthrich?= Date: Sat, 17 Aug 2024 12:52:48 -0500 Subject: [PATCH] [ios] Configure audio session once with AVAudioSessionModeVoicePrompt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../Maps/Core/TextToSpeech/MWMTextToSpeech.mm | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm b/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm index c7f7658c54..efcb8b383b 100644 --- a/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm +++ b/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm @@ -101,10 +101,11 @@ using Observers = NSHashTable; 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; 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];