Manage Voice Volume
If your application uses voice navigation, it is recommended that you implement volume ducking and volume control through hardware keys.
NavigationManager.AudioPlayer.getStreamId()to retrieve the current audio stream, and then use it with the Android
AudioManager. For example:
By default, the HERE SDK uses
int result = audioManager.requestAudioFocus(afChangeListener, NavigationManager.getInstance().getAudioPlayer().getStreamId(), AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
AudioManager.STREAM_MUSICas 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
The HERE SDK provides a way for you to take over audio playback by the
NavigationManager. To do this, implement the
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
- 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 come 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 to achieve the best user experience.