From 34286dd1a5f2941cc70de9e92ddf86b701c9b328 Mon Sep 17 00:00:00 2001 From: Ilya Grechuhin Date: Fri, 8 Apr 2016 16:00:30 +0300 Subject: [PATCH] [ios] Changed tts voice creation. --- .../Sound/MWMTextToSpeech.mm | 63 ++++++++++--------- 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm index 7e8043ca02..63116ca1e1 100644 --- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm +++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm @@ -55,7 +55,7 @@ static NSString * const DEFAULT_LANG = @"en-US"; if (find(_availableLanguages.begin(), _availableLanguages.end(), lan) != _availableLanguages.end()) [self setNotificationsLocale:preferedLanguageBcp47]; else - [self setNotificationsLocale: isIOS7 || isIOS8 ? DEFAULT_LANG : AVSpeechSynthesisVoiceIdentifierAlex]; + [self setNotificationsLocale:DEFAULT_LANG]; // Before 9.0 version iOS has an issue with speechRate. AVSpeechUtteranceDefaultSpeechRate does not work correctly. // It's a work around for iOS 7.x and 8.x. @@ -146,43 +146,46 @@ static NSString * const DEFAULT_LANG = @"en-US"; - (void)createVoice:(NSString *)locale { - if (!locale) - { - LOG(LERROR, ("locale is nil. Trying default locale.")); - locale = DEFAULT_LANG; - } + NSMutableArray * candidateLocales = [@[DEFAULT_LANG, @"en-GB"] mutableCopy]; - if (!(isIOS7 || isIOS8) && [locale isEqualToString:DEFAULT_LANG]) - locale = AVSpeechSynthesisVoiceIdentifierAlex; + if (locale) + [candidateLocales insertObject:locale atIndex:0]; + else + LOG(LWARNING, ("locale is nil. Trying default locale.")); - NSArray * availTTSLangs = [AVSpeechSynthesisVoice speechVoices]; - - if (!availTTSLangs) + NSArray * availTTSVoices = [AVSpeechSynthesisVoice speechVoices]; + AVSpeechSynthesisVoice * voice = nil; + for (NSString * loc in candidateLocales) { - LOG(LERROR, ("No languages for TTS. MWMTextFoSpeech is invalid.")); - return; // self is not valid. - } - - AVSpeechSynthesisVoice * voice = [AVSpeechSynthesisVoice voiceWithLanguage:locale]; - if (!voice || ![availTTSLangs containsObject:voice]) - { - locale = isIOS7 || isIOS8 ? DEFAULT_LANG : AVSpeechSynthesisVoiceIdentifierAlex; - AVSpeechSynthesisVoice * voice = [AVSpeechSynthesisVoice voiceWithLanguage:locale]; - if (!voice || ![availTTSLangs containsObject:voice]) + if ([loc isEqualToString:@"en-US"]) + voice = [AVSpeechSynthesisVoice voiceWithLanguage:AVSpeechSynthesisVoiceIdentifierAlex]; + if (voice) + break; + for (AVSpeechSynthesisVoice * ttsVoice in availTTSVoices) { - LOG(LERROR, ("The UI language and English are not available for TTS. MWMTestToSpeech is invalid.")); - return; // self is not valid. + if ([ttsVoice.language isEqualToString:loc]) + { + voice = [AVSpeechSynthesisVoice voiceWithLanguage:loc]; + break; + } } + if (voice) + break; } - - self.speechVoice = [AVSpeechSynthesisVoice voiceWithLanguage:locale]; - string const twineLang = tts::bcp47ToTwineLanguage(locale); - if (twineLang.empty()) + + self.speechVoice = voice; + if (voice) { - LOG(LERROR, ("Cannot convert UI locale or default locale to twine language. MWMTestToSpeech is invalid.")); - return; // self is not valid. + string const twineLang = tts::bcp47ToTwineLanguage(voice.language); + if (twineLang.empty()) + LOG(LERROR, ("Cannot convert UI locale or default locale to twine language. MWMTextToSpeech is invalid.")); + else + GetFramework().SetTurnNotificationsLocale(twineLang); + } + else + { + LOG(LERROR, ("The UI language and English are not available for TTS. MWMTextToSpeech is invalid.")); } - GetFramework().SetTurnNotificationsLocale(twineLang); } - (void)speakOneString:(NSString *)textToSpeak