Voice Downloading
In this guide you will learn how to list all navigation instruction voices available on the server, indicating which are already downloaded, and download a voice.
Setup
- Get your Magic Lane API key token: if you do not have a token, see the Getting Started guide
- Download the Maps & Navigation SDK for Android archive file
- Download the VoiceDownloading project archive file or clone the project with Git
- See the Configure Android Example guide
Run the example
In Android Studio, from the File
menu, select Sync Project with Gradle Files
An android device should be connected via USB cable.
Press SHIFT+F10 to compile, install and run the example on the android device.



How it works
You can open the MainActivity.kt file to see how the list of navigation instruction voices is obtained from the server, displayed, and how a voice is downloaded.
SdkSettings.onConnectionStatusUpdated = { connected ->
if (connected && !voicesCatalogRequested)
{
voicesCatalogRequested = true
val loadVoicesCatalog = {
SdkCall.execute {
// Defines an action that should be done after the network is connected.
// Call to the content store to asynchronously retrieve the list of voices.
contentStore.asyncGetStoreContentList(EContentType.HumanVoice, progressListener)
}
}
}
}
The MainActivity
overrides the onCreate
function, which sends an asynchronous request to the server, once a connection is available, to load the list of available voices. In the request to get the voices from the server, a progressListener
is also passed in:
contentStore.asyncGetStoreContentList(EContentType.HumanVoice, progressListener)
private val progressListener = ProgressListener.create(
onStarted = {
progressBar?.visibility = View.VISIBLE
showStatusMessage("Started content store service.")
},
onCompleted = { errorCode, _ ->
progressBar?.visibility = View.GONE
showStatusMessage("Content store service completed with error code: $errorCode")
when (errorCode)
{
GemError.NoError ->
{
// No error encountered, we can handle the results.
SdkCall.execute {
// Get the list of voices that was retrieved in the content store.
val models = contentStore.getStoreContentList(EContentType.HumanVoice)?.first
if (!models.isNullOrEmpty())
{
// The voice items list is not empty or null.
val voiceItem = models[0]
val itemName = voiceItem.name
// Start downloading the first voice item.
SdkCall.execute {
voiceItem.asyncDownload(GemSdk.EDataSavePolicy.UseDefault,
true,
onStarted = {
showStatusMessage("Started downloading $itemName.")
},
onCompleted = { _, _ ->
listView?.adapter?.notifyItemChanged(0)
showStatusMessage("$itemName was downloaded.")
},
onProgress = {
listView?.adapter?.notifyItemChanged(0)
})
}
}
displayList(models)
}
}
GemError.Cancel ->
{
// The action was cancelled.
}
else ->
{
// There was a problem at retrieving the content store items.
showDialog("Content store service error: ${GemError.getMessage(errorCode)}")
}
}
},
postOnMain = true
)
In MainActivity
a progressListener
is created to wait for the online content store service to start. The onCompleted
block in the progress listener waits for the content store service to be ready.
If there was no error in obtaining the list of voices from the server, requested from the onCreate
function, the progress listener gets the list of voices from the downloaded (local) copy of the list:
val models = contentStore.getStoreContentList(EContentType.HumanVoice)?.first
If the list of voices, named models
, is not empty, then the data (sound) for the first voice in the list, at index 0, is downloaded automatically:
val voiceItem = models[0]
voiceItem.asyncDownload()
private fun displayList(models: ArrayList<ContentStoreItem>?)
{
if (models != null)
{
val adapter = CustomAdapter(models)
listView?.adapter = adapter
}
}
The example also uses a CustomAdapter
to display a scrollable list of country names, flags and voice names with the displayList()
function.
Android Examples
Maps SDK for Android Examples can be downloaded or cloned with Git