LiveSessionFutures

@PublicPreviewAPI
public abstract classLiveSessionFutures


Wrapper class providing Java compatible methods forLiveSession.

See also
LiveSession

Summary

Nested types

public static classLiveSessionFutures.Companion

Public methods

abstract @NonNullListenableFuture<Unit>

Closes the client session.

static final @NonNullLiveSessionFutures
abstract @NonNullPublisher<@NonNullLiveServerMessage>

Receives responses from the model for both streaming and standard requests.

abstract @NonNullListenableFuture<Unit>
send(@NonNullContent content)

Sendsdata to the model.

abstract @NonNullListenableFuture<Unit>

Sends text to the model.

abstract @NonNullListenableFuture<Unit>

Sends an audio input stream to the model, using the realtime API.

abstract @NonNullListenableFuture<Unit>

Sends function calling responses to the model.

abstract @NonNullListenableFuture<Unit>

This method is deprecated. Use `sendAudioRealtime`, `sendVideoRealtime`, or `sendTextRealtime` instead

abstract @NonNullListenableFuture<Unit>

For details about the realtime input usage, see theBidiGenerateContentRealtimeInput documentation (Gemini Developer API orVertex AI Gemini API ).

abstract @NonNullListenableFuture<Unit>

Sends a video input stream to the model, using the realtime API.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation()

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(boolean enableInterruptions)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    @NonNullLiveAudioConversationConfig liveAudioConversationConfig
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function2<TranscriptionTranscriptionUnit> transcriptHandler
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function2<TranscriptionTranscriptionUnit> transcriptHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler,
    Function2<TranscriptionTranscriptionUnit> transcriptHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

abstract @NonNullListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
stopAudioConversation()

Stops the audio conversation with the Gemini Server.

abstract void

Stops receiving from the model.

Public methods

close

public abstract @NonNullListenableFuture<Unitclose()

Closes the client session.

Once aLiveSession is closed, it can not be reopened; you'll need to start a newLiveSession.

from

public static final @NonNullLiveSessionFutures from(@NonNullLiveSession session)
Returns
@NonNullLiveSessionFutures

aLiveSessionFutures created around the providedLiveSession

receive

public abstract @NonNullPublisher<@NonNullLiveServerMessagereceive()

Receives responses from the model for both streaming and standard requests.

Callclose to stop receiving responses from the model.

Returns
@NonNullPublisher<@NonNullLiveServerMessage>

APublisher which will emitLiveServerMessage from the model.

Throws
com.google.firebase.ai.type.SessionAlreadyReceivingException com.google.firebase.ai.type.SessionAlreadyReceivingException

when the session is already receiving.

send

public abstract @NonNullListenableFuture<Unitsend(@NonNullContent content)

Sendsdata to the model.

Calling this afterstartAudioConversation will play the response audio immediately.

Parameters
@NonNullContent content

ClientContent to be sent to the model.

send

public abstract @NonNullListenableFuture<Unitsend(@NonNullString text)

Sends text to the model.

Calling this afterstartAudioConversation will play the response audio immediately.

Parameters
@NonNullString text

Text to be sent to the model.

sendAudioRealtime

public abstract @NonNullListenableFuture<UnitsendAudioRealtime(@NonNullInlineData audio)

Sends an audio input stream to the model, using the realtime API.

Parameters
@NonNullInlineData audio

The audio data to send.

sendFunctionResponse

public abstract @NonNullListenableFuture<UnitsendFunctionResponse(
    @NonNullList<@NonNullFunctionResponsePart> functionList
)

Sends function calling responses to the model.

Parameters
@NonNullList<@NonNullFunctionResponsePart> functionList

The list ofFunctionResponsePart instances indicating the function response from the client.

sendMediaStream

public abstract @NonNullListenableFuture<UnitsendMediaStream(@NonNullList<@NonNullMediaData> mediaChunks)
This method is deprecated.
Use `sendAudioRealtime`, `sendVideoRealtime`, or `sendTextRealtime` instead

Streams client data to the model.

Calling this afterstartAudioConversation will play the response audio immediately.

Parameters
@NonNullList<@NonNullMediaData> mediaChunks

The list ofMediaData instances representing the media data to be sent.

sendTextRealtime

public abstract @NonNullListenableFuture<UnitsendTextRealtime(@NonNullString text)

For details about the realtime input usage, see theBidiGenerateContentRealtimeInput documentation (Gemini Developer API orVertex AI Gemini API ).

Parameters
@NonNullString text

The text data to send.

sendVideoRealtime

public abstract @NonNullListenableFuture<UnitsendVideoRealtime(@NonNullInlineData video)

Sends a video input stream to the model, using the realtime API.

Parameters
@NonNullInlineData video

The video data to send. Video MIME type could be either video or image.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation()

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation(boolean enableInterruptions)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

Parameters
boolean enableInterruptions

If enabled, allows the user to speak over or interrupt the model's ongoing reply.

WARNING: The user interruption feature relies on device-specific support, and may not be consistently available.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation(
    Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

Parameters
Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler

A callback function that is invoked whenever the model receives a function call.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation(
    @NonNullLiveAudioConversationConfig liveAudioConversationConfig
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation.

Parameters
@NonNullLiveAudioConversationConfig liveAudioConversationConfig

ALiveAudioConversationConfig provided by the user to control the various aspects of the conversation.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation(
    Function2<TranscriptionTranscriptionUnit> transcriptHandler
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation.

Parameters
Function2<TranscriptionTranscriptionUnit> transcriptHandler

A callback function that is invoked whenever the model receives a transcript. The firstTranscription object is the input transcription, and the second is the output transcription

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation(
    Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

Parameters
Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler

A callback function that is invoked whenever the model receives a function call.

boolean enableInterruptions

If enabled, allows the user to speak over or interrupt the model's ongoing reply.

WARNING: The user interruption feature relies on device-specific support, and may not be consistently available.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation(
    Function2<TranscriptionTranscriptionUnit> transcriptHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

Parameters
Function2<TranscriptionTranscriptionUnit> transcriptHandler

A callback function that is invoked whenever the model receives a transcript. The firstTranscription object is the input transcription, and the second is the output transcription

boolean enableInterruptions

If enabled, allows the user to speak over or interrupt the model's ongoing reply.

WARNING: The user interruption feature relies on device-specific support, and may not be consistently available.

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstartAudioConversation(
    Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler,
    Function2<TranscriptionTranscriptionUnit> transcriptHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped usingstopAudioConversation orclose.

Parameters
Function1<@NonNullFunctionCallPart, @NonNullFunctionResponsePart> functionCallHandler

A callback function that is invoked whenever the model receives a function call.

Function2<TranscriptionTranscriptionUnit> transcriptHandler

A callback function that is invoked whenever the model receives a transcript. The firstTranscription object is the input transcription, and the second is the output transcription

boolean enableInterruptions

If enabled, allows the user to speak over or interrupt the model's ongoing reply.

WARNING: The user interruption feature relies on device-specific support, and may not be consistently available.

stopAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNullListenableFuture<UnitstopAudioConversation()

Stops the audio conversation with the Gemini Server.

This only needs to be called after a previous call tostartAudioConversation.

If there is no audio conversation currently active, this function does nothing.

stopReceiving

public abstract void stopReceiving()

Stops receiving from the model.

If this function is called during an ongoing audio conversation, the model's response will not be received, and no audio will be played; the live session object will no longer receive data from the server.

To resume receiving data, you must either handle it directly usingreceive, or indirectly by usingstartAudioConversation.

See also
close

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-11 UTC.