Schema
[BETA] Modules concerning the schema for the realtime session.
RealtimeActivityType
Bases: StrEnum
[BETA] Defines common realtime activity types of the realtime session.
RealtimeDataType
Bases: StrEnum
[BETA] Defines the data types for the realtime session.
RealtimeEvent
Bases: BaseModel
[BETA] Defines the realtime event schemas for the realtime session.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
RealtimeEventType
|
The type of the event. |
data |
str | bytes
|
The data of the event. |
data_type |
RealtimeDataType
|
The data type of the event. |
metadata |
dict[str, Any]
|
The metadata of the event. |
activity(activity, metadata=None)
classmethod
Create an activity event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activity
|
str
|
The activity of the event. |
required |
metadata
|
dict[str, Any]
|
The metadata of the event. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEvent |
RealtimeEvent
|
The activity event. |
input_audio(audio, metadata=None)
classmethod
Create an input audio event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
bytes
|
The audio of the event. |
required |
metadata
|
dict[str, Any]
|
The metadata of the event. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEvent |
RealtimeEvent
|
The input audio event. |
input_image(image, metadata=None)
classmethod
Create an input image event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
bytes
|
The image of the event. |
required |
metadata
|
dict[str, Any]
|
The metadata of the event. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEvent |
RealtimeEvent
|
The input image event. |
input_text(text, metadata=None)
classmethod
Create an input text event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text of the event. |
required |
metadata
|
dict[str, Any]
|
The metadata of the event. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEvent |
RealtimeEvent
|
The input text event. |
output_audio(audio, metadata=None)
classmethod
Create an output audio event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
bytes
|
The audio of the event. |
required |
metadata
|
dict[str, Any]
|
The metadata of the event. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEvent |
RealtimeEvent
|
The output audio event. |
output_image(image, metadata=None)
classmethod
Create an output image event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
bytes
|
The image of the event. |
required |
metadata
|
dict[str, Any]
|
The metadata of the event. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEvent |
RealtimeEvent
|
The output image event. |
output_text(text, metadata=None)
classmethod
Create an output text event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text of the event. |
required |
metadata
|
dict[str, Any]
|
The metadata of the event. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEvent |
RealtimeEvent
|
The output text event. |
RealtimeEventType
Bases: StrEnum
[BETA] Defines the event types for the realtime session.
RealtimeState
Bases: BaseModel
[BETA] Defines the realtime state of the realtime session module with thread-safe properties.
Attributes:
| Name | Type | Description |
|---|---|---|
interruption |
bool
|
Whether an interruption is active, causing non-activity events to be filtered. |
console_mode |
RealtimeEventType
|
The currently active console mode. |
get_console_mode()
async
Thread-safe getter for console_mode.
Returns:
| Name | Type | Description |
|---|---|---|
RealtimeEventType |
RealtimeEventType
|
The value of console_mode. |
get_interruption()
async
Thread-safe getter for interruption.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
The value of interruption. |
get_terminated()
Get termination state.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if terminated, False otherwise. |
set_console_mode(value)
async
Thread-safe setter for console_mode.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
RealtimeEventType
|
The value to set for console_mode. |
required |
set_interruption(value)
async
Thread-safe setter for interruption.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
The value to set for interruption. |
required |
set_terminated()
Set termination state.
Sets the termination event. This is thread-safe as asyncio.Event operations are inherently thread-safe.
wait_terminated()
async
Wait for termination to be signaled.
This method blocks until termination is set to True, providing instant notification.