Download the audio from a TikTok video, transcribe it to text with SenseVoice-Small, and save it as a Markdown file with frontmatter. Automatically detects the language when the content mixes Chinese and English.
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.tiktok.com/@user/video/1234567890"
# 短链(自动跟随跳转)
python scripts/transcribe.py "https://vm.tiktok.com/xxxxx"
python scripts/transcribe.py "https://vt.tiktok.com/xxxxx"
# 指定输出目录
python scripts/transcribe.py "https://vm.tiktok.com/xxxxx" -o ./output
Workflow
Step 1: Download audio with yt-dlp
TikTok has regional restrictions; the script adds by default --geo-bypass. Short links are automatically followed by yt-dlp, no manual handling required.
yt-dlp --extract-audio --audio-format mp3 --audio-quality 128K \
--geo-bypass \
"https://vm.tiktok.com/xxxxx"
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="auto", # TikTok 中英混杂,自动检测
use_itn=True,
batch_size_s=60,
)
Step 3: Generate Markdown
The script automatically creates a Markdown file with frontmatter, including the source link, author, language, and transcribed text.
Known Limitations
- Regional restrictions: TikTok content may be inaccessible in some regions or network environments;
--geo-bypasscan mitigate but does not guarantee a fix - Anti-scraping: Frequent requests may trigger rate limiting; the script has built-in retries, but it is still recommended to control the frequency
- Language mixing:
language=autoworks for content mixing Chinese and English, but quality for long English passages is not as good as a dedicated English model - Login state: Content from private accounts requires login; the current script does not carry a login state
- Model size: SenseVoice-Small is about 893MB on first download
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 others' rights. The copyright of downloaded content belongs to the original author.