Dubbing quickstart

Learn how to dub audio and video files across languages using the Dubbing API.

This guide shows you how to dub a media file into another language with the Dubbing API. In this example you create a dubbing project from an English audio file and generate a Spanish dub.

A dubbing project has two parts: a project, which holds one source of media and its transcript, and one or more language targets, each producing a dubbed output in a single language. You create a project, wait for its source to be transcribed, add a language, then download the finished dub.

Using the Dubbing API

1

Create an API key

Create an API key in the dashboard here, which you’ll use to securely access the API.

Store the key as a managed secret and pass it to the SDKs either as a environment variable via an .env file, or directly in your app’s configuration depending on your preference.

.env
1ELEVENLABS_API_KEY=<your_api_key_here>
2

Install the SDK

We’ll also use the dotenv library to load our API key from an environment variable.

1pip install elevenlabs
2pip install python-dotenv

The Python example uses the requests library to download the dubbed audio. Install it with pip install requests.

3

Make the API request

Create a new file named example.py or example.mts, depending on your language of choice, and add the following code:

1# example.py
2import os
3import time
4import requests
5from dotenv import load_dotenv
6from elevenlabs.client import ElevenLabs
7
8load_dotenv()
9
10elevenlabs = ElevenLabs(
11 api_key=os.getenv("ELEVENLABS_API_KEY"),
12)
13
14# 1. Create a project from a source URL
15project = elevenlabs.dubbing.project.create(
16 source_url="https://storage.googleapis.com/eleven-public-cdn/audio/marketing/nicole.mp3",
17 source_language="en",
18 reference="Quickstart dub",
19)
20
21# 2. Wait for the source media to be transcribed
22while True:
23 project = elevenlabs.dubbing.project.get(project.project_id)
24 if project.status == "ready":
25 break
26 if project.status == "failed":
27 raise RuntimeError("Project preparation failed")
28 print("Preparing project...")
29 time.sleep(5)
30
31# 3. Add a Spanish language target
32language = elevenlabs.dubbing.project.language.create(
33 project.project_id,
34 target_language="es",
35)
36
37# 4. Wait for the dub to finish generating
38while True:
39 language = elevenlabs.dubbing.project.language.get(
40 project.project_id, language.language_id
41 )
42 if language.status == "completed":
43 break
44 if language.status == "failed":
45 raise RuntimeError("Dub generation failed")
46 print("Generating dub...")
47 time.sleep(5)
48
49# 5. Download the dubbed audio from the signed URL
50audio = requests.get(language.outputs.lossless_audio)
51with open("dubbed.wav", "wb") as f:
52 f.write(audio.content)
53
54print("Saved dubbed audio to dubbed.wav")

The download URL in outputs.lossless_audio is signed and expires about an hour after it is issued. Fetch the language again to get a fresh URL if it has expired.

4

Execute the code

1python example.py

The dubbed audio is saved to dubbed.wav in your working directory.

Enterprise workspaces can review and correct the source transcript before adding a language, which produces more accurate translations. See Refine and regenerate a dub.

Next steps