Download recipe/kit-v3/asr_preprocessing.py from gowombat/tiny-voca-da: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/gowombat/tiny-voca-da/resolve/main/recipe/kit-v3/asr_preprocessing.py
- Command line
-
hf download hf://gowombat/tiny-voca-da/recipe/kit-v3/asr_preprocessing.py
-
curl -L -o asr_preprocessing.py https://huggingface.co/gowombat/tiny-voca-da/resolve/main/recipe/kit-v3/asr_preprocessing.py
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, | |
| ) | |