BiGRU_T_version / src /bigru_t /multimodal /audio_encoder.py
PowerMachine's picture
Upload folder using huggingface_hub
3275441 verified
Raw History Blame Contribute Delete
987 Bytes
"""Xavante - audio_encoder.py - Encoder de audio (estilo Whisper leve)."""
from __future__ import annotations
import logging
import torch
import torch.nn as nn
logger = logging.getLogger(__name__)
class AudioEncoder(nn.Module):
"""Convolucoes 1D + Linear para audio bruto ou mel-spec."""
def __init__(self, d_model: int = 512, in_channels: int = 1, n_mels: int = 80):
super().__init__()
in_ch = in_channels if in_channels > 1 else n_mels
self.conv = nn.Sequential(
nn.Conv1d(in_ch, 64, 5, 2, 2),
nn.GELU(),
nn.Conv1d(64, 128, 5, 2, 2),
nn.GELU(),
nn.Conv1d(128, 256, 5, 2, 2),
nn.GELU(),
nn.AdaptiveAvgPool1d(1),
)
self.proj = nn.Linear(256, d_model)
def forward(self, x: torch.Tensor) -> torch.Tensor:
# x: [B, C, T] ou [B, n_mels, T]
feat = self.conv(x).squeeze(-1)
return self.proj(feat)
__all__ = ["AudioEncoder"]