> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camb.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Dubbing

> Dub a video into another language using the Python or TypeScript SDK

## Overview

Translate the audio of any video into another language while preserving the original speaker's voice characteristics. Dubbing is useful for content localization, accessibility, and reaching global audiences without re-recording.

The dubbing pipeline is asynchronous: you submit a job, poll until it completes, then retrieve the dubbed output.

### Prerequisites

**1. Create an account**

Sign up at [CAMB.AI Studio](https://studio.camb.ai) if you haven't already.

**2. Get your API key**

Go to **Settings → API Keys** in Studio and copy your key. See [Authentication](https://docs.camb.ai/getting-started/authentication.md) for details.

**3. Install the SDK**

```bash Python theme={null}
pip install camb-sdk
```

```bash TypeScript theme={null}
npm install @camb-ai/sdk
```

Skip this step if you're using the [direct API](https://docs.camb.ai/tutorials/direct-api.md).

**4. Set your API key to use in your code**

```bash theme={null}
export CAMB_API_KEY="your_api_key_here"
```

***

## Code

```python Python theme={null}
import os
import time
from camb.client import CambAI
from camb.types.language_enums import Languages

client = CambAI(api_key=os.getenv("CAMB_API_KEY"))

response = client.dub.create_dub(
    video_url="your_accessible_video_url",
    source_language=Languages.EN_US,  # English (or check client.languages.get_source_languages())
    target_languages=[Languages.HI_IN],  # list of Languages, e.g. [Languages.HI_IN, Languages.FR_FR]
    transcription_mode="fast",
)
task_id = response.task_id
print(f"Dub Task created with ID: {task_id}")

while True:
    status_response = client.dub.get_dubbing_status(task_id=task_id)
    print(f"Current Status: {status_response.status}")
    if status_response.status == "SUCCESS":
        dubbed_run_info = client.dub.get_dubbed_run_info(run_id=status_response.run_id)
        print(f"Audio URL: {dubbed_run_info.audio_url}")
        print(f"Transcript: {dubbed_run_info.transcript}")
        print(f"Video URL: {dubbed_run_info.video_url}")
        break
    time.sleep(5)
```

```javascript TypeScript theme={null}
import { CambClient, CambApi } from '@camb-ai/sdk';

const client = new CambClient({
    apiKey: process.env.CAMB_API_KEY
});

async function dubVideo() {
    // Step 1: Submit the dubbing job
    const response = await client.dub.endToEndDubbing({
        video_url: 'your_accessible_video_url',
        source_language: CambApi.Languages.EN_US,
        target_languages: [CambApi.Languages.HI_IN], // pass an array, e.g. [HI_IN, FR_FR]
        transcription_mode: 'fast'
    });

    const taskId = response.task_id;
    console.log(`Dub Task created with ID: ${taskId}`);

    // Step 2: Poll until complete
    while (true) {
        const statusResponse = await client.dub.getEndToEndDubbingStatus({
            task_id: taskId
        });
        console.log(`Current Status: ${statusResponse.status}`);

        if (statusResponse.status === 'SUCCESS') {
            const dubbedRunInfo = await client.dub.getDubbedRunInfo({
                run_id: statusResponse.run_id
            });
            console.log(`Audio URL: ${dubbedRunInfo.audio_url}`);
            console.log(`Transcript: ${dubbedRunInfo.transcript}`);
            console.log(`Video URL: ${dubbedRunInfo.video_url}`);
            break;
        }

        await new Promise(resolve => setTimeout(resolve, 5000));
    }
}

dubVideo();
```

***

## Use Your Own SRT Transcript or Translation (Python)

Supply an original-language transcript with `source_transcript`, translated
dialogue with `target_transcripts`, or both. Read local `.srt` files as UTF-8 and
send their **contents**, not paths, URLs, base64 strings, or segment arrays.

> [!NOTE]
>
> This example requires a Python SDK release containing `DubSRTInput` and
> `DubTargetSRTInput` ([SDK change](https://github.com/Camb-ai/cambai-python-sdk/pull/44))
> and an API deployment supporting custom SRT input. If these imports are unavailable,
> check the SDK release before running this example. The example below is Python-only;
> it does not assume matching TypeScript SDK support.

Save these files beside your script, using timestamps that match your source video:

```text original.srt theme={null}
1
00:00:01,000 --> 00:00:03,000
Hello, and welcome to our demo.
```

```text spanish.srt theme={null}
1
00:00:01,000 --> 00:00:03,000
Hola, bienvenidos a nuestra demostración.
```

Set `CAMB_API_KEY` and replace the video URL with your publicly accessible media.
This example submits both files, polls for up to ten minutes, and retrieves the result:

```python Python theme={null}
import os
import time
from pathlib import Path

from camb import DubSRTInput, DubTargetSRTInput
from camb.client import CambAI
from camb.errors import UnprocessableEntityError
from camb.types.language_enums import Languages

client = CambAI(api_key=os.environ["CAMB_API_KEY"])

try:
    response = client.dub.create_dub(
        video_url="https://example.com/your-video.mp4",
        source_language=Languages.EN_US,
        target_languages=[Languages.ES_ES],
        source_transcript=DubSRTInput(
            content=Path("original.srt").read_text(encoding="utf-8"),
        ),
        target_transcripts=[
            DubTargetSRTInput(
                language=Languages.ES_ES,
                content=Path("spanish.srt").read_text(encoding="utf-8"),
            )
        ],
    )
except UnprocessableEntityError as exc:
    print("Invalid dubbing input:", exc.body.detail)
    raise

print(f"Dub task: {response.task_id}")
deadline = time.monotonic() + 600
while time.monotonic() < deadline:
    status = client.dub.get_dubbing_status(task_id=response.task_id)
    if status.status == "SUCCESS":
        if status.run_id is None:
            raise RuntimeError("Completed task returned no run ID")
        result = client.dub.get_dubbed_run_info(run_id=status.run_id)
        print(f"Audio URL: {result.audio_url}")
        print(f"Video URL: {result.video_url}")
        print(f"Transcript: {result.transcript}")
        break
    if status.status == "ERROR":
        raise RuntimeError(f"Dubbing failed: {status.exception_reason}")
    time.sleep(5)
else:
    raise TimeoutError(
        f"Still processing task {response.task_id}; resume polling instead of submitting again"
    )
```

* For a custom transcript only, omit `target_transcripts`; translations are generated automatically.
* For custom translations only, omit `source_transcript`. Include it when available to provide source-language context.
* For multiple translations, add one `DubTargetSRTInput` per language and include each language in `target_languages`, using `Languages` enums throughout. Targets without a supplied translation use automatic translation.
* Omit both fields to retain the automatic dubbing workflow. The same input arguments work with `AsyncCambAI`.

`format` defaults to `"srt"`. The API validates SRT parsing and requires at least
one cue, with limits of 2 MiB UTF-8 per script, 10 MiB combined, and 100 target
scripts. Target languages must be unique and included in `target_languages`.
Overlapping and out-of-order cues are allowed. API validation failures raise
`UnprocessableEntityError` (HTTP 422); `exc.body.detail` identifies the invalid fields.
See the [dubbing API reference](https://docs.camb.ai/api-reference/endpoint/end-to-end-dubbing.md) for the request contract.

***

## Parameters

### Required

| Parameter | Type | Description |
| - | - | - |
| `video_url` | string | Publicly accessible URL of the source video (YouTube links and direct URLs are supported) |
| `source_language` | `Languages` enum | Language spoken in the source video |
| `target_languages` | `Languages[]` | List of languages to dub into. Pass a single-element list (`[Languages.HI_IN]`) for one target, or multiple to dub into several languages in a single job. |

### Optional

| Parameter | Type | Description |
| - | - | - |
| `target_language` | `Languages` enum | Single-language convenience alternative to `target_languages`. Prefer `target_languages=[Languages.HI_IN]` — `target_language` exists for backwards compatibility. |
| `project_name` | string | Label for the job in your dashboard |
| `project_description` | string | Additional notes for the job |
| `selected_audio_tracks` | integer\[] | Specific audio track indices from the source video |
| `add_output_as_an_audio_track` | boolean | Attach the dubbed audio as an extra track instead of replacing the original |
| `source_transcript` | `DubSRTInput` (Python) | Original-language SRT contents; optional `format` defaults to `"srt"`. |
| `target_transcripts` | `list[DubTargetSRTInput]` (Python) | Translated SRT contents, at most one per requested target language. Use `Languages` enums for `language`. |

### Language Enum

Use the `Languages` enum (Python) or `CambApi.Languages` (TypeScript) to specify languages:

```python Python theme={null}
from camb.types.language_enums import Languages

# Examples
Languages.EN_US   # English (US)
Languages.ES_ES   # Spanish (Spain)
Languages.FR_FR   # French
Languages.DE_DE   # German
Languages.HI_IN   # Hindi
Languages.JA_JP   # Japanese
Languages.ZH_CN   # Chinese (Simplified)
```

```javascript TypeScript theme={null}
import { CambApi } from '@camb-ai/sdk';

// Examples
CambApi.Languages.EN_US   // English (US)
CambApi.Languages.ES_ES   // Spanish (Spain)
CambApi.Languages.FR_FR   // French
CambApi.Languages.DE_DE   // German
CambApi.Languages.HI_IN   // Hindi
CambApi.Languages.JA_JP   // Japanese
CambApi.Languages.ZH_CN   // Chinese (Simplified)
```

***

## Tips

* **Video URL:** The URL must be publicly accessible. YouTube video links and direct file URLs (MP4, WebM) are both supported.
* **Polling timeout:** For long videos, cap your polling loop (e.g. 60 attempts × 5s = 5 minutes) and handle the timeout gracefully.
* **Multiple targets:** `target_languages` accepts an array — pass several languages to dub into all of them in a single job, which is more efficient than submitting separate jobs.
* **Transcripts:** The result object includes a `transcript` field with per-segment timing data, useful for subtitle generation.

***

## Next Steps

> [card] [End-to-End Dubbing API](https://docs.camb.ai/api-reference/endpoint/end-to-end-dubbing.md)
>
> Full API reference for the dubbing endpoint.

> [card] [Get Dubbing Status](https://docs.camb.ai/api-reference/endpoint/get-end-to-end-dubbing-status.md)
>
> Status polling endpoint reference.

> [card] [Get Dubbed Run Info](https://docs.camb.ai/api-reference/endpoint/get-dubbed-run-info.md)
>
> Retrieve the dubbed output URLs and transcript.

> [card] [Voice Cloning](https://docs.camb.ai/tutorials/voice-cloning.md)
>
> Clone a custom voice for use in speech generation.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.