mapbox / mapbox-navigation-ios-examples

A collection of examples showing off the Mapbox Navigation SDK.
https://github.com/mapbox/mapbox-navigation-ios
Other
58 stars 34 forks source link

Example for integrating a third-party speech synthesizer #8

Closed 1ec5 closed 6 years ago

1ec5 commented 6 years ago

Plenty of text-to-speech engines besides Amazon Polly support SSML. Here’s a partial list. RouteVoiceController is open, so a developer write an adapter for a text-to-speech engine of their choice by subclassing it and overriding a few methods, using PollyVoiceController as a model. But an example would make it much easier for someone to do that.

/cc @bsudekum @ericdeveloper @captainbarbosa

bsudekum commented 6 years ago

Once https://github.com/mapbox/mapbox-navigation-ios/pull/617 is live, do you think there is much of a use case? Off the cuff, I think this would be a rather big lift for us.

1ec5 commented 6 years ago

Once mapbox/mapbox-navigation-ios#617 is live, do you think there is much of a use case?

Yes. There will remain some (hopefully niche) reasons to use something other than Polly via the Mapbox Speech API:

Whatever the case, we don’t have to get too fancy with this example. Just take MapboxVoiceController and replace all the code specific to the Mapbox Speech API with a comment explaining what TTS functionality to hook into. It can be up to the developer to understand the third-party library; we don’t have to advertise a particular library.

1ec5 commented 6 years ago

a developer write an adapter for a text-to-speech engine of their choice by subclassing it and overriding a few methods, using PollyVoiceController as a model.

As of mapbox/mapbox-navigation-ios#617, the developer would subclass RouteVoiceController, overriding didPassSpokenInstructionPoint(_:) (to prefetch audio from the network, if desired) and speak(_:) (to play the audio). To keep things simple, the example would probably assume the audio files have been bundled with the application, so the subclass wouldn’t need to override didPassSpokenInstructionPoint(_:); all it would do is override speak(_:) to create an AVAudioPlayer from the file and play it.

1ec5 commented 6 years ago

The override would look something like this:

https://github.com/mapbox/mapbox-navigation-ios/blob/c026c6fe76c34f85c80e50324e6ff4e8f422f256/MapboxNavigation/MapboxSpeechController.swift#L173-L198

I suppose we could also factor out an AudioPlayerVoiceController or something to make this task easier, since methods like duckAudio() are private.