ai newsFr., 23. Okt.
EilmeldungGooglebook Puts Gemini at the Cursor With Magic Pointer and Built-In AI Workflows

Create an AI Podcast Generator with ElevenLabs

Why an AI‑Powered Podcast? Podcasts have exploded in popularity, but producing them is still a manual, time‑consuming process. You have to write a script, record the audio, edit out mistakes, and finally publish the episode. What if you could automate most of that pipeline with a few lines of code?

dev.toFreitag 19:36 · 23.10.7 Min. Lesezeit
Bild: dev.to

Podcasts have exploded in popularity, but producing them is still a manual, time‑consuming process. You have to write a script, record the audio, edit out mistakes, and finally publish the episode. What if you could automate most of that pipeline with a few lines of code?

With modern text‑to‑speech (TTS) models, you can generate natural‑sounding narration in seconds. Combine that with a script generator (ChatGPT, Claude, or any LLM you prefer) and you have the makings of an AI podcast generator that can churn out episodes on demand.

In this article I’ll walk you through a simple, end‑to‑end workflow that:

The star of the TTS show is ElevenLabs, a platform that offers realistic voice cloning and a generous free tier. You can sign up via my affiliate link: https://try.elevenlabs.io/kr07zfuqn1bp – it’s the same link I’ll embed throughout the tutorial.

# Install the required Python packages pip install openai requests tqdm Enter fullscreen mode Exit fullscreen mode 1. Generating the Podcast Script First, let’s get a short script from an LLM. The following function uses OpenAI’s gpt-4o-mini model, but you can swap it for Claude, Gemini, etc.

import openai def generate_script ( topic: str, length_minutes: int = 5 ) -> str: prompt = f """ You are a podcast host. Write a { length_minutes } -minute script about " { topic } ". Include an intro, three main talking points, and a short outro. Keep the tone conversational and engaging. """ response = openai. ChatCompletion. create ( model = " gpt-4o-mini ", messages = [{ " role ": " user ", " content ": prompt }], temperature = 0.7, max_tokens = 800, ) return response. choices [ 0 ]. message. content. strip () Enter fullscreen mode Exit fullscreen mode Usage

topic = " The future of AI in education " script = generate_script ( topic ) print ( script ) Enter fullscreen mode Exit fullscreen mode You now have a ready‑to‑read script in plain text.

ElevenLabs provides a straightforward HTTP API. Below is a thin wrapper that sends the script and streams back an MP3 file.

import requests from pathlib import Path from tqdm import tqdm ELEVENLABS_API_KEY = " YOUR_ELEVENLABS_API_KEY " VOICE_ID = " 21m00Tcm4TlvDq8ikWAM " # Default "Rachel" voice – you can create your own clone def synthesize_speech ( text: str, output_path: Path ) -> None: url = f " https://api.elevenlabs.io/v1/text-to-speech/ { VOICE_ID } " headers = { " xi-api-key ": ELEVENLABS_API_KEY, " Content-Type ": " application/json ", } payload = { " text ": text, " model_id ": " eleven_monolingual_v1 ", " voice_settings ": { " stability ": 0.75, " similarity_boost ": 0.85, }, } # Stream the response so we can show a progress bar with requests. post ( url, json = payload, headers = headers, stream = True ) as r: r. raise_for_status () total = int ( r. headers. get ( " content-length ", 0 )) with open ( output_path, " wb " ) as f, tqdm ( total = total, unit = " B ", unit_scale = True, desc = " Downloading audio " ) as pbar: for chunk in r. iter_content ( chunk_size = 8192 ): if chunk: f. write ( chunk ) pbar. update ( len ( chunk )) # Example call output_file = Path ( " episode_01.mp3 " ) synthesize_speech ( script, output_file ) print ( f " Saved audio to { output_file } " ) Enter fullscreen mode Exit fullscreen mode Pro tip: If you want a custom voice that sounds like you, ElevenLabs lets you upload a few minutes of reference audio and creates a clone in under an hour. Check out the voice‑cloning docs after you’ve tried the default voice.

A polished podcast often has a short music bed. With ffmpeg you can prepend or append an MP3 file.

