The Gemini Live API provides a conversational audio interface for your app. On Android XR, you integrate with the Gemini Live API through Firebase AI Logic. Unlike combining Text to Speech (TTS) with Automatic Speech Recognition (ASR), the Gemini Live API handles both audio input and output over a single bidirectional connection. The API requires a persistent internet connection, incurs usage cost, and supports a limited number of concurrent connections per project. Because audio glasses have no display, provide immediate audio feedback on launch and use local TTS when a connection stalls or fails.
In addition to supporting audio interfaces, you can also use the Gemini Live API to build agentic experiences.
To get started with the Gemini Live API, follow the steps in the
Gemini Live API guide. It walks you through instantiating and configuring a
LiveGenerativeModel, establishing a
LiveSession, and creating custom
FunctionDeclaration instances that let your app process
requests from Gemini.
Confirm app launch immediately
When a user launches your app by voice through Gemini, Gemini stops its own audio feedback during handoff. Several seconds of silence after handoff make users assume the app failed to start. Newly launched projected activities also receive only a brief OS grace period to start an active audio, microphone, or camera stream and establish user awareness before the system stops and backgrounds them.
To confirm launch right away on audio glasses and display glasses:
- Play an earcon or greeting immediately: Play the generic
app_open.oggearcon withSoundPool(or speak a short greeting for conversational apps) as soon as your projected activity resumes. Trigger this cue before starting asynchronous initialization, such as reading API keys, initializing TTS, binding the camera, or callingconnect. - Adapt to displayless hardware: Inspect
ProjectedDeviceController.capabilitiesforCAPABILITY_VISUAL_UI. When that capability is missing on audio glasses, skip visual UI work and never rely on on-screen status cues. On display glasses, monitor display state changes because the display can turn off mid-conversation. - Follow sound design conventions: Use earcons for app open and loading states. Don't play exit earcons. Instead, end with an optional spoken wrap-up if needed, as described in Earcons.
Preload short earcons in onCreate with SoundPool and play the launch
sound when it finishes decoding if the activity resumes first:
import android.content.Context
import android.media.AudioAttributes
import android.media.SoundPool
class LaunchEarconPlayer(context: Context) {
private val soundPool = SoundPool.Builder()
.setMaxStreams(2)
.setAudioAttributes(
AudioAttributes.Builder()
.setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.build()
)
.build()
private val appOpenId: Int
private val appLoadingId: Int
private val loadedIds = mutableSetOf<Int>()
private var pendingOpenPlay = false
init {
soundPool.setOnLoadCompleteListener { _, sampleId, status ->
if (status == 0) {
loadedIds.add(sampleId)
if (sampleId == appOpenId && pendingOpenPlay) {
pendingOpenPlay = false
soundPool.play(sampleId, 1f, 1f, 1, 0, 1f)
}
}
}
appOpenId = soundPool.load(context, R.raw.app_open, 1)
appLoadingId = soundPool.load(context, R.raw.app_loading, 1)
}
fun playAppOpen() {
if (appOpenId in loadedIds) {
soundPool.play(appOpenId, 1f, 1f, 1, 0, 1f)
} else {
pendingOpenPlay = true
}
}
fun playLoading() {
if (appLoadingId in loadedIds) {
soundPool.play(appLoadingId, 1f, 1f, 1, 0, 1f)
}
}
fun release() {
soundPool.release()
}
}
Play playAppOpen once on launch in onResume before starting asynchronous
setup, and call release in onDestroy.
Mask latency longer than 1.7 seconds
After about 1.7 seconds of silence on audio glasses, users start to wonder
whether the app stalled. Mask noticeable delays during connect, session
resumption, and slow function calls:
- Arm a coroutine timer: Start the timer when launching
connect, reconnecting, or running a slow tool call. - Delay the first loading cue: Wait
1,700 msbefore playing the genericapp_loading.oggearcon so fast responses stay quiet. - Pulse and escalate: Repeat the loading cue at spaced intervals (for
example, every 2.2 seconds up to 3 pulses). If the wait continues past the
limit, speak a brief voice alert (such as
"Still connecting.") or report an error cleanly. - Disarm on first response: Cancel the timer as soon as model audio
starts playing, after
connectcompletes if your app waits passively with no opening prompt (or whenLiveServerSetupCompletearrives fromLiveSession.receive), when a turn completes, or when the activity pauses or disconnects. Callstopon localTextToSpeechbefore model audio starts so voices don't overlap.
The following example implements a bounded coroutine timer for latency masking:
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
class LatencyMasker(
private val scope: CoroutineScope,
private val playLoadingEarcon: () -> Unit,
private val initialDelayMs: Long = 1_700L,
private val repeatIntervalMs: Long = 2_200L,
private val maxPulses: Int = 3,
) {
private var job: Job? = null
fun arm(onEscalation: (() -> Unit)? = null) {
job?.cancel()
job = scope.launch {
delay(initialDelayMs)
repeat(maxPulses) { index ->
playLoadingEarcon()
if (index < maxPulses - 1) {
delay(repeatIntervalMs)
}
}
delay(repeatIntervalMs)
onEscalation?.invoke()
}
}
fun disarm() {
job?.cancel()
job = null
}
}
Reduce cold-start and response latency
Trim work off the launch path and configure the audio pipeline so the model responds sooner:
- Defer camera setup until needed: Don't initialize CameraX on the
critical startup path. Capture frames on demand or stream video at a low
frame rate (such as 1 FPS with
sendVideoRealtime) only when the user asks a visual question. Deferring camera activation also avoids triggering the three-second camera stream countdown during launch. - Request audio focus and route Bluetooth audio: Request
audio focus with
AudioManagerandAudioFocusRequestusingUSAGE_MEDIAorUSAGE_ASSISTANTwithCONTENT_TYPE_SPEECH. This pauses concurrent phone media cleanly and routes physical input to your activity, as described in Audio focus and concurrency. When coordinating focus with host media sessions from a projected activity, resolve the host context withProjectedContext.createHostDeviceContext. Route microphone input over Bluetooth HFP. When callingLiveSession.startAudioConversation, pass aLiveAudioConversationConfigto configureAudioRecord.BuilderandAudioTrack.BuilderininitializationHandler, enableenableInterruptions, and handle disconnect notices ingoAwayHandler. - Keep spoken responses concise and clean up on stop: Guide the model
through its system instruction to give short, direct spoken answers suited
for audio playback. Call
stopAudioConversationorcloseon theLiveSessionwhen the projected activity stops or the glasses disconnect. - Mask slow function calls: Wrap network or hardware tool calls inside
your
functionCallHandlerwith the 1.7-second latency masker so the user hears progress feedback if tool execution takes longer than 1.7 seconds.
Handle errors and offline states with local TTS
Because the Gemini Live API requires an active internet connection and enforces
concurrent session limits, audio glasses apps must never fail silently. Play the
generic announcement_alert.ogg earcon followed by a short local
TextToSpeech message (following voice alert guidelines) when the
device is offline, when connect fails, or when the server sends a
LiveServerGoAway disconnect notice.
Related guides
- Build audio interactions for audio glasses and display glasses
- Handle audio output for audio glasses and display glasses using Text to Speech
- Understand physical input routing for audio glasses
- Earcons
- Voice alerts