LiveSessionFutures

@PublicPreviewAPI
public abstract class LiveSessionFutures


Wrapper class providing Java compatible methods for LiveSession.

See also
LiveSession

Summary

Nested types

public static class LiveSessionFutures.Companion

Public methods

abstract @NonNull ListenableFuture<Unit>

Closes the client session.

static final @NonNull LiveSessionFutures
abstract @NonNull Publisher<@NonNull LiveServerMessage>

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

abstract @NonNull ListenableFuture<Unit>
send(@NonNull Content content)

Sends data to the model.

abstract @NonNull ListenableFuture<Unit>

Sends text to the model.

abstract @NonNull ListenableFuture<Unit>

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

abstract @NonNull ListenableFuture<Unit>

Sends function calling responses to the model.

abstract @NonNull ListenableFuture<Unit>

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

abstract @NonNull ListenableFuture<Unit>

Sends text data to the server in realtime.

abstract @NonNull ListenableFuture<Unit>

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

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

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

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

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

abstract @NonNull ListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

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

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

abstract @NonNull ListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

abstract @NonNull ListenableFuture<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 using stopAudioConversation or close.

abstract @NonNull ListenableFuture<Unit>
@RequiresPermission(value = "android.permission.RECORD_AUDIO")
startAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler,
    Function2<TranscriptionTranscriptionUnit> transcriptHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

abstract @NonNull ListenableFuture<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 @NonNull ListenableFuture<Unitclose()

Closes the client session.

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

See also
stopReceiving

from

public static final @NonNull LiveSessionFutures from(@NonNull LiveSession session)
Returns
@NonNull LiveSessionFutures

a LiveSessionFutures created around the provided LiveSession

receive

public abstract @NonNull Publisher<@NonNull LiveServerMessagereceive()

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

Call close to stop receiving responses from the model.

Returns
@NonNull Publisher<@NonNull LiveServerMessage>

A Publisher which will emit LiveServerMessage from the model.

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

when the session is already receiving.

See also
stopReceiving

send

public abstract @NonNull ListenableFuture<Unitsend(@NonNull Content content)

Sends data to the model.

Calling this after startAudioConversation will play the response audio immediately.

Parameters
@NonNull Content content

Client Content to be sent to the model.

send

public abstract @NonNull ListenableFuture<Unitsend(@NonNull String text)

Sends text to the model.

Calling this after startAudioConversation will play the response audio immediately.

Parameters
@NonNull String text

Text to be sent to the model.

sendAudioRealtime

public abstract @NonNull ListenableFuture<UnitsendAudioRealtime(@NonNull InlineData audio)

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

Parameters
@NonNull InlineData audio

The audio data to send.

sendFunctionResponse

public abstract @NonNull ListenableFuture<UnitsendFunctionResponse(
    @NonNull List<@NonNull FunctionResponsePart> functionList
)

Sends function calling responses to the model.

Parameters
@NonNull List<@NonNull FunctionResponsePart> functionList

The list of FunctionResponsePart instances indicating the function response from the client.

sendMediaStream

public abstract @NonNull ListenableFuture<UnitsendMediaStream(@NonNull List<@NonNull MediaData> mediaChunks)

Streams client data to the model.

Calling this after startAudioConversation will play the response audio immediately.

Parameters
@NonNull List<@NonNull MediaData> mediaChunks

The list of MediaData instances representing the media data to be sent.

sendTextRealtime

public abstract @NonNull ListenableFuture<UnitsendTextRealtime(@NonNull String text)

Sends text data to the server in realtime. Check https://ai.google.dev/api/live#bidigeneratecontentrealtimeinput for details about the realtime input usage.

Parameters
@NonNull String text

The text data to send.

sendVideoRealtime

public abstract @NonNull ListenableFuture<UnitsendVideoRealtime(@NonNull InlineData video)

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

Parameters
@NonNull InlineData video

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

startAudioConversation

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

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

startAudioConversation

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

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

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 @NonNull ListenableFuture<UnitstartAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

Parameters
Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler

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

startAudioConversation

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

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

Parameters
Function2<TranscriptionTranscriptionUnit> transcriptHandler

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

startAudioConversation

@RequiresPermission(value = "android.permission.RECORD_AUDIO")
public abstract @NonNull ListenableFuture<UnitstartAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

Parameters
Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> 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 @NonNull ListenableFuture<UnitstartAudioConversation(
    Function2<TranscriptionTranscriptionUnit> transcriptHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

Parameters
Function2<TranscriptionTranscriptionUnit> transcriptHandler

A callback function that is invoked whenever the model receives a transcript. The first Transcription 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 @NonNull ListenableFuture<UnitstartAudioConversation(
    Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> functionCallHandler,
    Function2<TranscriptionTranscriptionUnit> transcriptHandler,
    boolean enableInterruptions
)

Starts an audio conversation with the model, which can only be stopped using stopAudioConversation or close.

Parameters
Function1<@NonNull FunctionCallPart, @NonNull FunctionResponsePart> 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 first Transcription 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 @NonNull ListenableFuture<UnitstopAudioConversation()

Stops the audio conversation with the Gemini Server.

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

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 using receive, or indirectly by using startAudioConversation.

See also
close