# Firebase.AI.LiveSession

Manages asynchronous communication with Gemini model over a WebSocket connection.

## Summary

Warning: This API is in Public Preview, which means that the feature is not subject to any SLA or deprecation policy and could change in backwards-incompatible ways.

### Inheritance

Inherits from: IDisposable

| ### Protected functions ||
|---|---|
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a278d1927b09ed231da5b7cd9ab062527(bool disposing)` | `virtual void` |

| ### Public functions ||
|---|---|
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a3f3e7e81c5b44e3d7e902594dc38603e(CancellationToken cancellationToken)` | `Task` Close the `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session`. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1aa8a0e611e516105fc2bef48673c24cff()` | `void` |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1aacedbd79d0cb1c39e6df6654c243e96f(CancellationToken cancellationToken)` | `async IAsyncEnumerable< https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/live-session-response#struct_firebase_1_1_a_i_1_1_live_session_response >` Receives a stream of responses from the server. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a38ee1d1b019bd7634b1849d2932ed9f1(https://firebase.google.com/docs/reference/unity/class/firebase/a-i/session-resumption-config#class_firebase_1_1_a_i_1_1_session_resumption_config sessionResumption, CancellationToken cancellationToken)` | `async Task` Resumes an existing live session with the server. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a8f64581b489c7ffad5e30a242cabdffa(https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/model-content#struct_firebase_1_1_a_i_1_1_model_content? content, bool turnComplete, CancellationToken cancellationToken)` | `async Task` Sends a single piece of content to the server. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a1fa43af8e9a84ea5022a493a30274bb4(float[] audioData, CancellationToken cancellationToken)` | `Task` Convenience function for sending audio data in a float\[\] to the server. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1af83aedfba2095ff47e9be54042f19635(https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/model-content/inline-data-part#struct_firebase_1_1_a_i_1_1_model_content_1_1_inline_data_part audio, CancellationToken cancellationToken)` | `async Task` Sends audio data to the server in realtime. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a02bbeb698a762b990b38c17012a7ffc3(CancellationToken cancellationToken)` | `async Task` Manually marks the start of user activity, using the realtime API. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a97c490e59ac4758ccebe9508851674ca(CancellationToken cancellationToken)` | `async Task` Manually marks the end of user activity, using the realtime API. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a2e4e32c4dc0f57e2c0bada4534da7b9d(string text, CancellationToken cancellationToken)` | `async Task` Sends text data to the server in realtime. |
| `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1af42e4167bcb7a2fe84dc2f8e2bb451b3(https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/model-content/inline-data-part#struct_firebase_1_1_a_i_1_1_model_content_1_1_inline_data_part video, CancellationToken cancellationToken)` | `async Task` Sends video data to the server in realtime. |

## Protected functions

### Dispose

```c#
virtual void Dispose(
  bool disposing
)
```

## Public functions

### CloseAsync

```c#
Task CloseAsync(
  CancellationToken cancellationToken
)
```
Close the `https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session`.

<br />

Details Parameters `cancellationToken` A token to cancel the operation.

### Dispose

```c#
void Dispose()
```

### ReceiveAsync

```c#
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.

<br />

Details Parameters `cancellationToken` A token to cancel the operation. **Returns** A stream of `LiveContentResponse`s from the backend.

### ResumeSessionAsync

```c#
async Task ResumeSessionAsync(
  SessionResumptionConfig sessionResumption,
  CancellationToken cancellationToken
)
```
Resumes an existing live session with the server.

This closes the current WebSocket connection and establishes a new one using the same configuration as the original session.

<br />

Details Parameters `sessionResumption` The configuration for session resumption. `cancellationToken` A token to cancel the operation.

### SendAsync

```c#
async Task SendAsync(
  ModelContent? content,
  bool turnComplete,
  CancellationToken cancellationToken
)
```
Sends a single piece of content to the server.

<br />

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

```c#
Task SendAudioAsync(
  float[] audioData,
  CancellationToken cancellationToken
)
```
Convenience function for sending audio data in a float\[\] to the server.

<br />

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

```c#
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.

<br />

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

### SendStartActivityRealtimeAsync

```c#
async Task SendStartActivityRealtimeAsync(
  CancellationToken cancellationToken
)
```
Manually marks the start of user activity, using the realtime API.

The start of user activity is effectively the start of a user's turn, but depending on the configuration defined in [RealtimeInputConfig](https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/realtime-input-config#struct_firebase_1_1_a_i_1_1_realtime_input_config), it may not be interpreted as an interruption. An example of the start of user activity could be the user speaking (not silence).

Should be followed with a call to [SendStopActivityRealtimeAsync(CancellationToken)](https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a97c490e59ac4758ccebe9508851674ca); after all the data has been sent for the user's turn.

Only required when automatic activity detection is disabled via `https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/activity-detection-config#struct_firebase_1_1_a_i_1_1_activity_detection_config_1a0e9447938449334642831d938782aa1f`.

### SendStopActivityRealtimeAsync

```c#
async Task SendStopActivityRealtimeAsync(
  CancellationToken cancellationToken
)
```
Manually marks the end of user activity, using the realtime API.

The end of user activity is effectively the end of a user's turn, and signals that the model can start sending responses.

Should follow after a previous call to [SendStartActivityRealtimeAsync(CancellationToken)](https://firebase.google.com/docs/reference/unity/class/firebase/a-i/live-session#class_firebase_1_1_a_i_1_1_live_session_1a02bbeb698a762b990b38c17012a7ffc3).

Only required when automatic activity detection is disabled via `https://firebase.google.com/docs/reference/unity/struct/firebase/a-i/activity-detection-config#struct_firebase_1_1_a_i_1_1_activity_detection_config_1a0e9447938449334642831d938782aa1f`.

### SendTextRealtimeAsync

```c#
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.

<br />

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

### SendVideoRealtimeAsync

```c#
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.

<br />

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