# Synthesize a voice note

`POST https://api.morevoice.ai/v1/speech/synthesis`

Speaks up to 2000 characters in a voice from `GET /v1/voices` and returns an OGG/Opus file (`audio/ogg; codecs=opus`, mono, 48 kHz) that plays as a WhatsApp voice note. The `Audio-Duration-Ms` header gives its length and `Audio-Source` says whether it is `speech` or test mode's `synthetic` tone. Billed per character. With an `Idempotency-Key`, a retry within 24 hours returns the same file and is not billed again. Test-mode keys get a synthetic tone as long as the speech would be (the same bytes for the same request) and are never billed.

Authenticate with a secret API key: `Authorization: Bearer $MOREVOICE_API_KEY`.

Operation ID: `speech_synthesize`.

## Parameters

### Headers

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `MoreVoice-Version` | `string` | no | The API version to use for this request. Defaults to the version the API key is pinned to. |
| `Idempotency-Key` | `string` | no | A unique key (for example a UUID) that makes this request safe to retry: for 24 hours, a retry with the same key and parameters returns the first response instead of acting twice. |

## Request body

Required, `application/json`.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `text` | `string` | yes | What to say, up to 2000 characters (longer text is refused with 422 `text_too_long`). Billed per character. |
| `voice_id` | `string` | yes | The voice (`voice_id` from `GET /v1/voices`, your custom voices included). |
| `format` | `"ogg_opus"` | no | The audio format: `ogg_opus` (the default), mono 48 kHz, playable as a WhatsApp voice note. |
| `language` | `string` | no | The language of `text` (default: Hebrew when the text is in Hebrew script, else English). |

Example:

```json
{
  "format": "ogg_opus",
  "language": "he",
  "text": "שלום! ההזמנה שלך יצאה היום ותגיע מחר.",
  "voice_id": "Kore"
}
```

## Responses

### 200 OK

The voice note (OGG/Opus).

### 400 Bad Request

The request is invalid: a parameter is missing, malformed or unknown, or the version header is unknown. Returns `ErrorEnvelope`.

### 401 Unauthorized

No valid API key was sent. Returns `ErrorEnvelope`.

### 403 Forbidden

The key may not do this (a missing scope, a plan limit, or a compliance block). Returns `ErrorEnvelope`.

### 404 Not Found

No object with this ID (in the path or the body) exists in this organisation and mode. Returns `ErrorEnvelope`.

### 409 Conflict

The request conflicts with the object's state, or the Idempotency-Key was reused with other parameters. Returns `ErrorEnvelope`.

### 413 Payload Too Large

The request body is larger than the endpoint accepts, or has more parts or files than it takes. Returns `ErrorEnvelope`.

### 415 Unsupported Media Type

The request body's Content-Type is not one the endpoint takes. Returns `ErrorEnvelope`.

### 422 Unprocessable Entity

The request is well formed, but its content can't be processed: for example audio longer than allowed, audio with no speech, or text over the length limit. Returns `ErrorEnvelope`.

### 429 Too Many Requests

Too many requests, or no call capacity right now. Retry after the Retry-After delay. Returns `ErrorEnvelope`.

### 500 Internal Server Error

Something went wrong on MoreVoice's side. Retry with the same Idempotency-Key. Returns `ErrorEnvelope`.

### 503 Service Unavailable

A dependency this endpoint needs (a speech or language model, file storage) is temporarily unavailable. Retry later. Returns `ErrorEnvelope`.

## Code samples

**TypeScript**

```ts
import MoreVoice from "@morevoice/sdk";

const mv = new MoreVoice(); // MOREVOICE_API_KEY from the environment

const data = await mv.speech.synthesize({
	format: "ogg_opus",
	language: "he",
	text: "שלום! ההזמנה שלך יצאה היום ותגיע מחר.",
	voice_id: "Kore",
});
console.log(data);
```

**Python**

```python
from morevoice import MoreVoice

client = MoreVoice()  # MOREVOICE_API_KEY from the environment

data = client.speech.synthesize({
    "format": "ogg_opus",
    "language": "he",
    "text": "שלום! ההזמנה שלך יצאה היום ותגיע מחר.",
    "voice_id": "Kore",
})
print(len(data), "bytes")
```

**cURL**

```sh
curl -X POST https://api.morevoice.ai/v1/speech/synthesis \
  -H "Authorization: Bearer $MOREVOICE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
  "format": "ogg_opus",
  "language": "he",
  "text": "שלום! ההזמנה שלך יצאה היום ותגיע מחר.",
  "voice_id": "Kore"
}'
```
