# Replace a voice clone's reference audio

`POST https://my.neuronai.uz/api/v1/tts/voices/{id}/audio`

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

Replaces a voice clone's recording. The voice keeps its `id`.

The old recording stays until the new one is accepted, so a failed upload changes nothing.

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

## Параметры пути

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string | Yes | The voice id. |

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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `ref_audio` | string | Yes | At most 10 MB. |
| `ref_text` | string | No | What the new recording says, word for word. Send it when the words change. A voice with no transcript yet must get one. At most 1000 characters. |

## Ответ (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 |
| --- | --- | --- |
| `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 |
| --- | --- |
| 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`). |
| 404 | No such voice for this key: `not_found`. |
| 422 | The request failed validation (`invalid_request`). `error.fields` names each invalid field. |
| 502 | The voice service could not do it: `upstream_error`. Nothing changes. |
| 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/<voice-id>/audio" \
  -H "Authorization: Bearer <your-api-key>" \
  -F "ref_audio=@/path/to/sample.wav" \
  -F "ref_text=Assalomu alaykum, men sizga yordam berishga tayyorman."
```

### TypeScript SDK

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

const client = new NeuronAI();

// Replacing the clip rebuilds the voice from it, which can take minutes.
const voice = await client.voices.replaceAudio(
    "<voice-id>",
    {
        ref_audio: {data: await readFile("sample.wav"), filename: "sample.wav"},
        ref_text: "Assalomu alaykum, men sizga yordam berishga tayyorman.",
    },
    {timeout: 15 * 60_000},
);

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

### Python SDK

```python
from naiuz import NeuronAI

client = NeuronAI()

# Replacing the clip rebuilds the voice from it, which can take minutes.
voice = client.voices.replace_audio(
    "<voice-id>",
    ref_audio="sample.wav",
    ref_text="Assalomu alaykum, men sizga yordam berishga tayyorman.",
    timeout=15 * 60,
)

print(voice.id)
```

### PHP SDK

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

// Replacing the clip rebuilds the voice from it, which can take minutes.
$voice = $client->voices->replaceAudio('<voice-id>', [
    'ref_audio' => 'sample.wav',
    'ref_text' => 'Assalomu alaykum, men sizga yordam berishga tayyorman.',
], ['timeout' => 15 * 60]);

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

### JavaScript

```javascript
const form = new FormData();
form.append('ref_audio', file);  // a File or Blob (10–15 second clip), e.g. sample.wav
form.append('ref_text', 'Assalomu alaykum, men sizga yordam berishga tayyorman.');

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

const { data } = await response.json();  // data.id is unchanged
```

### Python

```python
import requests

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

response.raise_for_status()
voice = response.json()["data"]  # voice["id"] is unchanged
```

### PHP

```php
$ch = curl_init('https://my.neuronai.uz/api/v1/tts/voices/<voice-id>/audio');

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

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

$voice = json_decode($response, true)['data']; // same id as before
```

---

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