pyrit.models.DataTypeSerializer#
- class DataTypeSerializer[source]#
Bases:
ABC
Abstract base class for data type normalizers.
Responsible for reading and saving multi-modal data types to local disk or Azure Storage Account.
- __init__()#
Methods
__init__
()Returns True if the data is stored on disk.
Generates or retrieves a unique filename for the data file.
get_extension
(file_path)Get the file extension from the file path.
get_mime_type
(file_path)Get the MIME type of the file path.
Reads the data from the storage.
Reads the data from the storage.
save_b64_image
(data[, output_filename])Saves the base64 encoded image to storage.
save_data
(data)Saves the data to storage.
save_formatted_audio
(data[, ...])Saves the PCM16 of other specially formatted audio data to storage.
Attributes
- async get_data_filename() Path | str [source]#
Generates or retrieves a unique filename for the data file.
- static get_extension(file_path: str) str | None [source]#
Get the file extension from the file path.
- async read_data() bytes [source]#
Reads the data from the storage.
- Returns:
The data read from storage.
- Return type:
- async save_b64_image(data: str, output_filename: str = None) None [source]#
Saves the base64 encoded image to storage. :param data: string with base64 data :param output_filename: filename to store image as. Defaults to UUID if not provided :type output_filename: optional, str
- async save_formatted_audio(data: bytes, output_filename: str = None, num_channels: int = 1, sample_width: int = 2, sample_rate: int = 16000) None [source]#
Saves the PCM16 of other specially formatted audio data to storage. :param data: bytes with audio data :param output_filename: filename to store audio as. Defaults to UUID if not provided :type output_filename: optional, str :param num_channels: number of channels in audio data. Defaults to 1 :type num_channels: optional, int :param sample_width: sample width in bytes. Defaults to 2 :type sample_width: optional, int :param sample_rate: sample rate in Hz. Defaults to 16000 :type sample_rate: optional, int