mstar.model.omnilingual_asr.audio#
Waveform preprocessing for Omnilingual ASR, in the reference’s order.
The reference pipeline (omnilingual_asr models/inference/pipeline.py and
datasets/utils/audio.py) decodes the file at its own rate (libsndfile,
float32), resamples every channel to 16 kHz with
torchaudio.functional.resample, averages the channels, normalizes the
utterance to zero mean and unit variance (layer_norm over the whole
waveform, eps 1e-5) and rejects clips over 40 s. load_waveform and
preprocess do the same, with the same ops, so an upload reaches the encoder
bit-identical to the reference’s input.
Functions
|
|
|
Float32 samples at the file's own rate: |
|
A file's 16 kHz mono float32 waveform, not yet normalized. |
|
Zero mean, unit variance over the whole utterance, in float32 (the reference's |
|
16 kHz mono waveform -> the encoder input: length-checked, normalized. |
|
Resample each channel to 16 kHz, then average the channels, as the reference does (resample, then |
- mstar.model.omnilingual_asr.audio.check_length(num_samples)[source]#
- Parameters:
num_samples (int)
- Return type:
None
- mstar.model.omnilingual_asr.audio.decode_file(path)[source]#
Float32 samples at the file’s own rate:
(time,)for mono,(time, channels)otherwise, as libsndfile (the reference’s decoder) returns them.libsndfile through
soundfilefirst; then, for a WAV file, a reader here that scales samples as libsndfile does, so a server without soundfile still decodes WAV exactly; then FFmpeg throughtorchcodecfor the containers neither reads. The two library decoders stop just pastMAX_AUDIO_SECONDSand refuse a longer file withAudioTooLongError, whatever its header declares.
- mstar.model.omnilingual_asr.audio.load_waveform(path)[source]#
A file’s 16 kHz mono float32 waveform, not yet normalized.
- mstar.model.omnilingual_asr.audio.normalize(waveform)[source]#
Zero mean, unit variance over the whole utterance, in float32 (the reference’s
layer_norm(waveform, waveform.shape)).