> This page is for Model APIs.

> Sarvam Voice Agents (Samvaad) is a voice AI agent platform for Indian languages: build, test and deploy AI calling agents on your own phone numbers, from ₹3 a minute. Start here: https://docs.sarvam.ai/voice-agents/why-voice-agents.
> For clean Markdown of any page, append `.md` to the page URL.
> For a complete documentation index, see https://docs.sarvam.ai/llms.txt. For a section index, append `/llms.txt` to any section URL (for example https://docs.sarvam.ai/voice-agents/llms.txt).
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.sarvam.ai/_mcp/server.

# How to choose audio formats

> Input and output audio formats for the Sarvam AI Instant Voice Cloning API. Supported reference codecs, output codecs, sample rates, and file-size guidance.

## Input formats

The `file` uploaded to `POST /voices/create` accepts the following codecs:

| Codec      | Notes                                                                                |
| ---------- | ------------------------------------------------------------------------------------ |
| `WAV`      | Recommended. Uncompressed; fastest to decode and avoids lossy compression artifacts. |
| `MP3`      | Widely available; ensure bitrate ≥ 128 kbps for cleaner clones.                      |
| `FLAC`     | Lossless compression; equivalent quality to WAV with smaller file size.              |
| `OPUS`     | Modern codec with good speech quality at low bitrates.                               |
| `AAC`      | Common in mobile recordings.                                                         |
| `LINEAR16` | Raw 16-bit PCM.                                                                      |
| `MULAW`    | 8-bit μ-law (telephony). Quality is limited by the codec.                            |
| `ALAW`     | 8-bit A-law (telephony). Quality is limited by the codec.                            |

For best cloning quality, use WAV or FLAC. Telephony codecs (MULAW, ALAW) work but cap the achievable fidelity at the source.

## Output formats

### One-shot (`POST /voices/clone`)

Specify the output codec via `output_audio_codec`. The default is `wav`.

| Codec value | Description                                                        |
| ----------- | ------------------------------------------------------------------ |
| `wav`       | Uncompressed WAV. Default. Best quality for downstream processing. |
| `mp3`       | MP3-encoded audio. Smaller file size; suitable for web playback.   |
| `flac`      | Lossless compression.                                              |
| `opus`      | Low-bitrate codec ideal for streaming.                             |
| `aac`       | Common in mobile and broadcast.                                    |
| `linear16`  | Raw 16-bit PCM.                                                    |
| `mulaw`     | 8-bit μ-law. Use for IVR/telephony pipelines.                      |
| `alaw`      | 8-bit A-law. Use for IVR/telephony pipelines.                      |

> **Warning**
>
> **OPUS restricts the sample rate.** When `output_audio_codec` is `opus` and `speech_sample_rate` is explicitly set, it must be one of 8000, 16000, 24000, or 48000 Hz. Other rates fail with `400 Bad Request`. When `speech_sample_rate` is omitted, opus output is returned at the native 24000 Hz.

### Streaming (`POST /voices/clone/stream` and WebSocket)

Streaming endpoints default to `mp3` and only accept codecs that concatenate cleanly across sentences:

| Codec value      | MIME type                    | Notes                                                 |
| ---------------- | ---------------------------- | ----------------------------------------------------- |
| `mp3`            | `audio/mpeg`                 | Default. Self-framing; best for progressive playback. |
| `wav`            | `audio/wav`                  | One RIFF header, then PCM chunks.                     |
| `linear16`       | `audio/pcm`                  | Raw PCM (no header).                                  |
| `mulaw` / `alaw` | `audio/mulaw` / `audio/alaw` | Telephony encodings.                                  |

`flac`, `aac`, and `opus` are rejected on streaming endpoints (422). Optional `output_audio_bitrate` (`32k`–`192k`, default `128k`) applies to lossy codecs. See [HTTP Streaming](/api/api-guides-tutorials/voice-cloning/how-to/http-streaming).

## Sample rate

Use `speech_sample_rate` to set the output sample rate in Hz:

`8000`, `16000`, `22050`, `24000`, `32000`, `44100`, `48000`

If omitted, the API returns audio at the model's native rate (24,000 Hz). Set the sample rate to match your downstream pipeline:

| Pipeline            | Recommended sample rate |
| ------------------- | ----------------------- |
| Telephony / IVR     | 8000                    |
| Voice agents / VoIP | 16000                   |
| Web playback        | 24000 (default)         |
| Broadcast / studio  | 44100 or 48000          |

> **Note**
>
> Sample rates above 24000 Hz (32000, 44100, 48000) are supported for broadcast-quality output, matching the Bulbul v3 REST API.

## File size guidance

Higher sample rates and uncompressed codecs produce larger output files. As a rough guide for a 10-second clip:

| Codec            | Sample rate | Approximate size |
| ---------------- | ----------- | ---------------- |
| `wav`            | 24000       | \~470 KB         |
| `wav`            | 48000       | \~940 KB         |
| `mp3` (128 kbps) | 24000       | \~160 KB         |
| `opus` (32 kbps) | 24000       | \~40 KB          |
| `mulaw`          | 8000        | \~80 KB          |

For high-volume API usage, choose a compressed codec (mp3, opus, aac) unless your downstream pipeline specifically requires uncompressed audio.

## Decoding the response

The `audio` field is a base64-encoded string of the raw bytes for the codec you requested. Prefer the [SDK](/api/getting-started/sdks) — it returns the same payload without hand-building multipart:

#### Python

```python
import base64
from sarvamai import SarvamAI

client = SarvamAI(api_subscription_key="YOUR_SARVAM_API_KEY")

response = client.voice_cloning.convert(
    voice_id="svc-your-voice-id",
    text="Hello world",
    output_audio_codec="wav",
)
with open("output.wav", "wb") as f:
    f.write(base64.b64decode(response.audio))
```

#### JavaScript

```javascript
import { SarvamAIClient } from "sarvamai";
import fs from "fs";

const client = new SarvamAIClient({
  apiSubscriptionKey: process.env.SARVAM_API_KEY,
});

const result = await client.voiceCloning.convert({
  voiceId: "svc-your-voice-id",
  text: "Hello world",
  output_audio_codec: "wav",
});
fs.writeFileSync("output.wav", Buffer.from(result.audio, "base64"));
```

#### cURL

```bash
curl -s -X POST "https://api.sarvam.ai/voices/clone" \
  -H "api-subscription-key: $SARVAM_API_KEY" \
  -F "voice_id=svc-your-voice-id" \
  -F "text=Hello world" \
  -F "output_audio_codec=wav" \
  -o response.json

# Decode audio into a file; use the extension matching your output_audio_codec
python3 -c "import base64, json; open('output.wav', 'wb').write(base64.b64decode(json.load(open('response.json'))['audio']))"
```

`language_code` is optional and omitted here so the service detects English from the text. Detection can be wrong on short or code-mixed text — pass the code when pronunciation has to be exact. See [Supported languages](/api/api-guides-tutorials/voice-cloning/supported-languages#omitting-language_code).

## Next steps

#### [Prepare Reference Audio](/api/api-guides-tutorials/voice-cloning/how-to/prepare-reference-audio)

Reference clip guidelines and technical specs.