mstar.model.components.audio_features#
Whisper-family log-mel front end, in torch.
Whisper, Qwen3-ASR’s AuT and the Higgs audio tower all consume the same
features: a 16 kHz waveform, 25 ms Hann-windowed STFT at a 10 ms hop, a
Slaney-scaled mel filterbank (80 or 128 bins), log10, an 8-unit dynamic
range clamp under the clip’s maximum, then (x + 4) / 4. This module
reproduces HF’s WhisperFeatureExtractor torch path to ~1e-5 so a
natively served encoder sees the features its HF oracle was tested with,
without transformers in the serving path. It runs wherever the waveform
is, on the CPU of the API-server data worker or on the GPU inside an
encoder’s forward (every op is fixed-shape for a fixed clip length, so it
captures into a CUDA graph).
Functions
|
Decode an audio file to a float32 mono waveform at |
|
Whisper's fixed sinusoidal position table, |
|
Area-normalized triangular mel filters, |
Classes
|
|
- class mstar.model.components.audio_features.LogMelSpectrogram(num_mel_bins=128, sampling_rate=16_000, n_fft=400, hop_length=160, chunk_length=30)[source]#
Bases:
Module(B, samples)or(samples,)float waveform ->(B, n_mels, frames)log-mel features,frames = samples // hop_length.Matches HF’s
_torch_extract_fbank_features:torch.stftwithcenter=Trueyieldssamples // hop + 1frames and the last is dropped, and the dynamic-range clamp is per clip. Whisper pads or truncates tochunk_lengthseconds before this transform; usepad_or_trim()for that.- extra_repr()[source]#
Return the extra representation of the module.
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
- Return type:
- forward(waveform)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- mstar.model.components.audio_features.load_audio_file(path, sample_rate=16_000)[source]#
Decode an audio file to a float32 mono waveform at
sample_rate.libsndfile (
soundfile) first — it needs no FFmpeg and covers WAV, FLAC, OGG and MP3 — then torchcodec for anything else (M4A, WebM, …). Resampling goes through torchaudio.
- mstar.model.components.audio_features.sinusoid_positions(length, channels, max_timescale=10_000.0)[source]#
Whisper’s fixed sinusoidal position table,
(length, channels):[sin | cos]halves over geometrically spaced timescales. The checkpoint ships it asembed_positions.weight; this is for models (Qwen3-ASR’s AuT) that compute it instead.
- mstar.model.components.audio_features.slaney_mel_filter_bank(num_frequency_bins, num_mel_filters, sampling_rate, min_frequency=0.0, max_frequency=8000.0)[source]#
Area-normalized triangular mel filters,
(num_mel_filters, num_frequency_bins)in float64 — the transpose of HF’s layout, so the forward is onefilters @ power_spectrogrammatmul.