AudioContent Class
Audio Content class.
This can be created either the bytes data or a data uri, additionally it can have a uri. The uri is a reference to the source, and might or might not point to the same thing as the data.
Use the .from_audio_file method to create an instance from an audio file. This reads the file and guesses the mime_type.
If both data_uri and data is provided, data will be used and a warning is logged.
Args: uri (Url | None): The reference uri of the content. data_uri (DataUrl | None): The data uri of the content. data (str | bytes | None): The data of the content. data_format (str | None): The format of the data (e.g. base64). mime_type (str | None): The mime type of the audio, only used with data. kwargs (Any): Any additional arguments:
inner_content (Any): The inner content of the response,
this should hold all the information from the response so even
when not creating a subclass a developer can leverage the full thing.
ai_model_id (str | None): The id of the AI model that generated this response.
metadata (dict[str, Any]): Any metadata that should be attached to the response.
Note: This class is marked as 'experimental' and may change in the future.
Create an Audio Content object, either from a data_uri or data.
Constructor
AudioContent(uri: str | None = None, data_uri: str | None = None, data: str | bytes | ndarray | None = None, data_format: str | None = None, mime_type: str | None = None, *, inner_content: Any | None = None, ai_model_id: str | None = None, metadata: dict[str, Any] = None, content_type: Literal[ContentTypes.AUDIO_CONTENT] = 'audio')
Parameters
| Name | Description |
|---|---|
|
uri
|
The reference uri of the content. Default value: None
|
|
data_uri
|
The data uri of the content. Default value: None
|
|
data
|
The data of the content. Default value: None
|
|
data_format
|
The format of the data (e.g. base64). Default value: None
|
|
mime_type
|
The mime type of the audio, only used with data. Default value: None
|
|
kwargs
Required
|
Any additional arguments: inner_content: The inner content of the response, this should hold all the information from the response so even when not creating a subclass a developer can leverage the full thing. ai_model_id: The id of the AI model that generated this response. metadata: Any metadata that should be attached to the response. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
inner_content
Required
|
|
|
ai_model_id
Required
|
|
|
metadata
Required
|
|
|
content_type
|
Default value: audio
|
Methods
| from_audio_file |
Create an instance from an audio file. |
| model_post_init |
We need to both initialize private attributes and call the user-defined model_post_init method. |
| to_dict |
Convert the instance to a dictionary. |
from_audio_file
Create an instance from an audio file.
from_audio_file(path: str) -> AudioContent
Parameters
| Name | Description |
|---|---|
|
path
Required
|
|
model_post_init
We need to both initialize private attributes and call the user-defined model_post_init method.
model_post_init(context: Any, /) -> None
Positional-Only Parameters
| Name | Description |
|---|---|
|
context
Required
|
|
to_dict
Convert the instance to a dictionary.
to_dict() -> dict[str, Any]
Attributes
ai_model_id
ai_model_id: str | None
content_type
content_type: Literal[ContentTypes.AUDIO_CONTENT]
inner_content
inner_content: Annotated[Any | None, Field(exclude=True)]
is_experimental
is_experimental = True
metadata
metadata: dict[str, Any]
stage_status
stage_status = 'experimental'
tag
tag: ClassVar[str] = 'audio'
uri
uri: Url | str | None