Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spoken locale #235

Merged
merged 4 commits into from
Feb 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions MapboxDirections/MBRoute.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import Polyline
open class Route: NSObject, NSSecureCoding {
// MARK: Creating a Route

@objc internal init(routeOptions: RouteOptions, legs: [RouteLeg], distance: CLLocationDistance, expectedTravelTime: TimeInterval, coordinates: [CLLocationCoordinate2D]?) {
@objc internal init(routeOptions: RouteOptions, legs: [RouteLeg], distance: CLLocationDistance, expectedTravelTime: TimeInterval, coordinates: [CLLocationCoordinate2D]?, speechLocale: Locale?) {
self.routeOptions = routeOptions
self.legs = legs
self.distance = distance
self.expectedTravelTime = expectedTravelTime
self.coordinates = coordinates
self.speechLocale = speechLocale
}

/**
Expand Down Expand Up @@ -46,7 +47,12 @@ open class Route: NSObject, NSSecureCoding {
coordinates = nil
}

self.init(routeOptions: routeOptions, legs: legs, distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates)
var speechLocale: Locale?
if let locale = json["voiceLocale"] as? String {
speechLocale = Locale(identifier: locale)
}

self.init(routeOptions: routeOptions, legs: legs, distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates, speechLocale: speechLocale)
}

@objc public required init?(coder decoder: NSCoder) {
Expand All @@ -70,6 +76,8 @@ open class Route: NSObject, NSSecureCoding {
routeOptions = options

routeIdentifier = decoder.decodeObject(of: NSString.self, forKey: "routeIdentifier") as String?

speechLocale = decoder.decodeObject(of: NSLocale.self, forKey: "speechLocale") as Locale?
}

open static var supportsSecureCoding = true
Expand All @@ -86,6 +94,7 @@ open class Route: NSObject, NSSecureCoding {
coder.encode(expectedTravelTime, forKey: "expectedTravelTime")
coder.encode(routeOptions, forKey: "routeOptions")
coder.encode(routeIdentifier, forKey: "routeIdentifier")
coder.encode(speechLocale, forKey: "speechLocale")
}

// MARK: Getting the Route Geometry
Expand Down Expand Up @@ -194,6 +203,13 @@ open class Route: NSObject, NSSecureCoding {
Each route produced by a single call to `Directions.calculate(_:completionHandler:)` has the same route identifier.
*/
@objc open var routeIdentifier: String?

/**
The locale to use for spoken instructions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explain that this locale is specifically meant for use with the Mapbox Voice API. Add a note about what nil means.


This locale is specific to Mapbox Voice API. If `nil` is returned, the instruction should be spoken with an alternative speech synthesizer.
*/
@objc open var speechLocale: Locale?
}

// MARK: Support for Directions API v4
Expand All @@ -214,6 +230,6 @@ internal class RouteV4: Route {
coordinates = nil
}

self.init(routeOptions: routeOptions, legs: [leg], distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates)
self.init(routeOptions: routeOptions, legs: [leg], distance: distance, expectedTravelTime: expectedTravelTime, coordinates: coordinates, speechLocale: nil)
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions MapboxDirectionsTests/V5Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class V5Tests: XCTestCase {
XCTAssertEqual(route!.accessToken, BogusToken)
XCTAssertEqual(route!.apiEndpoint, URL(string: "https://api.mapbox.com"))
XCTAssertEqual(route!.routeIdentifier, "cj725hpi30yp2ztm2ehbcipmh")
XCTAssertEqual(route!.speechLocale!.identifier, "en-US")


// confirming actual decoded values is important because the Directions API
Expand Down