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

MapboxVoiceController requires access token in Info.plist #1830

Closed
1ec5 opened this issue Nov 10, 2018 · 0 comments
Closed

MapboxVoiceController requires access token in Info.plist #1830

1ec5 opened this issue Nov 10, 2018 · 0 comments
Assignees
Labels
bug Something isn’t working topic: voice
Milestone

Comments

@1ec5
Copy link
Contributor

1ec5 commented Nov 10, 2018

This SDK is designed so that the application can specify a Mapbox access token programmatically at runtime as an alternative to specifying it in the Info.plist file. However, by default, if the application specifies the access token by setting MGLAccountManager.accessToken and passing an access token into Directions(accessToken:), instructions are spoken by VoiceOver instead of by Amazon Polly via the Mapbox Voice API.

Diagnosis

By default, NavigationViewController(for:styles:navigationService:voiceController:) creates a MapboxVoiceController with no arguments:

self.voiceController = voiceController ?? MapboxVoiceController()

By default, MapboxVoiceController(speechClient:dataCache:audioPlayerType:) creates a SpeechSynthesizer with no access token:

@objc public init(speechClient: SpeechSynthesizer = SpeechSynthesizer(accessToken: nil), dataCache: BimodalDataCache = DataCache(), audioPlayerType: AVAudioPlayer.Type? = nil) {

By default, SpeechSynthesizer reads the access token out of the Info.plist file:

https://github.com/mapbox/mapbox-speech-swift/blob/b6b7a8f430efdd9a2945fb2a91347dfc501e7428/MapboxSpeech/MapboxSpeech.swift#L9

With a Debug build of MapboxSpeech, this assertion would fail:

https://github.com/mapbox/mapbox-speech-swift/blob/b6b7a8f430efdd9a2945fb2a91347dfc501e7428/MapboxSpeech/MapboxSpeech.swift#L89-L90

But in a Release build, the library would request audio without an access token, and the Voice API would return an error, causing MapboxVoiceController to fall back to VoiceOver via RouteVoiceController.

Workaround

let voiceController = MapboxVoiceController(speechClient: SpeechSynthesizer(accessToken: "pk.feedCafeDeadBeefBadeBede"))
let navigationViewController = NavigationViewController(for: route, navigationService: navigationService, voiceController: voiceController)

Proposed fix

A fix would look similar to the workaround: by default, NavigationViewController would create a MapboxVoiceController that uses the same access token and API endpoint as the NavigationService:

MapboxVoiceController(speechClient: SpeechSynthesizer(accessToken: navigationService.directions.accessToken))

For this to work, RouteOptions.accessToken needs to be made public: mapbox/mapbox-directions-swift#308.

Note that MapboxNavigationService(route:directions:locationSource:eventsManagerType:simulating:routerType:) also defaults to Directions.shared, which reads the access token from the Info.plist file:

self.directions = directions ?? Directions.shared

So even with this fix, the application would still be required to pass a NavigationService into NavigationViewController(for:styles:navigationService:voiceController:) instead of relying on the default NavigationService. Specifying an access token at runtime requires a lot of fiddling, which is why the Info.plist key is supported as a global configuration option.

/cc @mapbox/navigation-ios

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn’t working topic: voice
Projects
None yet
Development

No branches or pull requests

3 participants