Skip to content

Use MapboxVoice instead of aws - #617

Merged
bsudekum merged 32 commits into
masterfrom
mapbox-voice-swift
Feb 13, 2018
Merged

bsudekum merged 32 commits into
masterfrom
mapbox-voice-swift

Conversation

@bsudekum

@bsudekum bsudekum commented Sep 15, 2017 •

Copy link
Copy Markdown
Contributor

This removes the dependency on AWS and also makes it so anyone using MapboxCoreNavigation can get access to AWS Polly with only a Mapbox access token.

There is a lot do here, but so far so good.

  • release MapboxVoice
  • improve falling back to AVSpeechSynthesizer
  • Add ssml support back
  • localize voices

/cc @1ec5 @ericrwolfe @frederoni @mapbox/navigation @willwhite

Comment thread Cartfile Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The step table needs this dependency: RouteTableViewCell → VisualInstructionFormatter → RouteStepFormatter → OSRMInstructionFormatter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oh this was a mistake.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will the Voice API choose a voice based on the locale?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'll add this to the list.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we keep the structure with one TTS service per class?
For example, Polly doesn't speak Mandarin so extending RouteVoiceController with AMandarinSpeakingVoiceController shouldn't fall back to MapboxVoice then AVSpeech but directly to AVSpeech.

@bsudekum
bsudekum force-pushed the mapbox-voice-swift branch 4 times, most recently from 6bda83c to e850c44 Compare September 19, 2017 18:30
@bsudekum
bsudekum force-pushed the mapbox-voice-swift branch 2 times, most recently from 9c71dbc to 0310bee Compare December 12, 2017 19:11
Comment thread Cartfile Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will remove once this PR is ready. It makes it easier for me to keep both while developing between branches.

@bsudekum

Copy link
Copy Markdown
Contributor Author

@mapbox/navigation-ios this is ready for review.

}

spokenInstructionsForRoute.countLimit = 200
sessionConfiguration.timeoutIntervalForRequest = timeoutIntervalForRequest;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: drop the semicolon.

