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

# Telephony Audio Formats

> Use mu-law, A-law, and low-sample-rate PCM with Gradium voice APIs

Telephony providers commonly send 8 kHz mono audio encoded as mu-law
or A-law. Gradium supports those formats directly for STT and can
produce telephony-friendly TTS output.

## Recommended Formats

| Use case                   | Gradium format                             | Notes                                                    |
| -------------------------- | ------------------------------------------ | -------------------------------------------------------- |
| Incoming PSTN audio to STT | `ulaw_8000` or `alaw_8000`                 | Use the encoding your telephony provider sends.          |
| Incoming linear PCM to STT | `pcm_8000` or `pcm_16000`                  | 16-bit signed little-endian mono PCM.                    |
| Outgoing audio to PSTN     | `ulaw_8000` or `alaw_8000`                 | Avoid resampling in your telephony bridge when possible. |
| Higher quality app audio   | `pcm_24000`, `pcm_48000`, `wav`, or `opus` | Use outside PSTN constraints.                            |

## STT WebSocket Setup

```json theme={null}
{
  "type": "setup",
  "model_name": "default",
  "input_format": "ulaw_8000",
  "json_config": {"language": "en"}
}
```

Then send base64-encoded audio payloads:

```json theme={null}
{"type": "audio", "audio": "base64_encoded_ulaw_chunk"}
```

## TTS WebSocket Setup

```json theme={null}
{
  "type": "setup",
  "voice_id": "YTpq7expH9539ERJ",
  "output_format": "ulaw_8000"
}
```

The `audio` messages contain base64-encoded mu-law chunks that can be
forwarded to a telephony media stream.

## Chunk Size Guidance

Many telephony media streams send 20 ms frames. Gradium accepts small
chunks, but batching to roughly 80 ms can reduce message overhead while
keeping latency low:

| Format                    | 20 ms payload | 80 ms payload |
| ------------------------- | ------------: | ------------: |
| `ulaw_8000` / `alaw_8000` |     160 bytes |     640 bytes |
| `pcm_8000`                |     320 bytes |    1280 bytes |
| `pcm_16000`               |     640 bytes |    2560 bytes |

## Bridge Checklist

* Preserve the provider's stream/session ID in your own logs.
* Use one Gradium STT session per caller audio stream.
* Set `input_format` to the actual bytes you forward.
* For TTS, request an output format your provider can play directly.
* Use STT `step` messages or your provider's VAD to decide when to
  send the user's turn to an agent.
* Close the WebSocket and start a new session if the call leg changes
  format.

## Related

<CardGroup cols={2}>
  <Card title="Speech-to-Text WebSocket" icon="microphone" href="/guides/speech-to-text">
    Real-time transcription with VAD and flush.
  </Card>

  <Card title="Text-to-Speech WebSocket" icon="waveform-lines" href="/guides/text-to-speech">
    Stream generated audio back to your telephony bridge.
  </Card>
</CardGroup>
