# Audio Join

Joins an ordered list of audio clips into one audio file.

Use it when audio arrives in pieces — speech generated one section at a time, clips from your
media library, sound effects — and you need to deliver a single file.

## Behavior

- Every clip must be the same format. Mixed clips are refused rather than joined.
- The output format is the format of the clips; there is nothing to choose.
- Clip order is output order.
- The result is binary audio on `output`. Add `Upload Media` after it to keep the file.

Speech providers cap how much text one request may carry — InWorld's limit is 2,000 characters,
roughly two minutes of speech — so a longer script is split, spoken in sections, and joined here:

```text
Split Text -> Loop -> Generate Speech
                |
          Loop.output -> Audio Join -> Upload Media
```

## Ordering

Clip `i` of the output is element `i` of the input array. `metadata.segment_durations_secs` lists
the clips in that same order, so a workflow can confirm the sequence rather than assume it.

## Inputs

**input** — An array of audio clips. Each element accepts:

- binary audio from another node, such as `Generate Speech`, `Generate SFX` or `Extract Audio`
- a media object id string, or `{ "object_id": "..." }`
- `{ "url": "..." }`
- the binary response from `HTTP Request`

A single value is treated as a list of one. An empty list is an error, not a no-op.

## Configuration

**gap_ms** — Silence between clips, in milliseconds. Defaults to `0`. Not available for Ogg. For
MP3 the gap lands on the nearest frame, within about 26 ms at 44,100 Hz.

**filename** — Optional output filename. Defaults to `joined.mp3`, `joined.wav` or `joined.ogg`.

There is no format setting. The output format follows the clips.

## Supported formats

| Format | Notes |
|---|---|
| MP3 | |
| WAV | Uncompressed PCM and IEEE float. Compressed WAV such as ADPCM is refused. |
| Ogg Vorbis, Ogg Opus | Every clip must come from the same voice and output format. |

A clip's format is determined from the audio itself, so a file whose declared type does not match
its contents is still handled correctly.

## Outputs

**output** — Binary audio:

```json
{
  "binary": { "__binary__": true },
  "filename": "joined.mp3",
  "content_type": "audio/mpeg",
  "size_bytes": 123456,
  "metadata": {
    "format": "mp3",
    "codec": "mp3",
    "sample_rate": 44100,
    "channels": 1,
    "segment_count": 3,
    "duration_secs": 312.4,
    "segment_durations_secs": [104.1, 103.9, 104.4]
  }
}
```

`Discord Action` attachments and `Upload Media` both take this directly.

## Examples

### Long-form speech as one attachment

```text
Constant(script)
  -> Split Text(max_chars = 1850)
  -> Loop
       -> Generate Speech
  -> Audio Join
  -> Discord Action(attachments)
```

### Assembled audio from stored media

```text
Query Collection Items
  -> Loop
       -> Read Media(output_format = binary)
  -> Audio Join(gap_ms = 500)
  -> Upload Media(kind_hint = audio)
```

## Limits

- At most 64 clips.
- At most 50 MB of audio in, and 50 MB out.
- At most 30 minutes of joined audio.

Discord caps attachments at 8 MB. Read `size_bytes` and send a link from `Upload Media` instead
for anything larger — around 9,000 characters of speech reaches that size.

## Known limitations

- **Clips are joined at their edges.** A brief click can be audible at each join. For speech split
  at sentence boundaries it is not noticeable, but it is not suitable for gapless music. Fewer,
  longer clips mean fewer joins.
- **Ogg clips must share a voice and output format.** Clips generated with different settings are
  refused.
- **Ogg does not support `gap_ms`.** Use MP3 or WAV when you need silence between clips.

## When it refuses

The node fails the run rather than producing a file that plays back wrong. Each message names the
clip to look at.

| Cause | What to change |
|---|---|
| The input was empty | Check the step feeding `input` produced clips |
| More than 64 clips, or over the size or duration limit | Join fewer clips, or in stages |
| A clip is a different format, sample rate, channel count or voice than the first | Regenerate every clip with the same model, voice and output format |
| A clip is not audio the node can read, or is raw PCM with no format information | Request `mp3` or `wav` output from the step that produced it |
| A clip is compressed WAV, such as ADPCM | Use uncompressed PCM WAV, or MP3 |
| A clip is damaged, incomplete, or is itself several files stuck together | Regenerate that clip |
| `gap_ms` is set and the clips are Ogg | Set `gap_ms` to `0`, or use MP3 or WAV |
