<!-- https://bobabanana.com/docs/api/speech/ · Clone a voice from a 5-30 second sample, or use a saved library voice, and turn text into speech with POST /v1/speech. Returns a WAV file. Consent required. -->

# Voice cloning and text-to-speech API

**`POST /v1/speech` speaks your text in a voice you choose: either a saved library voice (`"@handle"`) or a new voice cloned from a 5 to 30 second recording you upload.** The result is a WAV file. Use the same voice in [videos](https://bobabanana.com/docs/api/videos/) to make lip-synced talking characters.

## Request fields

| Field | Type | Required | Description |
|---|---|---|---|
| `text` | string, up to 600 chars | yes | What to say |
| `voice` | `"@handle"` or a voice sample object | yes | The voice |
| `voice_consent` | boolean | with a sample | Must be `true` to clone an uploaded voice |
| `webhook_url`, `metadata`, `name` | | no | As for [images](https://bobabanana.com/docs/api/images/) |

## Voice samples

A voice sample is an object with one of `file_id`, `url` or `data`, plus an optional `transcript`:

```json
{"file_id": "file_voice123", "transcript": "The exact words spoken in the recording."}
```

A plain string also works: `"file_voice123"`, an `https://` URL or a `data:` URI.

**What makes a good sample:**

1. **5 to 30 seconds** of speech (2 to 60 seconds is accepted).
2. **One speaker only**, no music, no background noise.
3. **Clear, natural delivery** in the style you want to hear back.
4. **An exact transcript**, if you have one. Without it, BobaBanana transcribes the sample first.

Accepted formats: WAV, MP3, M4A, OGG, FLAC, WEBM, AAC, OPUS, up to 60 MB. The upload response includes `duration` and quality `warnings` (too short, too quiet, distorted, noisy).

## Example: clone a voice and speak

```bash
# 1. upload the sample
curl https://bobabanana.com/api/v1/files -H "Authorization: Bearer $BOBABANANA_API_KEY" -F "file=@my-voice.wav"

# 2. speak new text in that voice
curl https://bobabanana.com/api/v1/speech \
  -H "Authorization: Bearer $BOBABANANA_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "text": "Thanks for joining us. The next episode drops on Friday.",
    "voice": {"file_id": "file_voice123", "transcript": "Hi, this is my normal speaking voice for the sample."},
    "voice_consent": true
  }'
```

## Example: a saved library voice

```json
{"text": "Once upon a time, in a valley hidden by mist, there lived a clockmaker.", "voice": "@storyteller"}
```

List available voices with `GET /v1/voices` ([assets](https://bobabanana.com/docs/api/assets/)).

## Response

When the job succeeds, `output.speech.url` is a WAV file:

```json
{"id": "x_51aa", "type": "speech", "status": "succeeded", "output": {"speech": {"url": "https://bobabanana.com/api/v1/files/content/out/...wav?...", "content_type": "audio/wav"}}}
```

## Responsible voice cloning

- Clone only your own voice, or a voice whose speaker has given you explicit permission.
- `voice_consent: true` is required for every uploaded sample and is stored with the job.
- Voice samples are used only to make the jobs you request with them.

## Frequently asked questions

### How much audio do I need to clone a voice?
5 to 30 seconds of clean speech from one person.

### Do I have to provide a transcript?
No, but it helps. Without one, the sample is transcribed automatically before speaking.

### Which languages are supported?
English works best. Speech in the sample's language is the most reliable.

### Can I use the cloned voice in a video?
Yes. Send the same `voice` with a `script` to `POST /v1/videos` for a lip-synced talking clip.
