> ## Documentation Index
> Fetch the complete documentation index at: https://docs.runanywhere.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Diarization

> Work out who spoke when

Diarization segments a recording by speaker. It answers "who spoke when", not "what did they
say"; pair it with [transcription](/swift/stt/transcribe) for both.

```swift theme={null}
let result = try await RunAnywhere.diarization.diarize(AudioInput.file(path))
```

## Options

| Field               | Meaning                                                        |
| ------------------- | -------------------------------------------------------------- |
| `threshold`         | How different two voices must be to count as separate speakers |
| `minimumDurationMs` | Ignore segments shorter than this                              |
| `mergeGapMs`        | Join two segments from one speaker separated by less than this |

`mergeGapMs` is the one to tune. Natural speech has pauses inside a turn, and without merging
you get one speaker fragmented into a dozen segments.

## Diarization inside transcription

For a transcript labelled by speaker rather than a separate segment list, ask the STT namespace
instead:

```swift theme={null}
let transcription = try await RunAnywhere.stt.transcribe(
    audio,
    options: SttOptions(diarization: true, maxSpeakers: 2)
)
```

Use the STT route when you want a readable transcript. Use the diarization namespace when you
want timing, for example to drive a speaker timeline or to split a recording into per-speaker
files.

## Knowing the speaker count helps

`maxSpeakers` on the STT path, and a sensible `threshold` here, both improve accuracy a lot
when you know how many people are in the room. Diarization over-segments when left to guess.

## Streaming

Swift is the only SDK with a streaming diarizer:

```swift theme={null}
let events = try await RunAnywhere.diarization.diarizeStream(
    audioStream,
    sampleRate: 16000,
    channels: 1,
    encoding: .pcmF32Le
)

for try await result in events {
    timeline.append(result)
}
```

Use it to label speakers live in a meeting view rather than after the recording ends.
