Create an AI Podcast Generator with ElevenLabs
本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。
Create an AI Podcast Generator with ElevenLabs
使用 ElevenLabs 创建 AI 播客生成器
Why an AI‑Powered Podcast? Podcasts have exploded in popularity, but producing a full episode still means spending hours on research, script‑writing, recording, and editing. What if you could automate the whole pipeline? By combining a large‑language model (LLM) for content generation with a state‑of‑the‑天才 text‑to‑speech (TTS) service, you can spin up a fully voiced episode in minutes.
为什么选择 AI 驱动的播客?播客的受欢迎程度呈爆炸式增长,但制作一期完整的节目仍然意味着需要花费数小时进行研究、撰写脚本、录音和剪辑。如果能将整个流程自动化会怎样?通过将用于内容生成的大语言模型 (LLM) 与最先进的文本转语音 (TTS) 服务相结合,你可以在几分钟内生成一期配音完整的节目。
In this guide we’ll build a simple AI Podcast Generator that: Takes a topic prompt, asks an LLM (e.g., OpenAI’s gpt‑4o) to write a short script. Sends each paragraph to ElevenLabs – a high‑quality TTS platform that supports voice cloning. Concatenates the audio files into a single MP3 ready for publishing. Everything is done with plain Python and a few command‑line tools, so you can drop it into a CI job, a serverless function, or your local dev environment.
在本指南中,我们将构建一个简单的 AI 播客生成器,它可以:接收主题提示,要求 LLM(例如 OpenAI 的 gpt-4o)编写简短脚本。将每个段落发送给 ElevenLabs——一个支持语音克隆的高质量 TTS 平台。将音频文件合并为可供发布的单个 MP3。所有操作均使用纯 Python 和几个命令行工具完成,因此你可以将其放入 CI 作业、无服务器函数或本地开发环境中。
Prerequisites
前置要求
What you need: Python 3.9+ (Core language for the script), OpenAI API key (Generates the podcast script), ElevenLabs API key (Turns text into lifelike speech), ffmpeg (Merges multiple audio chunks into one file), Git (optional, version-control the project). If you don’t have an ElevenLabs account yet, grab a free trial through this affiliate link: https://try.elevenlabs.io/kr07zfuqn1bp. It gives you 10 k characters of TTS credit and access to a handful of premium voices.
你需要:Python 3.9+(脚本的核心语言)、OpenAI API 密钥(生成播客脚本)、ElevenLabs API 密钥(将文本转换为逼真的语音)、ffmpeg(将多个音频片段合并为一个文件)、Git(可选,用于项目版本控制)。如果你还没有 ElevenLabs 账户,可以通过此联盟链接获取免费试用:https://try.elevenlabs.io/kr07zfuqn1bp。它提供 10k 字符的 TTS 额度以及对部分高级语音的使用权限。
1. Get Your API Keys
1. 获取你的 API 密钥
Save your keys as environment variables (never hard‑code them!):
export OPENAI_API_KEY="sk-..."
export ELEVENLABS_API_KEY="your-elevenlabs-key"
Both services use bearer tokens in the Authorization header, so keeping them in the environment is the safest approach.
将你的密钥保存为环境变量(切勿硬编码!):
export OPENAI_API_KEY="sk-..."
export ELEVENLABS_API_KEY="your-elevenlabs-key"
这两项服务都在 Authorization 请求头中使用 bearer 令牌,因此将它们保存在环境中是最安全的方法。
2. Generate a Podcast Script
2. 生成播客脚本
Below is a minimal wrapper around the OpenAI chat completion endpoint. It accepts a topic and returns a concise script split into paragraphs. Tip: Adjust temperature for more creative vs. deterministic output. For a news‑style podcast you might set it lower (0.3).
以下是围绕 OpenAI 聊天补全端点的最小封装。它接受一个主题并返回一个分为段落的简洁脚本。提示:调整 temperature 参数以获得更具创造性或更确定的输出。对于新闻风格的播客,你可以将其设置得更低(0.3)。
3. Turn Text into Speech with ElevenLabs
3. 使用 ElevenLabs 将文本转换为语音
ElevenLabs provides a clean REST API that accepts plain text and returns an MP3 buffer. You can experiment with different voice IDs or even upload a custom cloned voice through ElevenLabs’ dashboard. For a truly branded podcast, clone the voice of your host and reference it here – the same API call works with the cloned voice’s ID.
ElevenLabs 提供了一个简洁的 REST API,它接受纯文本并返回 MP3 缓冲区。你可以尝试不同的语音 ID,甚至可以通过 ElevenLabs 的仪表板上传自定义的克隆语音。为了打造真正的品牌播客,请克隆你主持人的声音并在此处引用——相同的 API 调用同样适用于克隆语音的 ID。
4. Stitch the Segments Together
4. 将片段拼接在一起
ffmpeg makes concatenation painless. First, write a temporary file list, then run the command. The script uses subprocess to execute the merge and cleans up the temporary files afterward.
ffmpeg 让拼接变得轻松简单。首先,编写一个临时文件列表,然后运行命令。该脚本使用 subprocess 执行合并,并在之后清理临时文件。
5. The Full Pipeline
5. 完整流程
Putting everything together, the create_podcast function orchestrates the generation, synthesis, and combination steps. Run it like: python podcast.py "The future of quantum computing" episode1.mp3. You’ll end up with an MP3 that sounds like a professional host, ready to upload to Spotify, Apple Podcasts, or any platform you prefer.
将所有内容整合在一起,create_podcast 函数负责协调生成、合成和合并步骤。运行方式如下:python podcast.py "The future of quantum computing" episode1.mp3。你最终将得到一个听起来像专业主持人的 MP3 文件,随时可以上传到 Spotify、Apple Podcasts 或你喜欢的任何平台。
6. Going Further
6. 进阶思路
Ideas include implementing dynamic intros/outros using ffmpeg, using the /v1/voices/add endpoint for custom voice cloning, batch generation by looping over a CSV of topics, saving transcripts as metadata, or creating multilingual episodes by passing non-English text to ElevenLabs.
进阶思路包括:使用 ffmpeg 实现动态片头/片尾,使用 /v1/voices/add 端点进行自定义语音克隆,通过循环遍历 CSV 主题列表进行批量生成,将脚本保存为元数据,或者通过向 ElevenLabs 传递非英语文本来创建多语言节目。