SDK for Android Developer's Guide

Audio Management

Manage Voice Volume

If your application uses voice navigation, it is recommended that you implement volume ducking and volume control through hardware keys.

Volume ducking is the practice of manipulating volume based on audio focus. It allows another app such as a phone call to flag its audio as having higher priority and "take over" the current device audio. To grant or request audio focus, call NavigationManager.AudioPlayer.getStreamId() to retrieve the current audio stream and then use it with the Android AudioManager. For example:
int result = audioManager.requestAudioFocus(afChangeListener,
By default HERE SDK uses AudioManager.STREAM_MUSIC as the audio stream. For more information on volume ducking, consult this article: "Managing Audio Focus" .

To control voice navigation volume through hardware keys, call Activity.setVolumeControlStream(NavigationManager.AudioPlayer.getStreamId()) at an early point in your app's lifecycle. This ensures that presses on the hardware keys modify the volume for the navigation manager's audio stream. For more information on hardware keys and application audio volume, consult this article: "Controlling Your App's Volume and Playback" .

Overriding Default Audio Playback

HERE SDK provides a way for you to take over audio playback by the NavigationManager. To do this, implement AudioPlayerDelegate class and call NavigationManager.AudioPlayer.setDelegate(AudioPlayerDelegate). Note that setting a delegate stops all audio and text-to-speech playback by the SDK.

AudioPlayerDelegate interface contains two callback methods. When you are implementing your own delegate, follow these recommendations:

  • If you are using your own text-to-speech engine, the locale used in the engine should match up with the VoiceSkin.
  • In most cases the text can be directly submitted to the engine's playback API. For example, for the Android system text-to-speech engine you can submit the text to TextToSpeech.speak(String, int, HashMap).
  • For the best user experience the speech rate and pitch should be adjusted.
  • The list of file paths comes in a sequence. The order in the array indicates the exact order the files should be played. The files are single words used for composing commands with numbers and units.
  • Since recordings may contain padding in the end, do not play the files in a sequence as this sounds too slow and robotic. Instead you can add each file into individual instances of android.Media.MediaPlayer and at almost the end of playback for one file start the next one in parallel. In this manner the resulting sentence sounds more natural. The finite timing before the end of playback can be adjusted and experimented with to achieve the best user experience.