for instruction in instructions {
guard spokenInstructionsForRoute.object(forKey: instruction.ssmlText as NSString) == nil else { continue }

cacheAndPlay(instruction: instruction, play: false)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The new code targeting the Mapbox Speech API should live in its own RouteVoiceController subclass for the following reasons:

  • It keeps the failable network request and precaching code more modular.
  • It makes the fallback to AVSpeechSynthesizer more clear.
  • Even if the Mapbox Speech API is available out of the box, a developer may already be using a third-party speech recognition SDK that comes with its own speech synthesizer. Or they may be using a third-party speech synthesizer custom-tailored to a language that the Speech API doesn’t support.

We can have the navigation SDK use this new voice controller by default, but it should still be possible to swap in a different voice controller.

@bsudekum

Copy link
Copy Markdown
Contributor Author

@1ec5 good call, updated.

import MapboxDirections

/**
`PollyVoiceController` extends the default `RouteVoiceController` by providing support for AWSPolly. `RouteVoiceController` will be used as a fallback during poor network conditions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Typo: PollyVoiceController. Also, AWSPolly is no longer a direct dependency.

`PollyVoiceController` extends the default `RouteVoiceController` by providing support for AWSPolly. `RouteVoiceController` will be used as a fallback during poor network conditions.
*/
@objc(MBMapboxSpeechController)
public class MapboxSpeechController: RouteVoiceController {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

MapboxSpeechController and RouteVoiceController have dissimilar names, so the relationship is unclear. Some possibilities:

  • MapboxVoiceController inherits from RouteVoiceController
  • MapboxSpeechController inherits from RouteSpeechController
  • RemoteVoiceController inherits from RouteVoiceController

var urlSession: URLSession
var cacheURLSession: URLSession
var pollyTask: URLSessionDataTask?
var cachePollyTask: URLSessionDataTask?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Remove “Polly” from these property names.

var cachePollyTask: URLSessionDataTask?
var spokenInstructionsForRoute = NSCache<NSString, NSData>()

var mapboxSpeechSynth: SpeechSynthesizer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avoid abbreviating “synthesizer” as “synth”. It’s also a bit redundant that the class MapboxSpeechController in the module MapboxNavigation contains the property mapboxSpeechSynth.

audioTask?.cancel()
let options = SpeechOptions(ssml: instruction.ssmlText)
if let locale = locale {
options.locale = locale

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should figure out a way to let this code know the value of RouteOptions.locale so it can automatically match the language of the SSML coming from the Directions API.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The good news is that the default locale value is calculated in the same manner across libs. But yeah, its almost like we need a public LocaleManager class.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@1ec5 changed in f12ea1b. What are your thoughts on the new API?


let localizedErrorMessage = NSLocalizedString("FAILED_INSTRUCTION", bundle: .mapboxNavigation, value: "Unable to read instruction aloud.", comment: "Error message when the SDK is unable to read a spoken instruction.")

public init(locale: Locale, accessToken: String? = nil, host: String? = nil) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don’t think locale should be an argument on the initializer. A developer using just MapboxSpeechController in conjunction with RouteController (but not NavigationViewController) would need to manually set the locale, which runs counter to the goal of making localization as transparent as possible.

didPassSpokenInstructionPoint(_:) has access to the RouteProgress:

let routeProgresss = notification.userInfo![MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey] as! RouteProgress

so RouteOptions is also easily accessible:

let routeProgresss = notification.userInfo![MBRouteControllerDidPassSpokenInstructionPointRouteProgressKey] as! RouteProgress
let routeOptions = routeProgress.route.routeOptions
…
cacheSpokenInstruction(instruction: instruction, locale: routeOptions.locale)

Streamlining localization is also relevant to RouteVoiceController’s AVSpeechSynthesizer fallback, so I opened #933 to track the general issue.

This was referenced Jan 19, 2018

let utterance = AVSpeechUtterance(string: text)
speechSynth.delegate = self
speechSynth.speak(utterance)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The intent of this code was to demonstrate using AVSpeechSynthesizer as opposed to Polly. speechSynth (still present in this PR) is an instance of AVSpeechSynthesizer.

let localizedErrorMessage = NSLocalizedString("FAILED_INSTRUCTION", bundle: .mapboxNavigation, value: "Unable to read instruction aloud.", comment: "Error message when the SDK is unable to read a spoken instruction.")

public init(accessToken: String? = nil, host: String? = nil) {
@objc public init(accessToken: String? = nil, host: String? = nil) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This method needs documentation.

@@ -9,7 +9,7 @@ import MapboxDirections
`MapboxVoiceController` extends the default `RouteVoiceController` by providing a more robust speech synthesizer via the Mapbox Speech API. `RouteVoiceController` will be used as a fallback during poor network conditions.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it the Mapbox Speech API or the Mapbox Voice API?

/**
Speaks an instruction.

The cache is first checked to see if we have already downloaded the speech file. If not, the instruction is fetched and played. If there is an error anywhere along the way, the instruction will be spoken with the default speech synthesizer.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

s/with the default speech synthesizer/by RouteVoiceController/

/**
Fetches and plays an instruction.
*/
@objc open func fetch(instruction: SpokenInstruction) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Set the argument’s label to _ instruction, so that the call site reads more naturally as “fetch modified instruction” instead of “fetch instruction modified instruction”.

/**
Caches an instruction in an in-memory cache.
*/
@objc open func cacheSpokenInstruction(instruction: SpokenInstruction) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

cache(_ instruction: SpokenInstruction, for consistency with fetch(_:).

Comment thread languages.md Outdated
| Vietnamese | ✅ | ❌ |

The `PollyVoiceController` is powered by Amazon Web Service's Polly product. If Polly supports a language, we will add support for it in [`PollyVoiceController`](https://github.com/mapbox/mapbox-navigation-ios/blob/1d74296aa4c6adc779193fad07f0c97de2f79e90/MapboxNavigation/PollyVoiceController.swift#L99). Reference [AWS Polly supported languages](https://docs.aws.amazon.com/polly/latest/dg/SupportedLanguage.html).
The `MapboxVoiceController` is powered by Amazon Web Service's Polly product. If Polly supports a language, we will add support for it in [`PollyVoiceController`](https://github.com/mapbox/mapbox-navigation-ios/blob/1d74296aa4c6adc779193fad07f0c97de2f79e90/MapboxNavigation/PollyVoiceController.swift#L99). Reference [AWS Polly supported languages](https://docs.aws.amazon.com/polly/latest/dg/SupportedLanguage.html).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Eventually, the MapboxVoiceController column should go away and this document should refer to the Mapbox Voice API documentation at the Mapbox API Documentation site.

@1ec5 1ec5 mentioned this pull request Jan 19, 2018
@@ -0,0 +1,251 @@
// Generated by Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did you mean to check in the framework bundle?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Aw, my mistake.

@bsudekum

Copy link
Copy Markdown
Contributor Author

@mapbox/navigation-ios this is ready for review. All server side API changes are ready and MapboxSpeech.swift v0.0.1 has been released.

@JThramer JThramer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good!

Just thought I would hop back in time and take a quick look at this. Looks good!

Comment thread Cartfile Outdated
@@ -1,7 +1,7 @@
binary "https://www.mapbox.com/ios-sdk/Mapbox-iOS-SDK.json" ~> 3.7
github "mapbox/MapboxDirections.swift" ~> 0.16.0
github "mapbox/MapboxDirections.swift" "voiceLocale"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this has been or will be merged to master, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@JThramer waiting mapbox/mapbox-directions-swift#235 before changing this.

@1ec5 1ec5 left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🙊👍

Before merging, please update the changelog, indicating which classes were renamed, added, or otherwise changed.

"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/SDWebImage.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/Polyline.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/AWSPolly.framework",
"$(BUILT_PRODUCTS_DIR)/$(FRAMEWORKS_FOLDER_PATH)/AWSCore.framework",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should remove this line

@bsudekum
bsudekum merged commit e7d21be into master Feb 13, 2018
@bsudekum
bsudekum deleted the mapbox-voice-swift branch February 13, 2018 21:42
@1ec5 1ec5 added the backwards incompatible changes that break backwards compatibility of public API label Dec 18, 2018
@1ec5 1ec5 added this to the v0.14.0 milestone Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backwards incompatible changes that break backwards compatibility of public API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants