ttscn

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ttscn — 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).
#BackendCostKey strength
1Edge TTS (default)FreeNo API key, works everywhere
2Doubao (ByteDance)~1 RMB/10KBest Chinese naturalness (9/10)
3CosyVoice (Alibaba)~0.2 RMB/1KFast streaming, flexible
4Azure (Microsoft)~1 USD/M charsEnterprise SSML, eastasia
5Tencent Cloud0.75 RMB/10KLowest cost, 380+ voices
6Baidu AIFlexible30+ voices, emotion + dialects
7MiniMax~$0.10/1KBest quality, 300+ voices, cloning
8iFlytek Xunfei~2 RMB/10KMOS 4.8, 500+ voices, pro grade
9ElevenLabsPaid tiers (from $5/mo)Top voice quality, instant cloning
10OpenAI TTS~$15-30/M chars6 voices, multilingual, simple REST
11Google 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
--format
), idempotency hits report
cached: true
and re-synthesize if the cached audio was deleted,
--input f out.wav
positional fixed, chunker never splits inside
[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)。
序号后端服务成本核心优势
1Edge TTS(默认)免费无需API密钥,全平台可用
2Doubao(字节跳动)约1元/万字符中文自然度最佳(9/10)
3CosyVoice(阿里云)约0.2元/千字符流式合成速度快,灵活性高
4Azure(微软)约1美元/百万字符企业级SSML支持,覆盖东亚区域
5腾讯云0.75元/万字符成本最低,支持380+种音色
6百度AI灵活定价30+种音色,支持情感与方言
7MiniMax约0.1美元/千字符音质最佳,300+种音色,支持语音克隆
8讯飞约2元/万字符MOS评分4.8,500+种音色,专业级品质
9ElevenLabs付费套餐(最低5美元/月)顶级语音质量,支持即时克隆
10OpenAI TTS约15-30美元/百万字符6种音色,多语言支持,REST接口简洁
11Google Cloud TTS约16美元/百万字符(含免费额度)220+种音色,支持40+种语言
1.4–1.6版本新增:词级时间戳(edge/azure/doubao/minimax/cosyvoice支持,效果因服务而异,无边界时降级)、[PAUSE:x] + 音效标记(全平台支持)、--phonemes发音修正(azure/minimax支持)。 1.7版本新增:--json参数(独立于
--format
的JSON封装)、幂等调用缓存命中时返回
cached: 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
undefined

Cross-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
docs/providers.html
as shown above. Let them explore, then ask which backend + voice they want.
如果用户正在浏览、对比服务商或不确定选择哪个后端,请按上述方式打开
docs/providers.html
。让用户浏览后,询问其选择的后端+音色。

Step 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
zh-CN-XiaoxiaoNeural
(female, warm, standard) if unsure. Mention your choice.
根据使用场景选择(见后端选择指南)。若不确定,默认选择Edge TTS
zh-CN-XiaoxiaoNeural
(女声、温暖、标准普通话)。告知用户你的选择。

Step 3 — Synthesize

步骤3 — 合成语音

Run
scripts/tts.py
with the text and chosen options.
运行
scripts/tts.py
并传入文本及所选参数。

Step 4 — Report

步骤4 — 结果反馈

Confirm: output path, file size, audio duration.
确认:输出路径、文件大小、音频时长。

Backend Selection Guide

后端选择指南

Quick Pick

快速选择

Use caseBackendVoiceWhy
Default / generaledgezh-CN-XiaoxiaoNeuralFree, no setup
Short video / DouyindoubaoBV001_streamingNative short-video style
Audiobook / long-formcosyvoicelongxiaochun_v3Fast synthesis, natural
Enterprise / SSMLazurezh-CN-XiaoxiaoNeuralRich prosody control
Bulk / lowest costtencent1010010.75 RMB/10K chars
Emotion / dialectsbaidu3 or 4Emotion synthesis, Cantonese
Best quality / cloningminimaxfemale-shaonvspeech-2.6-hd, voice design
Education / proxunfeixiaoyanMOS 4.8, 500+ voices
Male narrationedgezh-CN-YunxiNeuralEnergetic male voice
Documentaryazurezh-CN-YunyangNeuralDeep, professional male
Children's contentedgezh-CN-XiaomengNeuralBright, youthful female
Cost-sensitiveedgezh-CN-XiaoxiaoNeuralCompletely free
English, top qualityelevenlabs21m00Tcm4TlvDq8ikWAM (Rachel)Best-in-class English voices
English, simple/cheapopenaialloytts-1-hd, one env var
English, enterprisegoogleen-US-Neural2-F220+ voices, free tier
使用场景后端服务音色理由
默认/通用场景edgezh-CN-XiaoxiaoNeural免费,无需配置
短视频/抖音风格doubaoBV001_streaming原生短视频风格
有声书/长文本cosyvoicelongxiaochun_v3合成速度快,自然度高
企业级/SSML支持azurezh-CN-XiaoxiaoNeural丰富的韵律控制
批量处理/最低成本tencent1010010.75元/万字符
情感/方言支持baidu3或4情感合成,支持粤语
最佳音质/语音克隆minimaxfemale-shaonvspeech-2.6-hd模型,支持音色定制
教育场景/专业级xunfeixiaoyanMOS评分4.8,500+种音色
男声旁白edgezh-CN-YunxiNeural活力男声
纪录片风格azurezh-CN-YunyangNeural沉稳专业男声
儿童内容edgezh-CN-XiaomengNeural明亮年轻女声
成本敏感场景edgezh-CN-XiaoxiaoNeural完全免费
英文/顶级音质elevenlabs21m00Tcm4TlvDq8ikWAM (Rachel)业界最佳英文音色
英文/简洁低成本openaialloytts-1-hd模型,仅需一个环境变量
英文/企业级googleen-US-Neural2-F220+种音色,含免费额度

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:
data/providers.json
. View them via:
  • The comparison page (
    docs/providers.html
    ) — best for humans
  • python3 scripts/tts.py schema backends --full
    — full capability fields per backend
  • python3 scripts/tts.py schema voices
    — every voice preset with style descriptions
  • python3 scripts/tts.py --list
    — human-readable terminal summary
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
命令)

Create a custom voice from reference audio, store it under a name, then use the name anywhere
--voice
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).
bash
undefined
通过参考音频创建自定义音色,为其命名后,可在任何接受
--voice
参数的地方使用该名称。minimax(支持本地文件,音频时长10秒-5分钟,付费:全球站点约1.5美元/音色,国内站点首次使用约9.9元;新创建的克隆音色为临时状态,需在7天内(全球站点)/48小时内(国内站点)进行首次实际合成,否则MiniMax会删除该音色,预览不计入;首次合成后转为永久状态)和cosyvoice(免费注册,音频必须为公开http(s)URL,时长10-20秒,音色1年未使用即过期)原生支持该功能。
bash
undefined

MiniMax — 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
undefined
bash
undefined

