Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.mavera.io/llms.txt

Use this file to discover all available pages before exploring further.

Scenario

Take Mavera-generated scripts and use ElevenLabs’ dubbing API to create localized versions in multiple languages, supporting global marketing campaigns without manual translation. Flow: Mavera POST /generations (English script) → ElevenLabs TTS → POST /v1/dubbing → Poll → Download per language

Code

import os, requests, time

EL_KEY = os.environ["ELEVENLABS_API_KEY"]
EL_BASE = "https://api.elevenlabs.io/v1"
MV = os.environ["MAVERA_API_KEY"]
MV_BASE = "https://app.mavera.io/api/v1"
MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}
os.makedirs("localized_audio", exist_ok=True)

LANGS = ["es", "fr", "de", "ja", "pt"]

# 1. Generate English script → source audio
gen = requests.post(f"{MV_BASE}/generations", headers=MV_H, json={
    "prompt": "Write a 45-second marketing video script for a SaaS analytics platform. "
        "Energetic, professional tone. Hook, three key benefits, CTA.",
}).json()
script = gen.get("output") or gen.get("content") or ""
print(f"English script: {len(script.split())} words")

tts = requests.post(f"{EL_BASE}/text-to-speech/21m00Tcm4TlvDq8ikWAM",
    headers={"xi-api-key": EL_KEY, "Content-Type": "application/json"},
    json={"text": script, "model_id": "eleven_multilingual_v2",
          "voice_settings": {"stability": 0.5, "similarity_boost": 0.75}})
with open("localized_audio/source_en.mp3", "wb") as f: f.write(tts.content)
print(f"Source audio: {len(tts.content) // 1024} KB")
time.sleep(2)

# 2. Dub into each target language
for lang in LANGS:
    with open("localized_audio/source_en.mp3", "rb") as af:
        dub = requests.post(f"{EL_BASE}/dubbing", headers={"xi-api-key": EL_KEY},
            data={"target_lang": lang, "source_lang": "en", "num_speakers": "1", "watermark": "false"},
            files={"file": ("source.mp3", af, "audio/mpeg")}).json()
    dubbing_id = dub["dubbing_id"]
    print(f"\n[{lang}] Dubbing ID: {dubbing_id}")

    # 3. Poll for completion
    for attempt in range(60):
        time.sleep(5)
        st = requests.get(f"{EL_BASE}/dubbing/{dubbing_id}", headers={"xi-api-key": EL_KEY}).json()
        if st.get("status") == "dubbed":
            dl = requests.get(f"{EL_BASE}/dubbing/{dubbing_id}/audio/{lang}", headers={"xi-api-key": EL_KEY})
            path = f"localized_audio/script_{lang}.mp3"
            with open(path, "wb") as f: f.write(dl.content)
            print(f"  Saved: {path} ({len(dl.content) // 1024} KB, {(attempt+1)*5}s)")
            break
        elif st.get("status") == "failed":
            print(f"  Failed: {st.get('error')}"); break
    time.sleep(3)

Example Output

English script: 118 words → source audio: 164 KB
[es] dub_9a2f7c3d → script_es.mp3 (172 KB, 35s)
[fr] dub_4b8e1f6a → script_fr.mp3 (178 KB, 40s)
[de] dub_7d3a9c2e → script_de.mp3 (169 KB, 30s)
[ja] dub_2e6b4d8f → script_ja.mp3 (151 KB, 55s)
[pt] dub_5c1a3e7d → script_pt.mp3 (175 KB, 45s)

Error Handling

ElevenLabs supports 29+ languages. Check supported languages before submitting. Unsupported codes return 400. Common: es, fr, de, ja, pt, zh, ko.
Processing scales with audio length — 45 seconds typically completes in 30–60s. Content over 5 minutes can take several minutes. If polling times out, check status manually.
Dubbing works best with clean, single-speaker audio at 44.1kHz+. Background music or multiple speakers degrade output. Pre-process noisy audio before submitting.