Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/iphone
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2015-08-10 17:37:48 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:01:05 +0300
commitd53a7da394a48a1c1e703b2cc1eed1889eb5e12b (patch)
tree414d546b1dd4605d3144786b6409c79f43638ef3 /iphone
parent31d8897c00348a89fbabc901baa4c1cf8a2e2a8a (diff)
Turn sound notifications. Objective C part.
Diffstat (limited to 'iphone')
-rw-r--r--iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm8
-rw-r--r--iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.cpp9
-rw-r--r--iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.h13
-rw-r--r--iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm107
-rw-r--r--iphone/Maps/Maps.xcodeproj/project.pbxproj8
5 files changed, 132 insertions, 13 deletions
diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm
index 6e6c114779..17c92801ed 100644
--- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm
+++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/MWMNavigationDashboardManager.mm
@@ -12,6 +12,7 @@
#import "MWMNavigationDashboardEntity.h"
#import "MWMNavigationDashboardManager.h"
#import "MWMRoutePreview.h"
+#import "MwmTextToSpeech.h"
@interface MWMNavigationDashboardManager ()
@@ -27,6 +28,7 @@
@property (weak, nonatomic) id<MWMNavigationDashboardManagerProtocol> delegate;
@property (nonatomic, readwrite) MWMNavigationDashboardEntity * entity;
+@property (nonatomic, readwrite) MWMTextToSpeech * tts;
@end
@implementation MWMNavigationDashboardManager
@@ -80,9 +82,15 @@
- (void)setupDashboard:(location::FollowingInfo const &)info
{
if (!self.entity)
+ {
self.entity = [[MWMNavigationDashboardEntity alloc] initWithFollowingInfo:info];
+ self.tts = [[MWMTextToSpeech alloc] init];
+ }
else
+ {
[self.entity updateWithFollowingInfo:info];
+ [self.tts speakNotifications:info.m_turnNotifications];
+ }
[self updateDashboard];
}
diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.cpp b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.cpp
deleted file mode 100644
index 64aac03a85..0000000000
--- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-//
-// MWMTextToSpeech.cpp
-// Maps
-//
-// Created by Vladimir Byko-Ianko on 10.08.15.
-// Copyright (c) 2015 MapsWithMe. All rights reserved.
-//
-
-#include "MWMTextToSpeech.h"
diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.h b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.h
index a5f887bc46..ee69b84696 100644
--- a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.h
+++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.h
@@ -6,4 +6,17 @@
// Copyright (c) 2015 MapsWithMe. All rights reserved.
//
+#import <Foundation/Foundation.h>
+#include "std/string.hpp"
+#include "std/vector.hpp"
+
+
+@interface MWMTextToSpeech : NSObject
+
+- (instancetype)init;
+- (bool)isEnabled;
+- (void)enable:(bool)enalbed;
+- (void)speakNotifications: (vector<string> const &)turnNotifications;
+
+@end
diff --git a/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm
new file mode 100644
index 0000000000..3d6da4898d
--- /dev/null
+++ b/iphone/Maps/Classes/CustomViews/NavigationDashboard/Sound/MWMTextToSpeech.mm
@@ -0,0 +1,107 @@
+//
+// MWMTextToSpeech.cpp
+// Maps
+//
+// Created by Vladimir Byko-Ianko on 10.08.15.
+// Copyright (c) 2015 MapsWithMe. All rights reserved.
+//
+
+#import <AVFoundation/AVFoundation.h>
+
+#include "MWMTextToSpeech.h"
+#include "Framework.h"
+
+
+@interface MWMTextToSpeech()
+@property (readwrite, nonatomic, strong) AVSpeechSynthesizer *speechSynthesizer;
+@property (nonatomic) AVSpeechSynthesisVoice * speechVoice;
+@property (nonatomic) float speechRate;
+@end
+
+@implementation MWMTextToSpeech
+
+- (instancetype)init
+{
+ self = [super init];
+ if (self)
+ {
+ self.speechSynthesizer = [[AVSpeechSynthesizer alloc] init];
+
+ // TODO(vbykoianko) Use [NSLocale preferredLanguages] instead of [AVSpeechSynthesisVoice currentLanguageCode].
+ // [AVSpeechSynthesisVoice currentLanguageCode] is used now because of we need a language code in BCP-47.
+ [self setLocaleIfAvailable:[AVSpeechSynthesisVoice currentLanguageCode]];
+ // iOS has an issue with speechRate. AVSpeechUtteranceDefaultSpeechRate does not work correctly. It's a work around.
+ if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1)
+ self.speechRate = 0.15;
+ else
+ self.speechRate = 0.3;
+ }
+ return self;
+}
+
++ (NSString *)TwineFromBCP47:(NSString *)bcp47LangName
+{
+ NSAssert(bcp47LangName, @"bcp47LangName is nil");
+
+ if ([bcp47LangName isEqualToString:@"zh-CN"] || [bcp47LangName isEqualToString:@"zh-CHS"]
+ || [bcp47LangName isEqualToString:@"zh-SG"])
+ {
+ return @"zh-Hans"; // Chinese simplified
+ }
+
+ if ([bcp47LangName hasPrefix:@"zh"])
+ return @"zh-Hant"; // Chinese traditional
+ // Taking two first symbols of a language name. For example ru-RU -> ru
+ return [bcp47LangName substringToIndex:2];
+}
+
+- (void)setLocaleIfAvailable:(NSString *)locale
+{
+ NSAssert(locale, @"locale is nil");
+
+ NSArray * availTtsLangs = [AVSpeechSynthesisVoice speechVoices];
+ NSAssert(locale, @"availTtsLangs is nil");
+
+ NSString * localeToSet = locale;
+ AVSpeechSynthesisVoice * voiceToSet = [AVSpeechSynthesisVoice voiceWithLanguage:localeToSet];
+ if(!voiceToSet || ![availTtsLangs containsObject:voiceToSet])
+ localeToSet = @"en-GB";
+
+ self.speechVoice = [AVSpeechSynthesisVoice voiceWithLanguage:localeToSet];
+ GetFramework().SetTurnNotificationsLocale([[MWMTextToSpeech TwineFromBCP47:localeToSet] UTF8String]);
+}
+
+- (void)speakText:(NSString *)textToSpeak
+{
+ if (!textToSpeak)
+ return;
+
+ NSLog(@"Speak text: %@", textToSpeak);
+ AVSpeechUtterance * utterance = [AVSpeechUtterance speechUtteranceWithString:textToSpeak];
+ utterance.voice = self.speechVoice;
+ utterance.rate = self.speechRate;
+ [self.speechSynthesizer speakUtterance:utterance];
+}
+
+- (bool)isEnabled
+{
+ return GetFramework().AreTurnNotificationsEnabled();
+}
+
+- (void)enable:(bool)enalbed
+{
+ GetFramework().EnableTurnNotifications(enalbed);
+}
+
+- (void)speakNotifications: (vector<string> const &)turnNotifications
+{
+ if (turnNotifications.empty())
+ return;
+
+ for (auto const & text : turnNotifications)
+ {
+ [self speakText:@(text.c_str())];
+ }
+}
+
+@end
diff --git a/iphone/Maps/Maps.xcodeproj/project.pbxproj b/iphone/Maps/Maps.xcodeproj/project.pbxproj
index c6815a60e9..d7b14314fc 100644
--- a/iphone/Maps/Maps.xcodeproj/project.pbxproj
+++ b/iphone/Maps/Maps.xcodeproj/project.pbxproj
@@ -111,7 +111,7 @@
4A7D89C71B2EBF3B00AC843E /* resources-xhdpi_dark in Resources */ = {isa = PBXBuildFile; fileRef = 4A7D89C31B2EBF3B00AC843E /* resources-xhdpi_dark */; };
4A7D89C81B2EBF3B00AC843E /* resources-xxhdpi_dark in Resources */ = {isa = PBXBuildFile; fileRef = 4A7D89C41B2EBF3B00AC843E /* resources-xxhdpi_dark */; };
5605022F1B6211E100169CAD /* sound-strings in Resources */ = {isa = PBXBuildFile; fileRef = 5605022E1B6211E100169CAD /* sound-strings */; };
- 560634F21B78806100F3D670 /* MWMTextToSpeech.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 560634F11B78806100F3D670 /* MWMTextToSpeech.cpp */; };
+ 560634F21B78806100F3D670 /* MWMTextToSpeech.mm in Sources */ = {isa = PBXBuildFile; fileRef = 560634F11B78806100F3D670 /* MWMTextToSpeech.mm */; };
6B8A738A1B2616E90085EFE6 /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FA87151A12B1518F00592DAF /* SystemConfiguration.framework */; };
6BA0BCD11B74DDBA00CC9969 /* MWMCustomFacebookEvents.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6BA0BCD01B74DDBA00CC9969 /* MWMCustomFacebookEvents.mm */; };
6C24A3AD1AD7CA1000A47B99 /* MWMNoMapInterfaceController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 6C47C8C81AD6C825000C52C1 /* MWMNoMapInterfaceController.mm */; };
@@ -453,7 +453,7 @@
6BA0BCCF1B74DDBA00CC9969 /* MWMCustomFacebookEvents.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMCustomFacebookEvents.h; sourceTree = "<group>"; };
6BA0BCD01B74DDBA00CC9969 /* MWMCustomFacebookEvents.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMCustomFacebookEvents.mm; sourceTree = "<group>"; };
560634F01B78804C00F3D670 /* MWMTextToSpeech.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMTextToSpeech.h; sourceTree = "<group>"; };
- 560634F11B78806100F3D670 /* MWMTextToSpeech.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MWMTextToSpeech.cpp; sourceTree = "<group>"; };
+ 560634F11B78806100F3D670 /* MWMTextToSpeech.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMTextToSpeech.mm; sourceTree = "<group>"; };
6C24A3B01AD7D65500A47B99 /* MWMWatchEventInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMWatchEventInfo.h; sourceTree = "<group>"; };
6C24A3B11AD7D65500A47B99 /* MWMWatchEventInfo.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = MWMWatchEventInfo.mm; sourceTree = "<group>"; };
6C47C8C31AD6C78A000C52C1 /* MWMNoLocationInterfaceController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MWMNoLocationInterfaceController.h; sourceTree = "<group>"; };
@@ -1247,7 +1247,7 @@
isa = PBXGroup;
children = (
560634F01B78804C00F3D670 /* MWMTextToSpeech.h */,
- 560634F11B78806100F3D670 /* MWMTextToSpeech.cpp */,
+ 560634F11B78806100F3D670 /* MWMTextToSpeech.mm */,
);
path = Sound;
sourceTree = "<group>";
@@ -2214,7 +2214,7 @@
341522BF1B666A550077AA8F /* MWMAPIBarView.m in Sources */,
349A35831B53E967009677EE /* MWMDownloadMapRequest.mm in Sources */,
A32B6D4C1A14980500E54A65 /* iosOGLContext.mm in Sources */,
- 560634F21B78806100F3D670 /* MWMTextToSpeech.cpp in Sources */,
+ 560634F21B78806100F3D670 /* MWMTextToSpeech.mm in Sources */,
46F26CD810F623BA00ECCA39 /* EAGLView.mm in Sources */,
EED10A4511F78D120095FAD4 /* MapViewController.mm in Sources */,
F61579341AC2CE9A0032D8E9 /* MWMRateAlert.mm in Sources */,