kirad.feature_extraction_whisper¶
kirad.feature_extraction_whisper
¶
Model stage: raw audio windows -> Whisper log-mel features, computed on the GPU in torch.
Used only by DAM 1 (mar_2024 model.forward_backbone); DAM 2/3 get log-mel from the HF extractor in KintsugiAudioDataset.
Feature extractor class for Whisper in native torch code. Modified from
transformers.models.whisper.feature_extraction_whisper.
WhisperTorchFeatureExtractor
¶
Bases: Module
Torch Whisper log-mel extractor: 80 bins, 25 ms window, 10 ms hop, 16 kHz.
Also applies per-window audio normalization and the IDEAL_LOGMEL_ENERGIES profile. Shapes: [ΣW, 480000] -> [ΣW, 80, 3000].
Constructs a Whisper feature extractor.
Args:
feature_size (int, optional, defaults to 80):
The feature dimension of the extracted features.
hop_length (int, optional, defaults to 160):
Length of the overlapping windows for the STFT used to obtain the Mel Frequency coefficients.
n_fft (int, optional, defaults to 400):
Size of the Fourier transform.
dither (float, optional, defaults to 0.0):
Adds dithering. In other words, adds a small Gaussian noise to each frame.
E.g. use 0.0001 to add dithering with a normal distribution centered
around 0.0 with standard deviation 0.0001 (assuming [-1,+1] range of raw_speech).
The value 0.0 means no dithering.
Dithering has similar effect as spectrogram(mel_floor=...). It reduces
the high log_mel_fbank values for signals with hard-zero sections,
when VAD cutoff is present in the signal.
ideal_logmel_energies (bool, optional, defaults to True):
Whether to use ideal_logmel_energies normalization
device (str, optional, defaults to 'cpu'):
Specifies the device for computation of the log-mel spectrogram of audio signals in the
_torch_extract_fbank_features method. (e.g., "cpu", "cuda")
Source code in kirad/feature_extraction_whisper.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |
n_fft = n_fft
instance-attribute
¶
hop_length = hop_length
instance-attribute
¶
dither = dither
instance-attribute
¶
normalize_audio = normalize_audio
instance-attribute
¶
ideal_logmel_energies = ideal_logmel_energies
instance-attribute
¶
window = torch.hann_window(self.n_fft)
instance-attribute
¶
mel_filters = torch.from_numpy(mel_filter_bank(num_frequency_bins=1 + n_fft // 2, num_mel_filters=feature_size, min_frequency=0.0, max_frequency=8000.0, sampling_rate=16000, norm='slaney', mel_scale='slaney'))
instance-attribute
¶
__init__(feature_size=80, hop_length=160, n_fft=400, dither=0.0, normalize_audio=True, ideal_logmel_energies=True)
¶
Precompute Hann window and Slaney mel filters; register the energy profile.
Source code in kirad/feature_extraction_whisper.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | |
forward(batched_speech)
¶
Normalize each window, compute log-mel, shift bins to IDEAL_LOGMEL_ENERGIES.
normalize_audio: zero mean, unit variance per window (in float64). ideal_logmel_energies: add (target - time-mean) per bin. Shapes: [ΣW, 480000] -> [ΣW, 80, 3000], returned in the input dtype.
Compute mel filter bank features from a batch x samples tensor of audio.
Source code in kirad/feature_extraction_whisper.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 | |