Download the audio of a Zhihu video, transcribe it to text with SenseVoice-Small, and save it as a Markdown file with frontmatter.
Environment Requirements
# Python 3.9+
python -m venv .venv
source .venv/bin/activate
# 依赖
pip install funasr modelscope torch torchaudio
# 系统依赖
# macOS: brew install ffmpeg yt-dlp
# Ubuntu: sudo apt install ffmpeg && pip install yt-dlp
Usage
# 独立视频页
python scripts/transcribe.py "https://www.zhihu.com/video/1234567890"
# 问答内嵌视频(脚本自动提取视频 ID)
python scripts/transcribe.py "https://www.zhihu.com/question/12345/answer/67890"
# 专栏文章(内嵌视频会被提取)
python scripts/transcribe.py "https://zhuanlan.zhihu.com/p/123456"
# 指定输出目录
python scripts/transcribe.py "https://www.zhihu.com/video/1234567890" -o ./output
Workflow
Step 1: Download audio with yt-dlp
Zhihu video pages, Q&A pages, and column articles have different link formats; the script uniformly hands them to yt-dlp for parsing. Referer + UA spoofing can circumvent basic anti-scraping measures.
yt-dlp --extract-audio --audio-format mp3 --audio-quality 128K \
--user-agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ..." \
--referer "https://www.zhihu.com/" \
"https://www.zhihu.com/video/1234567890"
Step 2: Transcribe with SenseVoice-Small
from funasr import AutoModel
model = AutoModel(
model="iic/SenseVoiceSmall",
trust_remote_code=True,
vad_model="fsmn-vad",
vad_kwargs={"max_single_segment_time": 30000},
device="cpu",
)
result = model.generate(
input=audio_path,
language="zh",
use_itn=True,
batch_size_s=60,
)
Step 3: Generate Markdown
The script automatically creates a Markdown file with frontmatter, including the source link, title, language, and transcribed text. Failed downloads are retried automatically.
Known Limitations
- Embedded videos: Embedded videos in Q&A and column articles depend on yt-dlp correctly extracting the video ID; if the page structure changes, extraction may fail
- Anti-scraping: Zhihu rate-limits frequent requests; the script has built-in retries, and an interval of no less than 3 seconds between single runs is recommended
- Login state: Yanxuan content and member-only videos require login, and the current script does not carry a login state
- Language: Zhihu is mainly in Chinese, and the script defaults to
language=zh; for English content, it is recommended to use youtube-transcribe instead - Model size: The first download of SenseVoice-Small is about 893MB
Acknowledgements
- yt-dlp/yt-dlp — video download tool
- FunAudioLLM/SenseVoice — speech recognition model
⚖️ Compliance Statement
Forpersonal learning and researchuse only. Please comply with the target platform's Terms of Service (ToS) and robots rules, control request frequency, and do not use it for bulk scraping, commercial crawling, or scenarios that infringe on the rights of others. The copyright of downloaded content belongs to the original author.