- Control when audio clips are played
- Pass your application's audio to
NMAAudioManagerby using its audio queue
- Disable automatic
- Receive audio playback events
The section also contains information about audio routing, such as how to use HERE SDK audio with a Bluetooth device.
NMAAudioManager and the Audio Queue
NMAAudioManager is the central class that is used by the SDK for iOS to modify the application's AVAudioSession and play audio. It is the interface that the
NMANavigationManager uses to play audio feedback such as voice instructions. You can also use
NMAAudioManager to change whether hardware keys directly control HERE SDK volume, and also use it to set volume as a factor relative to the user's device volume.
NMAAudioManager contains a queue of audio output objects. You can add to this queue by calling
NMATTSAudioOutput, or your own
NMAAudioOutput implementation. You can also use
NMAAudioManager methods such as
stopOutputAndClearQueue to manage audio output in this queue.
Audio Output Types
By default, the HERE SDK provides two
NMATTSAudioOutput. You can play or enqueue these (or your own custom
NMAAudioOutput subtype) by calling the
playOutput: method with
NMAAudioFileOutput represents a collection of audio files that are compatible with the iOS AVAudioPlayer. You can get an instance by calling
NMAAudioFileOutput audioOutputWithFiles: with an array of compatible files. All files in an
NMAAudioFileOutput instance are together considered as a single output segment when it is played by the
NMATTSAudioOutput represents a text-to-speech audio output segment. It contains a text string to be spoken and an AVSpeechSynthesisVoice. You can get an instance of this class by calling
NMATTSAudioOutput audioOutputWithText: with the text to be converted to a speech sample. By default, the text-to-speech (speech synthesis) engine selects the voice dialect based on the current device locale.
Delaying Audio Playback
You can use the
audioRouteLatencyCompensation property in
NMAAudioManager to introduce some silence before audio playback. This is useful if you need to compensate for Bluetooth connection or audio ducking, and to prevent clipping guidance audio.
Disabling Automatic Playback
In the case where you would like more control over the application's
AVAudioSession, you can use the
managesAudioSession property to manage automatic playback.
managesAudioSession property is
NMAAudioManager automatically configures, activates, and deactivates the
AVAudioSession as needed to play HERE SDK or application audio. If
NO, the application
AVAudioSession is not touched, and it is up to the application to configure the audio session for both its own and the HERE SDK audio.
managesAudioSession property is set to
NMAAudioManager continues to attempt to play audio output. However, the
AVAudioSession is not modified. Instead, you should configure
AVAudioSession to meet your own audio playback requirements. If you want to reconfigure
NMAAudioManager events, implement
NMAAudioManagerDelegate protocol methods.
Overriding Default Audio Playback Using NMAAudioManagerDelegate
Whether or not the
NMAAudioManager is set to automatically manage your application's HERE SDK audio session, you can choose to implement
NMAAudioManagerDelegate to listen for relevant audio output events and perform custom logic before using the audio output for playback.
NMAAudioManagerDelegatecontains the following methods:
audioManager:shouldPlayOutput:- This method is called when the audio manager has output to play. If you implement this method, you must return
NOto prevent audio playback, or return
YESand then call the
playOutput:method. You can use this to customize audio playback to some degree. For example, you can choose to configure
AVAudioSessionbefore playback, if you opted to manage the
audioManagerWillPlayOutput:- Callback that occurs just before the output is played by
audioManagerDidPlayOutput:- Callback that occurs after the output is played by
With iOS 8 or above devices, you can route
NMAAudioManager audio playback to the device speaker or Bluetooth peripherals, such as a headset or a car stereo, by using the
setAudioRoute: method before
playOutput: is called.
setAudioRoute:accepts the following
NMAAudioRoutevalues. The default audio route is
NMAAudioRouteDefault- Uses the default audio route as determined by the operating system. This audio route may represent connected wired headphones, connected A2DP Bluetooth devices, or the device speaker.
NMAAudioRouteDeviceSpeaker- Plays audio over the device speaker, even if headphones or other peripherals are connected.
NMAAudioRouteBluetoothHFP- Plays audio using Bluetooth the Hands-Free Profile (HFP).
If you set the audio route to
NMAAudioRouteBluetoothHFP, the HERE SDK attempts to play audio over the connected Bluetooth HFP device. If no device is connected,
NMAAudioManager automatically sets the audio route back to
NMAAudioRouteDefault. You can receive a notification for this fallback event by observing
You can retrieve the current audio route from
NMAAudioManager by using the