In this categoryAudio & Music ยท 25
- How to Create Your First Original Song in SunoStart
- How to Write Original Lyrics with an AI Chatbot to Use in Suno
- How to Generate Your First Original Track in Udio
- How to Make an Instrumental With No Vocals in Suno
- How to Write Style Prompts That Nail the Genre and Mood
- How to Control Song Structure with Section Tags in Suno and Udio
- How to Extend a Short Clip into a Full Song in Udio
- How to Check Licensing and Share Your AI Songs Safely
- How to Use Suno Covers on Your Own Recording Without Copyright Risk
- How to Download Stems from Suno and Mix Them in a DAW
- How to Replace AI Vocals with Your Own Voice on a Suno or Udio Track
- How to Make Your First Text-to-Speech Voiceover in ElevenLabs
- How to Clone Your Own Voice with Instant Voice Cloning
- How to Turn a Blog Article into a Narrated Podcast with ElevenLabs
- How to Design a Custom Voice from a Text Prompt in ElevenLabs
- How to Dub a Video into Another Language with ElevenLabs Dubbing
- How to Tune Stability and Similarity for Better-Sounding Voiceovers
- How to Produce a Multi-Speaker Podcast Episode in ElevenLabs Studio
- How to Fix Mispronounced Words and Names in ElevenLabs
- How to Generate Speech Programmatically with the ElevenLabs API
- How to Batch-Narrate Many Video Scripts with the ElevenLabs API
How to Batch-Narrate Many Video Scripts with the ElevenLabs API
Loop over a folder of script files and generate one voiceover MP3 per file with a single Python script.
If you publish a lot of short videos, generating each voiceover by hand is slow. With the API you can drop every script into a folder and produce all the MP3s in one run. This guide builds a small Python batch script that reads text files and writes matching audio files.
What you need
- An ElevenLabs API key in an environment variable
- Python 3 with the requests library installed
- A folder of plain-text scripts, one file per video
- A chosen voice ID
Step 1: Organize your scripts
Put each video's script in its own .txt file inside a scripts folder. The output file will reuse the script's name, so name them clearly, for example video-01.txt produces video-01.mp3.
Step 2: Write the batch script
The script lists every .txt file, sends each one to the Text to Speech endpoint, and saves the audio with a matching name. It skips files that already have an MP3 so reruns do not waste quota.
import os, glob, requests
VOICE_ID = "21m00Tcm4TlvDq8ikWAM"
API_KEY = os.environ["ELEVENLABS_API_KEY"]
URL = f"https://api.elevenlabs.io/v1/text-to-speech/{VOICE_ID}"
os.makedirs("audio", exist_ok=True)
for path in sorted(glob.glob("scripts/*.txt")):
name = os.path.splitext(os.path.basename(path))[0]
out = f"audio/{name}.mp3"
if os.path.exists(out):
print(f"skip {name} (already done)")
continue
with open(path, encoding="utf-8") as f:
text = f.read().strip()
resp = requests.post(
URL,
headers={"xi-api-key": API_KEY, "Content-Type": "application/json"},
json={"text": text, "model_id": "eleven_multilingual_v2"},
)
resp.raise_for_status()
with open(out, "wb") as f:
f.write(resp.content)
print(f"done {name}")Step 3: Run it
Run the script from your project root. It prints progress per file and leaves the finished MP3s in the audio folder. If it stops on an error, the already-done files are kept so you can rerun safely.
Result: a single command turns a folder of scripts into a folder of finished voiceovers, ready to pair with your video edits.
Ready to try it yourself? Get set up withElevenLabsin a few minutes.(affiliate link. We may earn a commission at no extra cost. Disclosure)
Watch related tutorials
12:45
12:48
10:22
14:20
18:30
23:00New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.