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.
SendAudioRealtimeAsync(ModelContent.InlineDataPart audio, CancellationToken cancellationToken)
async Task
Sends audio data to the server in realtime.
SendMediaChunksAsync(List< ModelContent.InlineDataPart > mediaChunks, CancellationToken cancellationToken)
async Task
Deprecated. Use SendAudioRealtimeAsync, SendVideoRealtimeAsync, or SendTextRealtimeAsync instead.
Send realtime input to the server.
SendTextRealtimeAsync(string text, CancellationToken cancellationToken)
async Task
Sends text data to the server in realtime.
SendVideoRealtimeAsync(ModelContent.InlineDataPart video, CancellationToken cancellationToken)
async Task
Sends video data to the server in realtime.

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.

SendAudioRealtimeAsync

async Task SendAudioRealtimeAsync(
  ModelContent.InlineDataPart audio,
  CancellationToken cancellationToken
)

Sends audio data to the server in realtime.

Check https://ai.google.dev/api/live#bidigeneratecontentrealtimeinput for details about the realtime input usage.

Details
Parameters
audio
The audio data to send.
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.

Use SendAudioRealtimeAsync, SendVideoRealtimeAsync, or SendTextRealtimeAsync instead.

Deprecated. Use SendAudioRealtimeAsync, SendVideoRealtimeAsync, or SendTextRealtimeAsync instead.

SendTextRealtimeAsync

async Task SendTextRealtimeAsync(
  string text,
  CancellationToken cancellationToken
)

Sends text data to the server in realtime.

Check https://ai.google.dev/api/live#bidigeneratecontentrealtimeinput for details about the realtime input usage.

Details
Parameters
text
The text data to send.
cancellationToken
A token to cancel the send operation.

SendVideoRealtimeAsync

async Task SendVideoRealtimeAsync(
  ModelContent.InlineDataPart video,
  CancellationToken cancellationToken
)

Sends video data to the server in realtime.

Check https://ai.google.dev/api/live#bidigeneratecontentrealtimeinput for details about the realtime input usage.

Details
Parameters
video
The video data to send.
cancellationToken
A token to cancel the send operation.