from pydantic import BaseModel, Field
from src.audiochunk import AudioBinary

class AudioBinary_Config(BaseModel):
    """二进制音频块配置信息"""
    audio_data: bytes = Field(description="音频数据", default=None)
    chunk_size: int = Field(description="块大小", default=100)
    chunk_stride: int = Field(description="块步长", default=1600)
    sample_rate: int = Field(description="采样率", default=16000)
    sample_width: int = Field(description="采样位宽", default=2)
    channels: int = Field(description="通道数", default=1)

    # 从Dict中加载
    @classmethod
    def AudioBinary_Config_from_dict(cls, data: dict):
        return cls(**data)

class AudioBinary_Slice(BaseModel):
    """音频块切片"""
    target_Binary: AudioBinary = Field(description="目标音频块", default=None)
    start_index: int = Field(description="开始位置", default=0)
    end_index: int = Field(description="结束位置", default=0)

    def __call__(self):
        return self.target_Binary(self.start_index, self.end_index)

class _AudioBinary_data(BaseModel):
    """音频二进制数据"""
    binary_data: bytes = Field(description="音频二进制数据", default=None)

class AudioBinary_data_list(BaseModel):
    """音频二进制数据列表"""
    binary_data_list: List[_AudioBinary_data] = Field(description="音频二进制数据列表", default=[])

    def __call__(self):
        return self.binary_data_list
