[ios] Changed volume buttons to control notifications volume.

This commit is contained in:
Ilya Grechuhin 2016-08-10 14:52:52 +03:00
parent f0aae07372
commit 4bcb9d6e32

View file

@ -50,7 +50,6 @@ vector<pair<string, string>> availableLanguages()
@property(nonatomic) AVSpeechSynthesisVoice * speechVoice;
@property(nonatomic) float speechRate;
@property(nonatomic) AVAudioSession * audioSession;
@property(nonatomic) NSInteger notificationsToSpeak;
@end
@ -141,10 +140,11 @@ vector<pair<string, string>> availableLanguages()
- (void)setActive:(BOOL)active
{
if (![MWMTextToSpeech isTTSEnabled])
if (![MWMTextToSpeech isTTSEnabled] || self.active == active)
return;
if (active && ![self isValid])
[self createSynthesizer];
[self setAudioSessionActive:active];
GetFramework().EnableTurnNotifications(active ? true : false);
runAsyncOnMainQueue(^{
[[NSNotificationCenter defaultCenter]
@ -225,12 +225,6 @@ vector<pair<string, string>> availableLanguages()
- (void)speakOneString:(NSString *)textToSpeak
{
if (!textToSpeak || ![textToSpeak length])
{
[self reduceNotificationsToSpeak];
return;
}
NSLog(@"Speak text: %@", textToSpeak);
AVSpeechUtterance * utterance = [AVSpeechUtterance speechUtteranceWithString:textToSpeak];
utterance.voice = self.speechVoice;
@ -247,17 +241,10 @@ vector<pair<string, string>> availableLanguages()
vector<string> notifications;
frm.GenerateTurnNotifications(notifications);
[self setActive:YES];
if (![self isValid])
return;
if (!notifications.empty())
{
BOOL const shouldStartAudioSession = (self.notificationsToSpeak == 0);
self.notificationsToSpeak += notifications.size();
if (shouldStartAudioSession && ![self setAudioSessionActive:YES])
return;
}
for (auto const & text : notifications)
[self speakOneString:@(text.c_str())];
}
@ -276,27 +263,6 @@ vector<pair<string, string>> availableLanguages()
return YES;
}
- (void)reduceNotificationsToSpeak
{
self.notificationsToSpeak = MAX(self.notificationsToSpeak - 1, 0);
if (self.notificationsToSpeak == 0)
[self setAudioSessionActive:NO];
}
#pragma mark - AVSpeechSynthesizerDelegate
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
didCancelSpeechUtterance:(AVSpeechUtterance *)utterance
{
[self reduceNotificationsToSpeak];
}
- (void)speechSynthesizer:(AVSpeechSynthesizer *)synthesizer
didFinishSpeechUtterance:(AVSpeechUtterance *)utterance
{
[self reduceNotificationsToSpeak];
}
@end
namespace tts