Default (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
undefined
python3 scripts/tts.py --rate +15% "快速播报" fast.wav python3 scripts/tts.py --rate -10% "慢速朗读" slow.wav
undefined

From File

从文件读取文本

bash
python3 scripts/tts.py --input script.txt output.wav
bash
python3 scripts/tts.py --input script.txt output.wav

Output Format

输出格式

bash
undefined
bash
undefined

MP3 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
undefined
python3 scripts/tts.py --json --format mp3 "你好" hello.mp3
undefined

Preview (Dry Run)

预览(试运行)

bash
undefined
bash
undefined

Preview without making API call — no package installs needed

预览模式,不调用API — 无需安装依赖包

python3 scripts/tts.py --dry-run "这是一段测试文本"
undefined
python3 scripts/tts.py --dry-run "这是一段测试文本"
undefined

List Options

查看选项列表

bash
python3 scripts/tts.py --list
bash
python3 scripts/tts.py --list

Expressiveness 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.
MarkerSyntaxazureminimaxall other platforms
Pause
[PAUSE:x]
— x = seconds, 0.01-99.99
<break time="xs"/>
(SSML)
<#x#>
stripped
Sound tags
(laughs)
(chuckle)
(sighs)
(breath)
(inhale)
(exhale)
(coughs)
strippedvoiced only if
MINIMAX_MODEL
starts with
speech-2.8
(else stripped + stderr warning)
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
输入文本可包含以下标记,所有平台均支持——在支持原生渲染的平台会生效,其他平台会自动移除(不会被朗读)。文本分割器不会拆分
[...]
标记内的内容。
标记类型语法azureminimax其他所有平台
停顿
[PAUSE:x]
— x为秒数,范围0.01-99.99
转换为SSML的
<break time="xs"/>
转换为
<#x#>
自动移除
音效标签
(laughs)
(chuckle)
(sighs)
(breath)
(inhale)
(exhale)
(coughs)
自动移除仅当
MINIMAX_MODEL
speech-2.8
开头时会合成对应音效(否则自动移除并在stderr输出警告)
自动移除
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

Pronunciation Overrides (
--phonemes
)

发音修正(
--phonemes

Fix polyphonic Chinese characters (多音字) with a JSON dict mapping words to space-separated pinyin — tone-numbered (
hang2 zhang3
) or tone-marked (
háng zhǎng
). Keys starting with
_
are comments.
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.wav
Per-platform: azure → SSML
<phoneme alphabet="sapi">
tags; minimax → inline pinyin annotations like
重(chong2)庆(qing4)
(applied before chunking so the annotation counts toward the chunk budget); all other platforms silently ignore the flag.
通过JSON字典修正汉字多音字,键为词语,值为空格分隔的拼音——支持数字声调(
hang2 zhang3
)或带声调符号的拼音(
há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的
<phoneme alphabet="sapi">
标签;minimax→转换为内联拼音注释,如
重(chong2)庆(qing4)
(注释会占用文本分割的字符配额);其他平台会忽略该参数。

Requirements

依赖要求

bash
undefined
bash
undefined

Core (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
undefined
bash
undefined

Global 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/credentials
export 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/credentials

Config File (Optional)

配置文件(可选)

Create
~/.ttscn.json
for personal defaults, or
.ttscn.json
in a project directory:
json
{
  "backend": "minimax",
  "voice": "female-shaonv",
  "rate": "+10%"
}
Priority (highest first):
  1. CLI arguments (
    --platform
    ,
    --voice
    ,
    --rate
    )
  2. Environment variables (
    TTS_BACKEND
    ,
    TTS_VOICE
    ,
    TTS_RATE
    )
  3. Project config (
    .ttscn.json
    in current directory)
  4. User config (
    ~/.ttscn.json
    )
  5. Built-in defaults
创建
~/.ttscn.json
作为个人默认配置,或在项目目录中创建
.ttscn.json
json
{
  "backend": "minimax",
  "voice": "female-shaonv",
  "rate": "+10%"
}
优先级(从高到低):
  1. CLI参数(
    --platform
    ,
    --voice
    ,
    --rate
  2. 环境变量(
    TTS_BACKEND
    ,
    TTS_VOICE
    ,
    TTS_RATE
  3. 项目配置(当前目录下的
    .ttscn.json
  4. 用户配置(
    ~/.ttscn.json
  5. 内置默认值

Examples

示例

Quick Narration (Free, Zero Setup)

快速生成旁白(免费,无需配置)

bash
python3 scripts/tts.py \
  "人工智能正在改变我们的生活方式,从智能助手到自动驾驶,技术革新无处不在。" \
  ai_narration.wav
bash
python3 scripts/tts.py \
  "人工智能正在改变我们的生活方式,从智能助手到自动驾驶,技术革新无处不在。" \
  ai_narration.wav

Douyin Style Short Video Voice

抖音风格短视频配音

bash
python3 scripts/tts.py \
  --platform doubao --voice BV001_streaming --rate +10% \
  "家人们,今天给大家推荐一个超好用的神器!" \
  douyin_style.wav
bash
python3 scripts/tts.py \
  --platform doubao --voice BV001_streaming --rate +10% \
  "家人们,今天给大家推荐一个超好用的神器!" \
  douyin_style.wav

Audiobook from Script File (CosyVoice)

从脚本文件生成有声书(CosyVoice)

bash
python3 scripts/tts.py \
  --platform cosyvoice --voice longxiaoxia_v3 \
  --input chapter1.txt chapter1.wav
bash
python3 scripts/tts.py \
  --platform cosyvoice --voice longxiaoxia_v3 \
  --input chapter1.txt chapter1.wav

Bulk 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.wav
bash
TENCENT_SECRET_ID="xxx" TENCENT_SECRET_KEY="xxx" \
python3 scripts/tts.py \
  --platform tencent --voice 101001 \
  --input course_script.txt course_audio.wav

Premium Quality with Emotion (MiniMax)

带情感的高品质语音(MiniMax)

bash
MINIMAX_API_KEY="xxx" \
python3 scripts/tts.py \
  --platform minimax --voice female-shaonv \
  "这是一段充满感情的语音合成演示。" premium.wav
bash
MINIMAX_API_KEY="xxx" \
python3 scripts/tts.py \
  --platform minimax --voice female-shaonv \
  "这是一段充满感情的语音合成演示。" premium.wav

Agent-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
undefined
bash
undefined

Explicit 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,...}}

undefined
undefined

Output 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:
meta.schema_version
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
1
) and fail with a clear error otherwise. An absent
schema_version
means a pre-contract ttscn release.
json
// 成功响应
{"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":{...}}
规范
meta.schema_version
是语义化版本字符串,所有响应(成功/错误)均包含该字段。主版本号仅在封装格式发生破坏性变更时升级——消费者应断言该主版本号与预期一致(例如video-podcast-maker要求主版本为
1
),否则应返回清晰的错误信息。若缺少
schema_version
,则表示使用的是规范发布前的ttscn版本。

Word 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
data.word_boundaries
— 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.
json
{"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.
对于edgeazuredoubaominimaxcosyvoice,成功响应的封装中包含原生词级时间戳,存储在
data.word_boundaries
字段中——为输出音频中的绝对秒数,按升序排列,保留三位小数。其他平台不会返回该字段——doubao/minimax/cosyvoice在服务商未返回时间数据时也不会返回该字段(例如doubao的小语种音色、minimax字幕下载失败、cosyvoice-v1或不支持时间戳的音色)——因此消费者应将其视为可选字段。
json
{"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

退出码

CodeMeaningAgent action
0SuccessParse
data
, proceed
1Internal / runtime errorReport to user, do not retry
2Validation / fixable error (bad input, missing package)Fix input or install package, retry allowed
3Auth / missing credentialsAsk user for API key, do not retry
4Backend API errorRetry with backoff
代码含义Agent操作
0成功解析
data
字段,继续执行
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 freshness
bash
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
undefined
python3 scripts/tts.py schema backends --fields name,cost,supports_clone,supports_ssml
undefined

Idempotency

幂等性

bash
undefined
bash
undefined

Orchestrators: 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
undefined
bash
undefined

No-ops accepted for agent runtime compatibility (ttscn never prompts)

为兼容Agent运行时,接受无操作参数(ttscn从不弹出提示)

python3 scripts/tts.py --yes --no-input "text" out.wav
undefined
python3 scripts/tts.py --yes --no-input "text" out.wav
undefined