# Install ffmpeg (if you haven't already) # macOS: brew install ffmpeg # Ubuntu: sudo apt-get install ffmpeg Enter fullscreen mode Exit fullscreen mode import subprocess def add_music ( base_audio: Path, intro: Path, outro: Path, final_output: Path ) -> None: # Build the ffmpeg command cmd = [ " ffmpeg ", " -y ", # overwrite output if it exists " -i ", str ( intro ), " -i ", str ( base_audio ), " -i ", str ( outro ), " -filter_complex ", " [0:a][1:a][2:a]concat=n=3:v=0:a=1[out] ", " -map ", " [out] ", str ( final_output ), ] subprocess. run ( cmd, check = True ) # Example usage intro_mp3 = Path ( " intro.mp3 " ) outro_mp3 = Path ( " outro.mp3 " ) final_mp3 = Path ( " episode_01_full.mp3 " ) add_music ( output_file, intro_mp3, outro_mp3, final_mp3 ) print ( f " Final episode ready: { final_mp3 } " ) Enter fullscreen mode Exit fullscreen mode Now you have a complete episode file that you can upload to Anchor, Libsyn, or any hosting platform.

Putting everything together into a single script makes it easy to generate a new episode with just one command.

import argparse def main (): parser = argparse. ArgumentParser ( description = " AI Podcast Generator " ) parser. add_argument ( " topic ", help = " Topic for the episode " ) parser. add_argument ( " --minutes ", type = int, default = 5, help = " Target length " ) parser. add_argument ( " --output ", default = " episode.mp3 ", help = " Output file name " ) args = parser. parse_args () # Step 1 – Script script = generate_script ( args. topic, args. minutes ) print ( " \n --- SCRIPT --- \n " ) print ( script ) # Step 2 – TTS temp_audio = Path ( " temp.wav " ) synthesize_speech ( script, temp_audio ) # Step 3 – Optional music intro = Path ( " intro.mp3 " ) outro = Path ( " outro.mp3 " ) if intro. exists () and outro. exists (): add_music ( temp_audio, intro, outro, Path ( args. output )) else: temp_audio. rename ( Path ( args. output )) print ( f " \n ✅ Episode saved to { args. output } " ) if __name__ == " __main__ ": main () Enter fullscreen mode Exit fullscreen mode Run it like:

python ai_podcast.py "How quantum computing will change cryptography" --minutes 7 --output quantum_ep.mp3 Enter fullscreen mode Exit fullscreen mode And you’ll have a 7‑minute, fully‑voiced episode ready for distribution.

If you want to produce a series, just feed a list of topics into the script. You can also parallelize the TTS calls (ElevenLabs allows up to 10 concurrent requests on paid plans). Here’s a quick concurrent.futures example:

from concurrent.futures import ThreadPoolExecutor topics = [ " AI in healthcare ", " Edge computing trends ", " Ethics of synthetic media " ] with ThreadPoolExecutor ( max_workers = 3 ) as executor: futures = [ executor. submit ( lambda t: synthesize_speech ( generate_script ( t ), Path ( f " { t }.mp3 " )), topic, ) for topic in topics ] for f in futures: f. result () # re‑raise any exception Enter fullscreen mode Exit fullscreen mode Now you can spin up a whole mini‑season in under an hour.

If you haven’t tried it yet, I highly recommend signing up through this link: https://try.elevenlabs.io/kr07zfuqn1bp. The free tier gives you 10 k characters per month, which is plenty for a few test episodes.

You can build a fully automated podcast generator with just a few Python functions: generate a script with an LLM, synthesize it using ElevenLabs’ high‑quality TTS, optionally add music with ffmpeg, and output a ready‑to‑publish MP3. The whole pipeline is lightweight, cheap, and scales nicely.

The code snippets above are a starting point—feel free to tweak the voice settings, experiment with different LLM prompts, or add more post‑processing steps. When you’re ready, head over to ElevenLabs via my affiliate link and grab your API key: https://try.elevenlabs.io/kr07zfuqn1bp.

Happy coding, and may your AI‑generated podcasts fill the airwaves!

Quelle: dev.to (dev.to). Original öffnen