零基础教程:打造你的个人AI播客——Whisper+TTS全流程实战
为什么你需要一个AI播客
想象这个场景:你每天通勤路上读长文章、看技术文档、刷新闻——但眼睛已经够累了。如果能把这些文字自动转成播客音频,通勤时听、健身时听、睡前听,信息摄入效率至少翻倍。

本教程带你用OpenAI Whisper(语音转文字)和Edge TTS(文字转语音)搭建一个私人AI播客系统。全程不超过80行代码,零基础也能跟着做。
环境准备
首先安装必要的依赖:
pip install openai-whisper edge-tts pydub ffmpeg-python⚠️ Whisper首次运行时会自动下载模型文件(约1.5GB),请确保网络畅通。
第一步:文字转语音(核心功能)
创建 `tts_engine.py`,这是我们播客的”嘴巴”:
import asyncio
import edge_tts
async def text_to_speech(text, output_file, voice="zh-CN-XiaoxiaoNeural"):
"""
将文字转为语音文件
voice参数可选(中文):
zh-CN-XiaoxiaoNeural — 女声(活泼)
zh-CN-YunxiNeural — 男声(沉稳)
zh-CN-XiaoyiNeural — 女声(温柔)
zh-CN-YunjianNeural — 男声(播报风格)
"""
communicate = edge_tts.Communicate(text, voice)
await communicate.save(output_file)
print(f"[TTS完成] 已保存到 {output_file}")
# 测试
async def main():
await text_to_speech(
"欢迎来到LC智趣厅的AI播客。今天我们来聊聊最近大火的达摩院超导AI。",
"podcast_intro.mp3"
)
asyncio.run(main())运行测试:
python3 tts_engine.py你会得到一个自然流畅的中文语音文件 `podcast_intro.mp3`。
第二步:语音转文字(辅助功能)
创建 `transcriber.py`,这是播客的”耳朵”——当你需要把会议录音、访谈素材转成文字稿时使用:
import whisper
def transcribe_audio(audio_path, model_size="base"):
"""
语音转文字
model_size: tiny(最快)/base/medium/large(最准)
"""
model = whisper.load_model(model_size)
result = model.transcribe(audio_path, language="zh")
return result["text"]
# 测试
text = transcribe_audio("meeting_recording.mp3")
print(f"[转写结果] {text[:200]}...")💡 `base` 模型在中文识别上已经相当准确,`medium` 和 `large` 会更好但更慢。日常使用 `base` 足够了。
第三步:播客生成器(组装)
创建 `podcast_maker.py`,把所有功能串起来:
import asyncio
import edge_tts
import os
from pydub import AudioSegment
class PodcastMaker:
def __init__(self, voice="zh-CN-YunjianNeural"):
self.voice = voice # 默认播报风格男声
async def _tts(self, text, filename):
"""内部TTS方法"""
comm = edge_tts.Communicate(text, self.voice)
await comm.save(filename)
async def create_episode(self, title, sections, output_file):
"""
生成一期播客
title: 播客标题
sections: [{"heading": "段落标题", "body": "段落正文"}, ...]
output_file: 输出文件路径
"""
temp_files = []
# 1. 片头
intro = f"欢迎收听LC智趣厅AI播客。本期主题:{title}。"
await self._tts(intro, "temp_00.mp3")
temp_files.append("temp_00.mp3")
# 2. 逐段生成
for i, sec in enumerate(sections, 1):
body_text = f"{sec['heading']}。{sec['body']}"
filename = f"temp_{i:02d}.mp3"
await self._tts(body_text, filename)
temp_files.append(filename)
print(f" [{i}/{len(sections)}] {sec['heading']} - 完成")
# 3. 片尾
outro = "感谢收听。关注LC智趣厅,我们下期再见。"
await self._tts(outro, "temp_99.mp3")
temp_files.append("temp_99.mp3")
# 4. 合并所有音频
combined = AudioSegment.empty()
for tf in temp_files:
combined += AudioSegment.from_mp3(tf)
# 段落间加1秒静音
combined += AudioSegment.silent(duration=1000)
combined.export(output_file, format="mp3", bitrate="128k")
print(f"\n[播客生成完成] {output_file}")
# 5. 清理临时文件
for tf in temp_files:
os.remove(tf)
async def main():
maker = PodcastMaker(voice="zh-CN-YunjianNeural")
await maker.create_episode(
title="达摩院AI发现4种全新超导材料",
sections=[
{
"heading": "AI改写材料科学规则",
"body": "7月3日,阿里达摩院发布了ElementsClaw智能体,一口气预测出6.8万种超导材料。"
"过去百年,人类仅发现了两千种。这个AI一天之内把数量提升了三十倍。",
},
{
"heading": "为什么这件事影响深远",
"body": "超导材料一旦实现室温化,将彻底改变电力传输、量子计算和磁悬浮交通。"
"达摩院已将全部数据开源,供全球科学家自由挖掘。",
},
{
"heading": "AI for Science的时代来了",
"body": "AI不再只是辅助工具,而是正在成为科学发现的第一性原理引擎。"
"从预测材料到设计实验,AI正在成为科学家的第二大脑。",
},
],
output_file="episode_001.mp3",
)
asyncio.run(main())运行:
python3 podcast_maker.py一分钟不到,你就会得到一个完整的播客音频文件 `episode_001.mp3`。
第四步:自动化内容源
想让播客自动更新?加一个内容抓取模块:
import requests
def fetch_news_headlines():
"""从RSS源获取新闻标题"""
# 示例:使用简单的RSS解析
import xml.etree.ElementTree as ET
url = "https://www.ithome.com/rss/"
resp = requests.get(url)
root = ET.fromstring(resp.content)
items = []
for item in root.iter("item"):
title = item.find("title").text
desc = item.find("description").text
items.append({"heading": title, "body": desc[:200]})
if len(items) >= 5:
break
return items配合cron定时任务,你可以每天早上8点自动生成一期AI新闻播报。
小结
不到80行核心代码,你拥有了一个完整的AI播客系统:
– ✅ 文字转语音(Edge TTS,免费)
– ✅ 语音转文字(OpenAI Whisper)
– ✅ 自动分段、合并、配乐
– ✅ 可扩展的新闻自动化
**下一步**:试试把 `voice` 换成 `zh-CN-XiaoxiaoNeural`(活泼女声),看看不同的播客风格。或者把几篇公众号文章喂进去,生成一个”文章朗读版”。
🔥 关注LC智趣厅,每期教程都让你多一个实用AI技能。
👇 你用AI做过什么有趣的音频项目?评论区分享你的作品。
— END —
LC 智趣厅 · 科技与生活的交点
ihygg.cn
