Integrate with the Gemini Live API for audio glasses and display glasses

Applicable XR devices
This guidance helps you build experiences for these types of XR devices.
Audio &
Display Glasses

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.ogg earcon with SoundPool (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 calling connect.
  • Adapt to displayless hardware: Inspect ProjectedDeviceController.capabilities for CAPABILITY_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:

  1. Arm a coroutine timer: Start the timer when launching connect, reconnecting, or running a slow tool call.
  2. Delay the first loading cue: Wait 1,700 ms before playing the generic app_loading.ogg earcon so fast responses stay quiet.
  3. 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.
  4. Disarm on first response: Cancel the timer as soon as model audio starts playing, after connect completes if your app waits passively with no opening prompt (or when LiveServerSetupComplete arrives from LiveSession.receive), when a turn completes, or when the activity pauses or disconnects. Call stop on local TextToSpeech before 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 AudioManager and AudioFocusRequest using USAGE_MEDIA or USAGE_ASSISTANT with CONTENT_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 with ProjectedContext.createHostDeviceContext. Route microphone input over Bluetooth HFP. When calling LiveSession.startAudioConversation, pass a LiveAudioConversationConfig to configure AudioRecord.Builder and AudioTrack.Builder in initializationHandler, enable enableInterruptions, and handle disconnect notices in goAwayHandler.
  • 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 stopAudioConversation or close on the LiveSession when the projected activity stops or the glasses disconnect.
  • Mask slow function calls: Wrap network or hardware tool calls inside your functionCallHandler with 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.