From 1b8172f744fc78fa04da587684d0fced1d0beab9 Mon Sep 17 00:00:00 2001 From: Yannik Bloscheck Date: Thu, 10 Jul 2025 16:02:31 +0200 Subject: [PATCH] [ios] Improved TTS system voice selection Signed-off-by: Yannik Bloscheck --- .../Maps/Core/TextToSpeech/MWMTextToSpeech.mm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm b/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm index da932040b..d82631f96 100644 --- a/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm +++ b/iphone/Maps/Core/TextToSpeech/MWMTextToSpeech.mm @@ -243,9 +243,24 @@ using Observers = NSHashTable; AVSpeechSynthesisVoice * voice = nil; for (NSString * loc in candidateLocales) { - voice = [AVSpeechSynthesisVoice voiceWithLanguage:loc]; - if (voice) + if (@available(iOS 16.0, *)) { + for (AVSpeechSynthesisVoice * aVoice in [AVSpeechSynthesisVoice speechVoices]) { + if (voice == nil && aVoice.language == loc && aVoice.quality == AVSpeechSynthesisVoiceQualityPremium) { + voice = aVoice; + } + } + } + for (AVSpeechSynthesisVoice * aVoice in [AVSpeechSynthesisVoice speechVoices]) { + if (voice == nil && aVoice.language == loc && aVoice.quality == AVSpeechSynthesisVoiceQualityEnhanced) { + voice = aVoice; + } + } + if (voice == nil) { + voice = [AVSpeechSynthesisVoice voiceWithLanguage:loc]; + } + if (voice) { break; + } } self.speechVoice = voice;