# Create a voice clone

`POST https://my.neuronai.uz/api/v1/tts/voices`

Справочник API › Клонирование голоса

Creates a voice clone from a 10 to 15 second recording of the voice and a transcript of what it says.

Use the new voice's `id` as `voice_id` when you synthesize.

**Authentication:** `Authorization: Bearer <API key>`, a key with `voices:write`.

## Заголовки

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | string | No | Makes a retry safe: the same key again answers 200 with the voice it created, as it is now, instead of cloning another. At most 191 characters, scoped to your organization and kept indefinitely. |

## Тело запроса (`multipart/form-data`)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | A name for the voice. At most 120 characters. |
| `language` | string | Yes | The language the recording is in. One of `uz`, `ru`, `en`, `kk`, `ky`, `tk`, `tg`, `az`, `tr`, `ug`, `tt`, `ba` and 24 more. |
| `ref_audio` | string | Yes | A 10 to 15 second recording of the voice: WAV, MP3, OGG or FLAC, at most 10 MB. |
| `ref_text` | string | Yes | What the recording says, word for word. At most 1000 characters. |
| `category` | string | No | One of `conversational`, `narration`, `characters`, `social_media`, `educational`. |
| `tags` | string[] | No | Send each tag as its own `tags[]` field. Blank tags are dropped. |

## Ответ (200, `application/json`)

Success.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object | Yes |  |
| `data.id` | string | Yes |  |
| `data.name` | string | Yes |  |
| `data.language` | string | Yes |  |
| `data.tags` | string[] | Yes |  |
| `data.type` | string | Yes | One of `custom`, `stock`. |
| `data.category` | string \| null | No |  |
| `data.ref_text` | string \| null | No |  |
| `data.created_at` | string \| null | No |  |
| `request_id` | string | Yes |  |

```json
{
  "data": {
    "id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41",
    "name": "Aziza",
    "language": "uz",
    "tags": [
      "calm"
    ],
    "type": "custom",
    "category": "narration",
    "ref_text": "Mening ismim Aziza, men sizga yordam berishga tayyorman.",
    "created_at": "2026-11-17T09:30:00Z"
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

### Заголовки

| Header | Type | Description |
| --- | --- | --- |
| `Idempotency-Replayed` | string | `1` when the answer is a replay of an earlier request with the same `Idempotency-Key`. |
| `X-Request-Id` | string | Identifies this request. A JSON body carries it as `request_id` too; quote it to support. |

## Ошибки

Every error has the same JSON shape:

```json
{
  "error": {
    "type": "invalid_request_error",
    "code": "invalid_request",
    "message": "The request is malformed or failed validation.",
    "param": null
  },
  "request_id": "7c4a8d09-ca37-4f3c-9e2b-1b0f3c2a9d41"
}
```

| Status | Meaning |
| --- | --- |
| 400 | The `Idempotency-Key` is over 191 characters: `invalid_request`. |
| 401 | The API key is missing or not recognized (`invalid_api_key`), revoked (`api_key_revoked`), disabled (`api_key_disabled`) or expired (`api_key_expired`). |
| 403 | The key lacks the permission this endpoint needs (`insufficient_permissions`), or the client IP is not in its allowlist (`ip_not_allowed`). |
| 409 | The `Idempotency-Key` was already used with a different body: `idempotency_conflict`. |
| 422 | The request failed validation (`invalid_request`). `error.fields` names each invalid field. |
| 502 | The voice service could not do it: `upstream_error`. Nothing is created. |
| default | Any other error, in the same shape, such as `server_error` (500) or `service_unavailable` (503). |

## Examples

### cURL

```bash
curl -X POST "https://my.neuronai.uz/api/v1/tts/voices" \
  -H "Authorization: Bearer <your-api-key>" \
  -F "name=Aziza" \
  -F "language=uz" \
  -F "ref_audio=@/path/to/aziza-sample.wav" \
  -F "ref_text=Mening ismim Aziza, men sizga yordam berishga tayyorman."
```

### TypeScript SDK

```typescript
import {NeuronAI} from "@naiuz/sdk";
import {readFile} from "node:fs/promises";

const client = new NeuronAI();

const voice = await client.voices.create({
    name: "Aziza",
    language: "uz",
    ref_audio: {data: await readFile("aziza-sample.wav"), filename: "aziza-sample.wav"},
    ref_text: "Mening ismim Aziza, men sizga yordam berishga tayyorman.",
});

console.log(voice.id);
```

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

voice = client.voices.create(
    name="Aziza",
    language="uz",
    ref_audio="aziza-sample.wav",
    ref_text="Mening ismim Aziza, men sizga yordam berishga tayyorman.",
)

print(voice.id)
```

### PHP SDK

```php
$client = new \Naiuz\NeuronAI();

$voice = $client->voices->create([
    'name' => 'Aziza',
    'language' => 'uz',
    'ref_audio' => 'aziza-sample.wav',
    'ref_text' => 'Mening ismim Aziza, men sizga yordam berishga tayyorman.',
]);

echo $voice->id, PHP_EOL;
```

### JavaScript

```javascript
const form = new FormData();
form.append('name', 'Aziza');
form.append('language', 'uz');
form.append('ref_audio', file);  // a File or Blob (10-15s clip)
form.append('ref_text', 'Mening ismim Aziza, men sizga yordam berishga tayyorman.');

const response = await fetch('https://my.neuronai.uz/api/v1/tts/voices', {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <your-api-key>' },
    body: form,
});

const { data } = await response.json();
const voiceId = data.id;  // use this as voice_id when synthesizing
```

### Python

```python
import requests

with open("aziza-sample.wav", "rb") as audio:
    response = requests.post(
        "https://my.neuronai.uz/api/v1/tts/voices",
        headers={"Authorization": "Bearer <your-api-key>"},
        data={
            "name": "Aziza",
            "language": "uz",
            "ref_text": "Mening ismim Aziza, men sizga yordam berishga tayyorman.",
        },
        files={"ref_audio": audio},
    )

response.raise_for_status()
voice = response.json()["data"]
voice_id = voice["id"]  # use this as voice_id when synthesizing
```

### PHP

```php
$ch = curl_init('https://my.neuronai.uz/api/v1/tts/voices');

curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer <your-api-key>'],
    CURLOPT_POSTFIELDS => [
        'name' => 'Aziza',
        'language' => 'uz',
        'ref_text' => 'Mening ismim Aziza, men sizga yordam berishga tayyorman.',
        'ref_audio' => new CURLFile('/path/to/aziza-sample.wav'),
    ],
]);

$response = curl_exec($ch);
curl_close($ch);

$voice = json_decode($response, true)['data'];
$voiceId = $voice['id']; // use this as voice_id when synthesizing
```

---

Source: https://docs.neuronai.uz/ru/api/reference/voice-cloning/create-voice
