tiny-voca-da / recipe /kit-v3 /asr_preprocessing.py
inlanger's picture
tiny-voca-da v0.1: frontend v4 + sm9 vocoder (ONNX fp32/int8, PyTorch, frontend, recipe, samples)
adabee1 verified
Raw History Blame Contribute Delete
1.18 kB
"""Shared Whisper waveform preprocessing for reproducible Danish ASR scores.
Short audio must be padded in waveform space before log-mel extraction. Padding
an already computed spectrogram with zero does not represent acoustic silence.
``truncation=False`` keeps all samples of inputs longer than the 30 s window.
Reference: Transformers 4.57.1 WhisperFeatureExtractor and short-form example:
https://huggingface.co/docs/transformers/v4.57.1/en/model_doc/whisper
"""
PREPROCESSING_VERSION = "whisper-waveform-pad-v2"
PREPROCESSING_SETTINGS = {
"version": PREPROCESSING_VERSION,
"sample_rate": 16000,
"padding": "max_length",
"truncation": False,
"return_attention_mask": True,
"description": "Pad short raw waveforms to the model window before log-mel extraction; retain full long audio.",
}
def prepare_whisper_input(processor, waveform):
"""Prepare one mono 16 kHz waveform; accepts a processor or feature extractor."""
return processor(
waveform,
sampling_rate=PREPROCESSING_SETTINGS["sample_rate"],
return_tensors="pt",
truncation=False,
padding="max_length",
return_attention_mask=True,
)