Firebase.AI.LiveSession

Manages asynchronous communication with Gemini model over a WebSocket connection.

Summary

Inheritance

Inherits from: IDisposable

Protected functions

Dispose(bool disposing)
virtual void

Public functions

CloseAsync(CancellationToken cancellationToken)
Task
Close the LiveSession.
Dispose()
void
ReceiveAsync(CancellationToken cancellationToken)
async IAsyncEnumerable< LiveSessionResponse >
Receives a stream of responses from the server.
SendAsync(ModelContent? content, bool turnComplete, CancellationToken cancellationToken)
async Task
Sends a single piece of content to the server.
SendAudioAsync(float[] audioData, CancellationToken cancellationToken)
Task
Convenience function for sending audio data in a float[] to the server.
SendMediaChunksAsync(List< ModelContent.InlineDataPart > mediaChunks, CancellationToken cancellationToken)
async Task
Send realtime input to the server.

Protected functions

Dispose

virtual void Dispose(
  bool disposing
)

Public functions

CloseAsync

Task CloseAsync(
  CancellationToken cancellationToken
)

Close the LiveSession.

Details
Parameters
cancellationToken
A token to cancel the operation.

Dispose

void Dispose()

ReceiveAsync

async IAsyncEnumerable< LiveSessionResponse > ReceiveAsync(
  CancellationToken cancellationToken
)

Receives a stream of responses from the server.

Having multiple of these ongoing will result in unexpected behavior. Closes upon receiving a TurnComplete from the server.

Details
Parameters
cancellationToken
A token to cancel the operation.
Returns
A stream of LiveContentResponses from the backend.

SendAsync

async Task SendAsync(
  ModelContent? content,
  bool turnComplete,
  CancellationToken cancellationToken
)

Sends a single piece of content to the server.

Details
Parameters
content
The content to send.
turnComplete
Indicates to the server that the client's turn is complete.
cancellationToken
A token to cancel the send operation.

SendAudioAsync

Task SendAudioAsync(
  float[] audioData,
  CancellationToken cancellationToken
)

Convenience function for sending audio data in a float[] to the server.

Details
Parameters
audioData
The audio data to send. Expected format: 16 bit PCM audio at 16kHz little-endian.
cancellationToken
A token to cancel the send operation.

SendMediaChunksAsync

async Task SendMediaChunksAsync(
  List< ModelContent.InlineDataPart > mediaChunks,
  CancellationToken cancellationToken
)

Send realtime input to the server.

Details
Parameters
mediaChunks
A list of media chunks to send.
cancellationToken
A token to cancel the send operation.