nemo_curator.stages.audio.alm.pretrain.extraction
nemo_curator.stages.audio.alm.pretrain.extraction
Audio extraction stage: slice, mono-resample, write into a tar shard.
Module Contents
Classes
API
Bases: ProcessingStage[AudioTask, AudioTask]
Slice the source audio per snippet plan, mono-resample, and write into a tar.
For each planned snippet:
- Read just the slice
[start, end]from the source file. - Channel-average to mono if the source has > 1 channel.
- Resample to
target_sample_rateusing torchaudio if the source rate differs. - Encode the mono waveform in-memory (via
soundfileto aBytesIO) and append it as<snippet_id>.<output_format>to this replica’s tar shard (output_audio_tar_path.shard-...); all replicas’ shards are merged intooutput_audio_tar_pathby :func:finalize_audio_pretrain_outputs. - Emit one
AudioTaskper snippet with the source row’s metadata carried over (minusalignment), the newsnippet_id,audio_filepathset to the tar-internal basename (<snippet_id>.<output_format>), updatedduration, and segments relativized to the snippet start.
The tar-internal basename matches webdataset / Energon convention:
sample key is <snippet_id> (everything before the first .),
extension is <output_format>. make_snippet_id already
avoids . characters so the snippet id never spuriously splits.
If the input produced zero snippets, a single “stub” AudioTask
is emitted (snippet_id=None, no audio written) so that
per-original metrics can still flow to the aggregator.
Dry-run mode (dry_run=True): skips steps 1-4 entirely (no
soundfile reads, no resampling, no tar writes — not even a tar
shard is opened), and step 5 uses the planned end - start as the
snippet duration instead of the post-resample frame count. The
emitted audio_filepath still uses the basename form for parity
with real runs. Useful for previewing the manifest and metrics on
real data before committing to a full run.
Emit snippet metadata only, without reading or writing audio.
audio_filepath is the tar-internal basename
<snippet_id>.<output_format> for parity with real runs —
the tar itself is not opened in dry-run. Snippet duration
is the planned end - start (vs. the resampled-frame-count
duration the real path would compute — the difference is at
most one frame at target_sample_rate).