ttscn
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesettscn — Multi-Platform Chinese TTS Skill
ttscn — 多平台中文TTS工具
Overview
概述
Generate natural speech audio from text. 11 backends — 8 China-friendly clouds plus 3 international (ElevenLabs / OpenAI / Google).
| # | Backend | Cost | Key strength |
|---|---|---|---|
| 1 | Edge TTS (default) | Free | No API key, works everywhere |
| 2 | Doubao (ByteDance) | ~1 RMB/10K | Best Chinese naturalness (9/10) |
| 3 | CosyVoice (Alibaba) | ~0.2 RMB/1K | Fast streaming, flexible |
| 4 | Azure (Microsoft) | ~1 USD/M chars | Enterprise SSML, eastasia |
| 5 | Tencent Cloud | 0.75 RMB/10K | Lowest cost, 380+ voices |
| 6 | Baidu AI | Flexible | 30+ voices, emotion + dialects |
| 7 | MiniMax | ~$0.10/1K | Best quality, 300+ voices, cloning |
| 8 | iFlytek Xunfei | ~2 RMB/10K | MOS 4.8, 500+ voices, pro grade |
| 9 | ElevenLabs | Paid tiers (from $5/mo) | Top voice quality, instant cloning |
| 10 | OpenAI TTS | ~$15-30/M chars | 6 voices, multilingual, simple REST |
| 11 | Google Cloud TTS | ~$16/M chars (free tier) | 220+ voices, 40+ languages |
New in 1.4–1.6: word-level timestamps (edge/azure/doubao/minimax/cosyvoice —
best-effort, degrades to no boundaries), [PAUSE:x] + sound-tag markers (all
platforms), --phonemes pronunciation overrides (azure/minimax).
New in 1.7: --json flag (JSON envelope independent of ), idempotency
hits report and re-synthesize if the cached audio was deleted,
positional fixed, chunker never splits inside .
--formatcached: true--input f out.wav[PAUSE:x]Cross-platform: Windows, macOS, Linux
All paths in this document are relative to this skill's root directory (the
directory containing this SKILL.md) — resolve them against it.
将文本转换为自然的语音音频。11种后端服务——8款国内友好云服务,外加3款国际服务(ElevenLabs / OpenAI / Google)。
| 序号 | 后端服务 | 成本 | 核心优势 |
|---|---|---|---|
| 1 | Edge TTS(默认) | 免费 | 无需API密钥,全平台可用 |
| 2 | Doubao(字节跳动) | 约1元/万字符 | 中文自然度最佳(9/10) |
| 3 | CosyVoice(阿里云) | 约0.2元/千字符 | 流式合成速度快,灵活性高 |
| 4 | Azure(微软) | 约1美元/百万字符 | 企业级SSML支持,覆盖东亚区域 |
| 5 | 腾讯云 | 0.75元/万字符 | 成本最低,支持380+种音色 |
| 6 | 百度AI | 灵活定价 | 30+种音色,支持情感与方言 |
| 7 | MiniMax | 约0.1美元/千字符 | 音质最佳,300+种音色,支持语音克隆 |
| 8 | 讯飞 | 约2元/万字符 | MOS评分4.8,500+种音色,专业级品质 |
| 9 | ElevenLabs | 付费套餐(最低5美元/月) | 顶级语音质量,支持即时克隆 |
| 10 | OpenAI TTS | 约15-30美元/百万字符 | 6种音色,多语言支持,REST接口简洁 |
| 11 | Google Cloud TTS | 约16美元/百万字符(含免费额度) | 220+种音色,支持40+种语言 |
1.4–1.6版本新增:词级时间戳(edge/azure/doubao/minimax/cosyvoice支持,效果因服务而异,无边界时降级)、[PAUSE:x] + 音效标记(全平台支持)、--phonemes发音修正(azure/minimax支持)。
1.7版本新增:--json参数(独立于的JSON封装)、幂等调用缓存命中时返回,且缓存音频删除后自动重新合成、修复位置参数、文本分割器不会拆分标记内容。
--formatcached: true--input f out.wav[PAUSE:x]跨平台支持:Windows、macOS、Linux
本文档中所有路径均相对于本工具的根目录(即包含SKILL.md的目录),请根据实际路径解析。
When to Use This Skill
适用场景
Automatically activate this skill when:
- User wants to convert Chinese text to speech audio
- Generating voice narration or voiceover for videos
- Creating audiobook or podcast audio from text
- User asks to compare TTS providers, choose a TTS backend, or see what voices are available
- User asks about TTS pricing, features, or which provider supports cloning/SSML/dialects
- User mentions any of: TTS, text-to-speech, 语音合成, 文字转语音, Edge TTS, Doubao TTS, CosyVoice, 火山引擎, 阿里云语音, Azure TTS, 腾讯云TTS, 百度语音, MiniMax, 讯飞语音, ElevenLabs, OpenAI TTS, Google Cloud TTS
- User needs word-level timestamps/subtitles, pause control, or fixing mispronounced Chinese characters (多音字)
- Any task where Chinese text-to-speech would be helpful
以下场景自动激活本工具:
- 用户需要将中文文本转换为语音音频
- 为视频生成旁白或配音
- 将文本转换为有声书或播客音频
- 用户询问TTS服务商对比、选择TTS后端或查看可用音色
- 用户询问TTS定价、功能,或哪个服务商支持克隆/SSML/方言
- 用户提及以下关键词:TTS、text-to-speech、语音合成、文字转语音、Edge TTS、Doubao TTS、CosyVoice、火山引擎、阿里云语音、Azure TTS、腾讯云TTS、百度语音、MiniMax、讯飞语音、ElevenLabs、OpenAI TTS、Google Cloud TTS
- 用户需要词级时间戳/字幕、停顿控制,或修正汉字多音字发音
- 任何需要中文文本转语音的任务
Provider Comparison Page
服务商对比页面
When the user wants to browse, compare, or choose a TTS provider, ALWAYS open the
local HTML comparison page in their browser FIRST — it's a visual, filterable table
that is much faster to scan than reading text output.
bash
undefined当用户需要浏览、对比或选择TTS服务商时,优先在浏览器中打开本地HTML对比页面——这是一个可视化的可筛选表格,比阅读文本输出更高效。
bash
undefinedCross-platform (path relative to this skill's directory)
跨平台(路径相对于本工具目录)
python3 -m webbrowser docs/providers.html
python3 -m webbrowser docs/providers.html
…or the platform-native opener: open (macOS) / xdg-open (Linux) / start (Windows)
或使用平台原生打开命令:macOS用open / Linux用xdg-open / Windows用start
The comparison page includes:
- **Filterable table** — filter by free, SSML, voice cloning, streaming, dialects, multilingual
- **Per-provider detail panels** — cost, max chars/duration, clone method, emotion, languages
- **Voice cards** — recommended voices with style descriptions and best-use labels
- **API key links** — direct links to each provider's console for key acquisition
This page is auto-generated from `data/providers.json` (the single source of truth
for all provider/voice data). Run `python3 scripts/build_docs.py` to regenerate it
after editing the JSON. The same data is queryable on the CLI via
`python3 scripts/tts.py schema backends|voices` (see Schema Introspection).
**After opening the page**, ask the user which backend and voice they'd like to use,
then proceed to Step 2.
对比页面包含:
- **可筛选表格**——按免费、SSML支持、语音克隆、流式合成、方言、多语言等维度筛选
- **服务商详情面板**——成本、单请求最大字符/时长、克隆方式、情感支持、语言覆盖
- **音色卡片**——推荐音色的风格描述及适用场景标签
- **API密钥获取链接**——直接跳转至各服务商控制台的密钥获取页面
该页面由`data/providers.json`自动生成(所有服务商/音色数据的唯一数据源)。编辑JSON后运行`python3 scripts/build_docs.py`可重新生成页面。同样的数据可通过CLI查询:`python3 scripts/tts.py schema backends|voices`(详见架构自省)。
**打开页面后**,询问用户选择的后端服务和音色,然后进入步骤2。Workflow
工作流程
Step 0 — Show the comparison page (when comparing/choosing)
步骤0 — 打开对比页面(对比/选择服务商时)
If the user is browsing, comparing providers, or unsure which backend to use, open
as shown above. Let them explore, then ask which backend +
voice they want.
docs/providers.html如果用户正在浏览、对比服务商或不确定选择哪个后端,请按上述方式打开。让用户浏览后,询问其选择的后端+音色。
docs/providers.htmlStep 1 — Understand the request
步骤1 — 明确需求
Clarify what the user needs:
- Text: inline text or a file? Short or long-form?
- Voice style: male/female, young/mature, warm/energetic? (see voice guide below)
- Speed: normal, faster (+10-20%), slower (-10-20%)?
- Format: WAV (lossless) or MP3 (compressed)?
确认用户需求:
- 文本来源:直接输入文本还是文件?短文本还是长文本?
- 音色风格:男声/女声、年轻/成熟、温暖/活力?(见下方音色指南)
- 语速:正常、加快(+10-20%)、减慢(-10-20%)?
- 输出格式:WAV(无损)还是MP3(压缩)?
Step 2 — Pick a backend & voice
步骤2 — 选择后端与音色
Choose based on the use case (see Backend Selection Guide). Default to Edge TTS
with (female, warm, standard) if unsure. Mention your choice.
zh-CN-XiaoxiaoNeural根据使用场景选择(见后端选择指南)。若不确定,默认选择Edge TTS的(女声、温暖、标准普通话)。告知用户你的选择。
zh-CN-XiaoxiaoNeuralStep 3 — Synthesize
步骤3 — 合成语音
Run with the text and chosen options.
scripts/tts.py运行并传入文本及所选参数。
scripts/tts.pyStep 4 — Report
步骤4 — 结果反馈
Confirm: output path, file size, audio duration.
确认:输出路径、文件大小、音频时长。
Backend Selection Guide
后端选择指南
Quick Pick
快速选择
| Use case | Backend | Voice | Why |
|---|---|---|---|
| Default / general | edge | zh-CN-XiaoxiaoNeural | Free, no setup |
| Short video / Douyin | doubao | BV001_streaming | Native short-video style |
| Audiobook / long-form | cosyvoice | longxiaochun_v3 | Fast synthesis, natural |
| Enterprise / SSML | azure | zh-CN-XiaoxiaoNeural | Rich prosody control |
| Bulk / lowest cost | tencent | 101001 | 0.75 RMB/10K chars |
| Emotion / dialects | baidu | 3 or 4 | Emotion synthesis, Cantonese |
| Best quality / cloning | minimax | female-shaonv | speech-2.6-hd, voice design |
| Education / pro | xunfei | xiaoyan | MOS 4.8, 500+ voices |
| Male narration | edge | zh-CN-YunxiNeural | Energetic male voice |
| Documentary | azure | zh-CN-YunyangNeural | Deep, professional male |
| Children's content | edge | zh-CN-XiaomengNeural | Bright, youthful female |
| Cost-sensitive | edge | zh-CN-XiaoxiaoNeural | Completely free |
| English, top quality | elevenlabs | 21m00Tcm4TlvDq8ikWAM (Rachel) | Best-in-class English voices |
| English, simple/cheap | openai | alloy | tts-1-hd, one env var |
| English, enterprise | en-US-Neural2-F | 220+ voices, free tier |
| 使用场景 | 后端服务 | 音色 | 理由 |
|---|---|---|---|
| 默认/通用场景 | edge | zh-CN-XiaoxiaoNeural | 免费,无需配置 |
| 短视频/抖音风格 | doubao | BV001_streaming | 原生短视频风格 |
| 有声书/长文本 | cosyvoice | longxiaochun_v3 | 合成速度快,自然度高 |
| 企业级/SSML支持 | azure | zh-CN-XiaoxiaoNeural | 丰富的韵律控制 |
| 批量处理/最低成本 | tencent | 101001 | 0.75元/万字符 |
| 情感/方言支持 | baidu | 3或4 | 情感合成,支持粤语 |
| 最佳音质/语音克隆 | minimax | female-shaonv | speech-2.6-hd模型,支持音色定制 |
| 教育场景/专业级 | xunfei | xiaoyan | MOS评分4.8,500+种音色 |
| 男声旁白 | edge | zh-CN-YunxiNeural | 活力男声 |
| 纪录片风格 | azure | zh-CN-YunyangNeural | 沉稳专业男声 |
| 儿童内容 | edge | zh-CN-XiaomengNeural | 明亮年轻女声 |
| 成本敏感场景 | edge | zh-CN-XiaoxiaoNeural | 完全免费 |
| 英文/顶级音质 | elevenlabs | 21m00Tcm4TlvDq8ikWAM (Rachel) | 业界最佳英文音色 |
| 英文/简洁低成本 | openai | alloy | tts-1-hd模型,仅需一个环境变量 |
| 英文/企业级 | en-US-Neural2-F | 220+种音色,含免费额度 |
Full capability & voice data
完整能力与音色数据
The complete capability matrix (cost, max chars/duration per chunk, SSML, cloning
method + cost, emotion, dialects, languages, streaming, setup difficulty) and the
per-backend voice lists live in one place: . View them via:
data/providers.json- The comparison page () — best for humans
docs/providers.html - — full capability fields per backend
python3 scripts/tts.py schema backends --full - — every voice preset with style descriptions
python3 scripts/tts.py schema voices - — human-readable terminal summary
python3 scripts/tts.py --list
Do not maintain copies of these tables elsewhere — regenerate from the JSON.
完整的能力矩阵(成本、单请求最大字符/时长、SSML支持、克隆方式及成本、情感支持、方言、语言覆盖、流式合成、配置难度)和各后端音色列表统一存储在****中。可通过以下方式查看:
data/providers.json- 对比页面()——最适合人类阅读
docs/providers.html - ——查看各后端的完整能力字段
python3 scripts/tts.py schema backends --full - ——查看所有预设音色及风格描述
python3 scripts/tts.py schema voices - ——终端可读的摘要信息
python3 scripts/tts.py --list
请勿在其他地方维护这些表格的副本——请从JSON文件重新生成。
Voice Cloning (clone
command)
clone语音克隆(clone
命令)
cloneCreate a custom voice from reference audio, store it under a name, then use
the name anywhere is accepted. Built-in for minimax (local file
OK, 10s-5min audio, paid: ~$1.5/voice global site or ¥9.9 on first use China
site; a new clone is TEMPORARY until its first real synthesis — use it within
7 days [global site] / 48 h [China site] of creation or MiniMax deletes it,
previews don't count; permanent after first use) and cosyvoice (enrollment
free, audio must be a PUBLIC http(s) URL, 10-20s, voice expires after 1 year
unused).
--voicebash
undefined通过参考音频创建自定义音色,为其命名后,可在任何接受参数的地方使用该名称。minimax(支持本地文件,音频时长10秒-5分钟,付费:全球站点约1.5美元/音色,国内站点首次使用约9.9元;新创建的克隆音色为临时状态,需在7天内(全球站点)/48小时内(国内站点)进行首次实际合成,否则MiniMax会删除该音色,预览不计入;首次合成后转为永久状态)和cosyvoice(免费注册,音频必须为公开http(s)URL,时长10-20秒,音色1年未使用即过期)原生支持该功能。
--voicebash
undefinedMiniMax — local file, paid, must confirm with --yes
MiniMax — 本地文件,付费,必须添加--yes参数确认
python3 scripts/tts.py clone create --platform minimax --audio my_voice.wav --name myvoice --yes
python3 scripts/tts.py clone create --platform minimax --audio my_voice.wav --name myvoice --yes
CosyVoice — free, but --audio must be a public URL; --target-model must
CosyVoice — 免费,但--audio必须为公开URL;--target-model必须与合成模型匹配(默认:$COSYVOICE_MODEL或cosyvoice-v3-flash)
match the synthesis model (default: $COSYVOICE_MODEL or cosyvoice-v3-flash)
—
python3 scripts/tts.py clone create --platform cosyvoice --audio https://example.com/my.wav --name myvoice
python3 scripts/tts.py clone create --platform cosyvoice --audio https://example.com/my.wav --name myvoice
Manage
管理克隆音色
python3 scripts/tts.py clone list
python3 scripts/tts.py clone delete --name myvoice [--remote] # --remote: cosyvoice only
python3 scripts/tts.py clone list
python3 scripts/tts.py clone delete --name myvoice [--remote] # --remote仅适用于cosyvoice
Use it — the stored name resolves to the platform voice_id automatically
使用克隆音色 — 存储的名称会自动解析为对应平台的voice_id
python3 scripts/tts.py "用我的声音说这句话" out.wav --platform minimax --voice myvoice
Rules the agent MUST follow:
- MiniMax creation is paid — never run `clone create --platform minimax`
without the user's explicit confirmation (the CLI enforces `--yes`).
- Only clone the user's own voice or one they are authorized to use — both
platforms contractually prohibit cloning third parties without consent.
- Reference audio: clean single-speaker speech, no BGM, 10-20s is ideal.
- Named voices live in `~/.ttscn.json` under `cloned_voices`.
Other platforms (Doubao/Tencent/Baidu/Xunfei/Azure) support cloning via
their consoles — the resulting voice id also works as a plain `--voice`.python3 scripts/tts.py "用我的声音说这句话" out.wav --platform minimax --voice myvoice
必须遵守的规则:
- MiniMax克隆需付费——未获得用户明确确认前,切勿运行`clone create --platform minimax`(CLI强制要求`--yes`参数)。
- 仅克隆用户自己的声音或其有权使用的声音——两个平台均禁止未经授权克隆第三方声音。
- 参考音频要求:清晰的单人语音,无背景音乐,时长10-20秒最佳。
- 已命名的音色存储在`~/.ttscn.json`的`cloned_voices`字段中。
其他平台(Doubao/腾讯/百度/讯飞/Azure)可通过其控制台进行克隆——生成的voice_id也可直接作为`--voice`参数使用。Usage
使用方法
Basic Usage
基础用法
bash
undefinedbash
undefinedDefault (Edge TTS, free, Xiaoxiao voice)
默认配置(Edge TTS,免费,Xiaoxiao音色)
python3 scripts/tts.py "你好世界" output.wav
python3 scripts/tts.py "你好世界" output.wav
Specific voice
指定音色
python3 scripts/tts.py --voice zh-CN-YunxiNeural "欢迎收听今天的节目" welcome.wav
python3 scripts/tts.py --voice zh-CN-YunxiNeural "欢迎收听今天的节目" welcome.wav
Specific backend
指定后端服务
python3 scripts/tts.py --platform doubao "今天天气真好" weather.wav
python3 scripts/tts.py --platform minimax "高品质语音合成" hq.wav
python3 scripts/tts.py --platform doubao "今天天气真好" weather.wav
python3 scripts/tts.py --platform minimax "高品质语音合成" hq.wav
Adjust speed
调整语速
python3 scripts/tts.py --rate +15% "快速播报" fast.wav
python3 scripts/tts.py --rate -10% "慢速朗读" slow.wav
undefinedpython3 scripts/tts.py --rate +15% "快速播报" fast.wav
python3 scripts/tts.py --rate -10% "慢速朗读" slow.wav
undefinedFrom File
从文件读取文本
bash
python3 scripts/tts.py --input script.txt output.wavbash
python3 scripts/tts.py --input script.txt output.wavOutput Format
输出格式
bash
undefinedbash
undefinedMP3 output (compressed, smaller file)
输出MP3格式(压缩,文件更小)
python3 scripts/tts.py --format mp3 "你好" hello.mp3
python3 scripts/tts.py --format mp3 "你好" hello.mp3
JSON envelope + MP3 audio at the same time
同时输出JSON封装和MP3音频
python3 scripts/tts.py --json --format mp3 "你好" hello.mp3
undefinedpython3 scripts/tts.py --json --format mp3 "你好" hello.mp3
undefinedPreview (Dry Run)
预览(试运行)
bash
undefinedbash
undefinedPreview without making API call — no package installs needed
预览模式,不调用API — 无需安装依赖包
python3 scripts/tts.py --dry-run "这是一段测试文本"
undefinedpython3 scripts/tts.py --dry-run "这是一段测试文本"
undefinedList Options
查看选项列表
bash
python3 scripts/tts.py --listbash
python3 scripts/tts.py --listExpressiveness Markers
表现力标记
Input text may contain markers on any platform — they are rendered natively
where supported and stripped everywhere else (never read aloud). The chunker
never splits inside a marker.
[...]| Marker | Syntax | azure | minimax | all other platforms |
|---|---|---|---|---|
| Pause | | | | stripped |
| Sound tags | | stripped | voiced only if | stripped |
bash
python3 scripts/tts.py --platform azure \
"大家好。[PAUSE:0.8] 今天我们聊一个新话题。" out.wav
MINIMAX_MODEL=speech-2.8-hd python3 scripts/tts.py --platform minimax \
"这也太好笑了 (laughs) 好,我们继续。" out.wav输入文本可包含以下标记,所有平台均支持——在支持原生渲染的平台会生效,其他平台会自动移除(不会被朗读)。文本分割器不会拆分标记内的内容。
[...]| 标记类型 | 语法 | azure | minimax | 其他所有平台 |
|---|---|---|---|---|
| 停顿 | | 转换为SSML的 | 转换为 | 自动移除 |
| 音效标签 | | 自动移除 | 仅当 | 自动移除 |
bash
python3 scripts/tts.py --platform azure \
"大家好。[PAUSE:0.8] 今天我们聊一个新话题。" out.wav
MINIMAX_MODEL=speech-2.8-hd python3 scripts/tts.py --platform minimax \
"这也太好笑了 (laughs) 好,我们继续。" out.wavPronunciation Overrides (--phonemes
)
--phonemes发音修正(--phonemes
)
--phonemesFix polyphonic Chinese characters (多音字) with a JSON dict mapping words to
space-separated pinyin — tone-numbered () or tone-marked
(). Keys starting with are comments.
hang2 zhang3háng zhǎng_json
{
"_comment": "pronunciation overrides for bank-themed script",
"行长": "hang2 zhang3",
"重庆": "chóng qìng"
}bash
python3 scripts/tts.py --platform azure --phonemes phonemes.json \
"行长在重庆开会。" out.wavPer-platform: azure → SSML tags; minimax →
inline pinyin annotations like (applied before chunking so
the annotation counts toward the chunk budget); all other platforms silently
ignore the flag.
<phoneme alphabet="sapi">重(chong2)庆(qing4)通过JSON字典修正汉字多音字,键为词语,值为空格分隔的拼音——支持数字声调()或带声调符号的拼音()。以开头的键为注释。
hang2 zhang3háng zhǎng_json
{
"_comment": "银行主题脚本的发音修正",
"行长": "hang2 zhang3",
"重庆": "chóng qìng"
}bash
python3 scripts/tts.py --platform azure --phonemes phonemes.json \
"行长在重庆开会。" out.wav各平台处理方式:azure→转换为SSML的标签;minimax→转换为内联拼音注释,如(注释会占用文本分割的字符配额);其他平台会忽略该参数。
<phoneme alphabet="sapi">重(chong2)庆(qing4)Requirements
依赖要求
bash
undefinedbash
undefinedCore (always needed)
核心依赖(必须安装)
pip install edge-tts # For Edge (default, free)
pip install edge-tts # 用于Edge(默认免费服务)
Optional backends — install only what you use
可选后端依赖 — 仅安装你需要的服务对应的依赖
pip install dashscope # CosyVoice
pip install requests # Doubao, MiniMax, ElevenLabs, OpenAI, Google
pip install azure-cognitiveservices-speech # Azure
pip install tencentcloud-sdk-python-tts # Tencent Cloud
pip install baidu-aip chardet # Baidu AI
pip install websocket-client # Xunfei
System requirement: `ffmpeg`pip install dashscope # CosyVoice
pip install requests # Doubao, MiniMax, ElevenLabs, OpenAI, Google
pip install azure-cognitiveservices-speech # Azure
pip install tencentcloud-sdk-python-tts # 腾讯云
pip install baidu-aip chardet # 百度AI
pip install websocket-client # 讯飞
系统依赖:`ffmpeg`Environment Variables
环境变量
bash
undefinedbash
undefinedGlobal defaults (optional)
全局默认配置(可选)
export TTS_BACKEND="edge"
export TTS_VOICE="zh-CN-XiaoxiaoNeural"
export TTS_RATE="+5%"
export TTS_FORMAT="wav" # wav | mp3 | json (json = JSON envelope mode)
export TTS_BACKEND="edge"
export TTS_VOICE="zh-CN-XiaoxiaoNeural"
export TTS_RATE="+5%"
export TTS_FORMAT="wav" # wav | mp3 | json(json为JSON封装模式)
Backend tuning (optional)
后端调优配置(可选)
export MINIMAX_MODEL="speech-2.6-hd" # use speech-2.8-* to voice sound tags
export MINIMAX_GROUP_ID="" # required by some MiniMax accounts
export COSYVOICE_MODEL="cosyvoice-v3-flash"
export MINIMAX_MODEL="speech-2.6-hd" # 使用speech-2.8-*模型可支持音效标签合成
export MINIMAX_GROUP_ID="" # 部分MiniMax账号需要该参数
export COSYVOICE_MODEL="cosyvoice-v3-flash"
ByteDance Volcano Ark (Doubao)
字节跳动火山方舟(Doubao)
v3 (recommended, no appid): API key from the new console (Ark API Key page)
v3版本(推荐,无需appid):从新控制台(Ark API Key页面)获取API密钥
export VOLCENGINE_API_KEY="your_api_key"
export VOLCENGINE_RESOURCE_ID="seed-tts-2.0" # optional; seed-tts-1.0 / seed-icl-2.0 also valid
export VOLCENGINE_API_KEY="your_api_key"
export VOLCENGINE_RESOURCE_ID="seed-tts-2.0" # 可选;seed-tts-1.0 / seed-icl-2.0也有效
v1 (legacy, appid + token): only when VOLCENGINE_API_KEY is unset
v1版本(旧版,需appid + token):仅当未设置VOLCENGINE_API_KEY时生效
export VOLCENGINE_APPID="your_app_id"
export VOLCENGINE_ACCESS_TOKEN="your_token"
export VOLCENGINE_APPID="your_app_id"
export VOLCENGINE_ACCESS_TOKEN="your_token"
Alibaba DashScope (CosyVoice)
阿里云DashScope(CosyVoice)
export DASHSCOPE_API_KEY="your_api_key"
export DASHSCOPE_API_KEY="your_api_key"
Microsoft Azure
微软Azure
export AZURE_SPEECH_KEY="your_key"
export AZURE_SPEECH_REGION="eastasia"
export TTS_STYLE="gentle" # optional: mstts:express-as style; unset = plain prosody
export AZURE_SPEECH_KEY="your_key"
export AZURE_SPEECH_REGION="eastasia"
export TTS_STYLE="gentle" # 可选:mstts:express-as风格;未设置则为普通韵律
Tencent Cloud
腾讯云
export TENCENT_SECRET_ID="your_secret_id"
export TENCENT_SECRET_KEY="your_secret_key"
export TENCENT_SECRET_ID="your_secret_id"
export TENCENT_SECRET_KEY="your_secret_key"
Baidu AI
百度AI
export BAIDU_APP_ID="your_app_id"
export BAIDU_API_KEY="your_api_key"
export BAIDU_SECRET_KEY="your_secret_key"
export BAIDU_APP_ID="your_app_id"
export BAIDU_API_KEY="your_api_key"
export BAIDU_SECRET_KEY="your_secret_key"
MiniMax
MiniMax
export MINIMAX_API_KEY="your_api_key"
export MINIMAX_API_KEY="your_api_key"
iFlytek Xunfei
讯飞
export XUNFEI_APP_ID="your_app_id"
export XUNFEI_API_KEY="your_api_key"
export XUNFEI_API_SECRET="your_api_secret"
export XUNFEI_APP_ID="your_app_id"
export XUNFEI_API_KEY="your_api_key"
export XUNFEI_API_SECRET="your_api_secret"
ElevenLabs (international)
ElevenLabs(国际服务)
export ELEVENLABS_API_KEY="your_api_key"
export ELEVENLABS_MODEL="eleven_multilingual_v2" # optional, this is the default
export ELEVENLABS_API_KEY="your_api_key"
export ELEVENLABS_MODEL="eleven_multilingual_v2" # 可选,默认值
OpenAI TTS (international)
OpenAI TTS(国际服务)
export OPENAI_API_KEY="your_api_key"
export OPENAI_TTS_MODEL="tts-1-hd" # optional, this is the default
export OPENAI_API_KEY="your_api_key"
export OPENAI_TTS_MODEL="tts-1-hd" # 可选,默认值
Google Cloud TTS (international)
Google Cloud TTS(国际服务)
export GOOGLE_TTS_API_KEY="your_api_key"
export GOOGLE_TTS_LANGUAGE="en-US" # optional, auto-derived from voice name
Get API Keys:
- Volcano Ark: https://console.volcengine.com/ark/region:ark+cn-beijing/apikey
- DashScope: https://bailian.console.aliyun.com/
- Azure: https://portal.azure.com/
- Tencent Cloud: https://console.cloud.tencent.com/tts
- Baidu AI: https://console.bce.baidu.com/ai/#/ai/speech/overview
- MiniMax: https://platform.minimaxi.com
- Xunfei: https://www.xfyun.cn
- ElevenLabs: https://elevenlabs.io/app/settings/api-keys
- OpenAI: https://platform.openai.com/api-keys
- Google Cloud: https://console.cloud.google.com/apis/credentialsexport GOOGLE_TTS_API_KEY="your_api_key"
export GOOGLE_TTS_LANGUAGE="en-US" # 可选,自动从音色名称推导
获取API密钥:
- 火山方舟:https://console.volcengine.com/ark/region:ark+cn-beijing/apikey
- DashScope:https://bailian.console.aliyun.com/
- Azure:https://portal.azure.com/
- 腾讯云:https://console.cloud.tencent.com/tts
- 百度AI:https://console.bce.baidu.com/ai/#/ai/speech/overview
- MiniMax:https://platform.minimaxi.com
- 讯飞:https://www.xfyun.cn
- ElevenLabs:https://elevenlabs.io/app/settings/api-keys
- OpenAI:https://platform.openai.com/api-keys
- Google Cloud:https://console.cloud.google.com/apis/credentialsConfig File (Optional)
配置文件(可选)
Create for personal defaults, or in a project directory:
~/.ttscn.json.ttscn.jsonjson
{
"backend": "minimax",
"voice": "female-shaonv",
"rate": "+10%"
}Priority (highest first):
- CLI arguments (,
--platform,--voice)--rate - Environment variables (,
TTS_BACKEND,TTS_VOICE)TTS_RATE - Project config (in current directory)
.ttscn.json - User config ()
~/.ttscn.json - Built-in defaults
创建作为个人默认配置,或在项目目录中创建:
~/.ttscn.json.ttscn.jsonjson
{
"backend": "minimax",
"voice": "female-shaonv",
"rate": "+10%"
}优先级(从高到低):
- CLI参数(,
--platform,--voice)--rate - 环境变量(,
TTS_BACKEND,TTS_VOICE)TTS_RATE - 项目配置(当前目录下的)
.ttscn.json - 用户配置()
~/.ttscn.json - 内置默认值
Examples
示例
Quick Narration (Free, Zero Setup)
快速生成旁白(免费,无需配置)
bash
python3 scripts/tts.py \
"人工智能正在改变我们的生活方式,从智能助手到自动驾驶,技术革新无处不在。" \
ai_narration.wavbash
python3 scripts/tts.py \
"人工智能正在改变我们的生活方式,从智能助手到自动驾驶,技术革新无处不在。" \
ai_narration.wavDouyin Style Short Video Voice
抖音风格短视频配音
bash
python3 scripts/tts.py \
--platform doubao --voice BV001_streaming --rate +10% \
"家人们,今天给大家推荐一个超好用的神器!" \
douyin_style.wavbash
python3 scripts/tts.py \
--platform doubao --voice BV001_streaming --rate +10% \
"家人们,今天给大家推荐一个超好用的神器!" \
douyin_style.wavAudiobook from Script File (CosyVoice)
从脚本文件生成有声书(CosyVoice)
bash
python3 scripts/tts.py \
--platform cosyvoice --voice longxiaoxia_v3 \
--input chapter1.txt chapter1.wavbash
python3 scripts/tts.py \
--platform cosyvoice --voice longxiaoxia_v3 \
--input chapter1.txt chapter1.wavBulk Generation at Lowest Cost (Tencent, inline env vars)
低成本批量生成(腾讯云,内联环境变量)
bash
TENCENT_SECRET_ID="xxx" TENCENT_SECRET_KEY="xxx" \
python3 scripts/tts.py \
--platform tencent --voice 101001 \
--input course_script.txt course_audio.wavbash
TENCENT_SECRET_ID="xxx" TENCENT_SECRET_KEY="xxx" \
python3 scripts/tts.py \
--platform tencent --voice 101001 \
--input course_script.txt course_audio.wavPremium Quality with Emotion (MiniMax)
带情感的高品质语音(MiniMax)
bash
MINIMAX_API_KEY="xxx" \
python3 scripts/tts.py \
--platform minimax --voice female-shaonv \
"这是一段充满感情的语音合成演示。" premium.wavbash
MINIMAX_API_KEY="xxx" \
python3 scripts/tts.py \
--platform minimax --voice female-shaonv \
"这是一段充满感情的语音合成演示。" premium.wavAgent-Native CLI Reference
原生Agent CLI参考
ttscn follows the agent-native-design contract.
It serves humans (readable terminal output), AI agents (structured JSON on stdout), and
orchestrators (distinct exit codes + idempotency) simultaneously.
ttscn遵循agent-native-design规范。同时支持人类用户(可读的终端输出)、AI Agent(标准JSON输出)和编排器(明确的退出码+幂等性)。
JSON Mode
JSON模式
bash
undefinedbash
undefinedExplicit JSON envelope mode (independent of --format)
显式JSON封装模式(独立于--format参数)
python3 scripts/tts.py --json "你好" out.wav
python3 scripts/tts.py --json --format mp3 "你好" out.mp3
python3 scripts/tts.py --json "你好" out.wav
python3 scripts/tts.py --json --format mp3 "你好" out.mp3
--format json is a deprecated alias for --json (kept for compatibility)
--format json是--json的已弃用别名(为兼容保留)
Auto-detect: pipe to jq → JSON automatically
自动检测:管道输出至jq时自动切换为JSON格式
python3 scripts/tts.py --list | jq .data.backends[0].name
python3 scripts/tts.py --list | jq .data.backends[0].name
Error envelope always structured
错误信息始终为结构化格式
python3 scripts/tts.py --json --platform doubao "test" out.wav
python3 scripts/tts.py --json --platform doubao "test" out.wav
→ {"ok":false, "error":{"code":"auth_missing_env","message":"...","retryable":false,...}}
→ {"ok":false, "error":{"code":"auth_missing_env","message":"...","retryable":false,...}}
undefinedundefinedOutput Envelope
输出封装格式
json
// Success
{"ok":true, "data":{...}, "meta":{"version":"...","schema_version":"1.2.0","timestamp":"...","ms":123}}
// Error
{"ok":false, "error":{"code":"auth_missing_env","message":"set one of: VOLCENGINE_APPID+VOLCENGINE_ACCESS_TOKEN / VOLCENGINE_API_KEY","retryable":false,"field":"VOLCENGINE_APPID","backend":"doubao"}, "meta":{...}}Contract: is a semver string present on every
envelope (success and error). The major version bumps only on breaking
envelope changes — consumers should assert it matches the schema major they
were written against (e.g. video-podcast-maker requires major ) and fail
with a clear error otherwise. An absent means a pre-contract
ttscn release.
meta.schema_version1schema_versionjson
// 成功响应
{"ok":true, "data":{...}, "meta":{"version":"...","schema_version":"1.2.0","timestamp":"...","ms":123}}
// 错误响应
{"ok":false, "error":{"code":"auth_missing_env","message":"set one of: VOLCENGINE_APPID+VOLCENGINE_ACCESS_TOKEN / VOLCENGINE_API_KEY","retryable":false,"field":"VOLCENGINE_APPID","backend":"doubao"}, "meta":{...}}规范:是语义化版本字符串,所有响应(成功/错误)均包含该字段。主版本号仅在封装格式发生破坏性变更时升级——消费者应断言该主版本号与预期一致(例如video-podcast-maker要求主版本为),否则应返回清晰的错误信息。若缺少,则表示使用的是规范发布前的ttscn版本。
meta.schema_version1schema_versionWord Boundaries (edge / azure / doubao / minimax / cosyvoice)
词边界(edge / azure / doubao / minimax / cosyvoice)
For edge, azure, doubao, minimax, and cosyvoice, the
success envelope includes native word-level timestamps under
— absolute seconds within the output file, ascending,
3-decimal rounding. The key is absent for other platforms — and may be absent
on doubao/minimax/cosyvoice too when the provider returns no timing payload
(minority-language doubao voices; minimax subtitle download failure;
cosyvoice-v1 or voices without timestamp support) — so consumers must treat
it as optional.
data.word_boundariesjson
{"ok":true, "data":{
"output_file": "out.wav",
"word_boundaries": [
{"text": "你好", "offset_sec": 0.1, "duration_sec": 0.45},
{"text": "世界", "offset_sec": 0.562, "duration_sec": 0.5}
]
}}Use these for subtitle/SRT generation or beat-synced animation without a
separate forced-alignment pass.
对于edge、azure、doubao、minimax和cosyvoice,成功响应的封装中包含原生词级时间戳,存储在字段中——为输出音频中的绝对秒数,按升序排列,保留三位小数。其他平台不会返回该字段——doubao/minimax/cosyvoice在服务商未返回时间数据时也不会返回该字段(例如doubao的小语种音色、minimax字幕下载失败、cosyvoice-v1或不支持时间戳的音色)——因此消费者应将其视为可选字段。
data.word_boundariesjson
{"ok":true, "data":{
"output_file": "out.wav",
"word_boundaries": [
{"text": "你好", "offset_sec": 0.1, "duration_sec": 0.45},
{"text": "世界", "offset_sec": 0.562, "duration_sec": 0.5}
]
}}可使用该字段生成字幕/SRT文件,或无需额外强制对齐即可实现节拍同步动画。
Exit Codes
退出码
| Code | Meaning | Agent action |
|---|---|---|
| 0 | Success | Parse |
| 1 | Internal / runtime error | Report to user, do not retry |
| 2 | Validation / fixable error (bad input, missing package) | Fix input or install package, retry allowed |
| 3 | Auth / missing credentials | Ask user for API key, do not retry |
| 4 | Backend API error | Retry with backoff |
| 代码 | 含义 | Agent操作 |
|---|---|---|
| 0 | 成功 | 解析 |
| 1 | 内部/运行时错误 | 告知用户,请勿重试 |
| 2 | 验证/可修复错误(输入无效、依赖缺失) | 修正输入或安装依赖,允许重试 |
| 3 | 认证/凭证缺失 | 请求用户提供API密钥,请勿重试 |
| 4 | 后端API错误 | 退避后重试 |
Schema Introspection
架构自省
bash
python3 scripts/tts.py schema backends # All 11 backends (compact by default)
python3 scripts/tts.py schema backends --full # All fields (22 per backend)
python3 scripts/tts.py schema backends.doubao # Single backend full detail
python3 scripts/tts.py schema voices # All voice presets per backend
python3 scripts/tts.py schema tags # Tag definitions
python3 scripts/tts.py schema version # Version + providers data freshnessbash
python3 scripts/tts.py schema backends # 查看所有11种后端服务(默认简洁格式)
python3 scripts/tts.py schema backends --full # 查看所有字段(每个后端22个字段)
python3 scripts/tts.py schema backends.doubao # 查看单个后端的完整详情
python3 scripts/tts.py schema voices # 查看各后端的所有预设音色
python3 scripts/tts.py schema tags # 查看标签定义
python3 scripts/tts.py schema version # 查看版本及服务商数据更新时间Field filtering for low-token-cost queries
字段过滤,减少查询token消耗
python3 scripts/tts.py schema backends --fields name,cost,supports_clone,supports_ssml
undefinedpython3 scripts/tts.py schema backends --fields name,cost,supports_clone,supports_ssml
undefinedIdempotency
幂等性
bash
undefinedbash
undefinedOrchestrators: retried calls return cached result — no double-billing
编排器:重试请求返回缓存结果——避免重复计费
python3 scripts/tts.py --idempotency-key "daily-podcast-2026-07-08" --input script.txt out.wav
python3 scripts/tts.py --idempotency-key "daily-podcast-2026-07-08" --input script.txt out.wav
Cache at ~/.ttscn_idem/, 7-day TTL, SHA-256 keyed
缓存存储在~/.ttscn_idem/,TTL为7天,使用SHA-256作为键
A cache hit returns the stored result with `data.cached: true`. If the cached
`output_file` no longer exists on disk, the call **re-synthesizes** instead of
returning a stale success.
缓存命中时返回的结果中包含`data.cached: true`。若缓存的`output_file`已从磁盘删除,请求会**重新合成**而非返回过期的成功响应。Agent Compatibility Flags
Agent兼容参数
bash
undefinedbash
undefinedNo-ops accepted for agent runtime compatibility (ttscn never prompts)
为兼容Agent运行时,接受无操作参数(ttscn从不弹出提示)
python3 scripts/tts.py --yes --no-input "text" out.wav
undefinedpython3 scripts/tts.py --yes --no-input "text" out.wav
undefined