Audio Preprocessing¶
Define an audio preprocessing pipeline to extract features for training your model. Pass the same pipeline to dg.export and it compiles directly into your model binary, so deployed inference runs on raw audio with no preprocessing mismatch.
For complete working examples, see the Tutorials page.
from dg import preprocess
pipe = preprocess.AudioPipeline([
preprocess.PeakNormalize(eps=1e-6),
preprocess.Window(frame_length=480, hop=320),
preprocess.Spectrum(n_fft=512, power=1),
preprocess.MelFilterbank(num_mels=40, sample_rate=16000, f_min=20.0, f_max=4000.0),
preprocess.Log(eps=1e-6),
preprocess.DCT(num_coefficients=10),
], num_samples=16000)
# Extract features once (waveforms: int16 [batch, 16000] PCM samples at 16 kHz)
features = pipe.features(waveforms, batch_size=2048)
# Train your model
model = MyKwsModel()
qmodel = dg.enable_quantization(model, (features[:2],))
# ... train / calibrate ...
quantized = dg.freeze_quantization(qmodel)
# Export with preprocessing
schema = dg.export(quantized, preprocess=pipe)
batch_size controls how many samples process per call; lower it if memory is tight.
Available transformations¶
Audio preprocessing pipelines typically include the following steps. See the API reference for all available steps and their parameters:
- Normalization – per-clip peak normalization
- Framing – window the waveform into overlapping frames
- Spectral analysis – compute FFT magnitude or power spectrum
- Perceptual scaling – apply mel-frequency filterbank for human-auditory sensitivity
- Compression – log or other nonlinear compression
- Feature extraction – DCT or other dimensionality reduction (MFCC)