> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/curator/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/curator/_mcp/server.

# nemo_curator.stages.audio.preprocessing.concatenation

Audio segment concatenation stage.

Concatenates VAD segments stored in `task.data["segments"]` (nested mode)
into one combined waveform per source file.  Segments are sorted by
`segment_num` (gaps from filtered-out segments are fine — order is
preserved) and concatenated with configurable silence between them.

Stores segment-to-original mappings in `task._metadata` so downstream
stages (TimestampMapperStage) can resolve final positions back to
the original file.

Uses canonical waveform + sample\_rate format only (no pydub).

## Module Contents

### Classes

| Name                                                                                                            | Description                                                      |
| --------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| [`SegmentConcatenationStage`](#nemo_curator-stages-audio-preprocessing-concatenation-SegmentConcatenationStage) | Concatenate nested VAD segments into a single combined waveform. |
| [`SegmentMapping`](#nemo_curator-stages-audio-preprocessing-concatenation-SegmentMapping)                       | Mapping from concatenated position to original file position.    |

### API

```python
class nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage(
    silence_duration_sec: float = 0.5,
    name: str = 'SegmentConcatenation',
    batch_size: int = 1,
    resources: nemo_curator.stages.resources.Resources = (lambda: Resources(cpus=1.0...
)
```

Dataclass

**Bases:** [ProcessingStage\[AudioTask, AudioTask\]](/nemo-curator/nemo_curator/stages/base#nemo_curator-stages-base-ProcessingStage)

Concatenate nested VAD segments into a single combined waveform.

Expects each incoming `AudioTask` to carry a
`task.data["segments"]` list (one file = one task, produced by
`VADSegmentationStage(nested=True)`).  Segments are sorted by
`segment_num`, concatenated with silence gaps, and the result
is a single `AudioTask` with the combined waveform and
segment-to-original mappings in `task._metadata["segment_mappings"]`.

**Parameters:**

Duration of silence inserted between
consecutive segments (seconds).

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage.__post_init__()
```

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage._concatenate(
    original_file: str,
    segments: list[dict[str, typing.Any]],
    task_id: str,
    dataset_name: str
) -> nemo_curator.tasks.AudioTask | None
```

Concatenate a list of segment dicts from the same source file.

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage._seg_sort_key(
    seg: dict[str, typing.Any]
) -> tuple[int, int, int]
```

staticmethod

Sort key for segment dicts: (segment\_num, start\_ms, 0).

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage._validate_segment(
    seg: dict[str, typing.Any]
) -> tuple[torch.Tensor, int] | None
```

staticmethod

Validate and return (waveform, sample\_rate) or None if invalid.

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage.inputs() -> tuple[list[str], list[str]]
```

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage.outputs() -> tuple[list[str], list[str]]
```

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentConcatenationStage.process(
    task: nemo_curator.tasks.AudioTask
) -> nemo_curator.tasks.AudioTask | list[nemo_curator.tasks.AudioTask]
```

Concatenate segments from `task.data["segments"]`.

```python
class nemo_curator.stages.audio.preprocessing.concatenation.SegmentMapping(
    original_file: str,
    original_start_ms: int,
    original_end_ms: int,
    concat_start_ms: int,
    concat_end_ms: int,
    segment_index: int
)
```

Dataclass

Mapping from concatenated position to original file position.

```python
nemo_curator.stages.audio.preprocessing.concatenation.SegmentMapping.to_dict() -> dict[str, typing.Any]
```