Back to skills
SKILL.md
Tts Generator
ASecurityGenerate speech audio from text using Gemini 3.8 Flash TTS (with emotion control) or Edge TTS fallback. Use when the user says "/tts", "语音合成", "文字转语音", "念出来", "读出来", "生成语音", "帮我念", "说出来", or when asked to convert text to speech audio.
- 5 stars
- 0 votes
- 0 copies
- 6 views
- Added September 13, 2026
Works with
Security analysis
100/100Pro scans all 2 files and shows the line behind each finding
npx -y skills add yangwhale/CloseCrab --skill tts-generator --agent claude-codeAre you the author of Tts Generator?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/yangwhale-tts-generator)---
name: tts-generator
description: Generate speech audio from text using Gemini 3.8 Flash TTS (with emotion control) or Edge TTS fallback. Use when the user says "/tts", "语音合成", "文字转语音", "念出来", "读出来", "生成语音", "帮我念", "说出来", or when asked to convert text to speech audio.
---
# TTS Generator (Gemini 3.8 Flash TTS)
Generate expressive speech audio using Google Gemini 3.8 TTS with emotion/audio tag support. Falls back to Edge TTS if Gemini is unavailable.
**默认(2026-12-04 起)**:模型 `gemini-3.8-flash-tts`、语言码 `zh-CN`、整段一次请求、
方括号情绪标签留在正文里(`--style-mode inline`)。可选 `--style "<一条短描述>"` 给整段加一个
全局 `speech_metadata.style`。Flash-Lite 快约 1/3,但实听方括号里的情绪基本丢了,所以不作默认。
**换模型不用重启**:把模型名写进 `~/.closecrab/tts_model`(第一行),每次调用现读,
bot 的流式语音和本脚本都生效;环境变量 `TTS_MODEL` 优先级更高,会把它钉死。其余环境变量:
`TTS_LANG`(`auto` = 让模型自己判断语言)、`TTS_STYLE`、`TTS_STYLE_MODE`。
缓存键带模型、语言和 style,切换任何一项都不会放旧音频。
## Usage
```bash
# Generate OGG audio (Gemini, default)
OGG=$(~/.claude/skills/tts-generator/scripts/tts-generate.py "[casually] 你好世界")
# Choose voice
OGG=$(~/.claude/skills/tts-generator/scripts/tts-generate.py "[excitedly] 太棒了!" --voice sulafat)
# Fallback to Edge TTS
OGG=$(~/.claude/skills/tts-generator/scripts/tts-generate.py "你好" --engine edge --voice xiaoxiao)
# Send as Discord voice message
~/.claude/scripts/send-to-discord.sh --voice "$OGG"
# Clean up
rm -f "$OGG"
```
## Gemini Voices (15 voices)
| 代号 | 风格 | 代号 | 风格 |
|------|------|------|------|
| `aoede` (default) | 轻松 | `achird` | 友好 |
| `sulafat` | 温暖 | `kore` | 坚定 |
| `puck` | 欢快 | `charon` | 知性 |
| `fenrir` | 兴奋 | `leda` | 青春 |
| `zephyr` | 明亮 | `achernar` | 柔和 |
| `gacrux` | 成熟 | `sadachbia` | 活泼 |
| `algieba` | 顺滑 | `vindemiatrix` | 温柔 |
| `orus` | 坚定 | | |
## Emotion Tags (Gemini only)
Gemini TTS 支持 inline audio tags 控制情感和风格。**有两种工作模式**,行为不同:
### 模式 A:单标签(director instruction)—— ⚠️ 在 3.8 上会把英文指令念出来,现只对旧模型生效
(2026-12-04 起:3.8 及以后的模型不再做这个改写,单标签也原样透传。)
只有一个开头标签时,旧版脚本把它改写成 `"Say the following in Chinese, casually:\n你好"`。
**Gemini 3.8 把输入严格当逐字稿**,这句英文会被念出来。2026-12-04 实测
(转写 + 时长):单标签 11/11 次念出 `Say the following in Chinese, …` 或标签词,
音频比同文本长约 2 秒。改成原样透传 `[seriously] 正文` 也不保险,3 次里 2 次念出 "Seriously"。`<voice-summary>[excitement] 搞定!…` 这类单标签语音总结
全中招。修法见下面的 `--style-mode metadata`(单标签 0 泄漏)。
### 模式 B:多个 inline 标签(raw passthrough)
文本里有 ≥2 个标签时,脚本不动它,原样 pass 给 Gemini。Gemini **只认它训练时见过的官方词**,自创词会被静默丢弃。一段话里想多次切换情绪(推荐用法,更生动)必须用下面的官方词:
**思考类**:`[thinking] [contemplative] [analysis] [focus] [reflection] [planning] [speculation] [pensive] [curiosity]`
**积极类**:`[excitement] [enthusiasm] [joy] [happy] [pleased] [optimism] [playful] [amusement] [friendly] [triumph] [satisfaction]`
**中性类**:`[neutral] [contentment] [serenity] [relaxation] [certainty]`
**严肃类**:`[seriousness] [urgency] [warning] [concern] [caution] [emphasis]`
**惊讶类**:`[surprise] [amazement] [realization] [confusion] [uncertainty] [doubt] [disbelief]`
**消极类**:`[disappointment] [frustration] [regret] [exhaustion] [weariness]`
**幽默类**:`[humor] [sarcasm] [amused] [self-deprecation]`
**自信类**:`[confidence] [determination] [assertive] [pride]`
**特效类**:`[laughs] [sighs] [slow] [fast]`
> ⛔ **不要用 `[whispers]`。** 它是 Gemini 官方标签、模型会照做,而照做的结果是
> 音量小到在手机外放、车里、地铁上根本听不见(Chris 2026-09-17 明确要求去掉)。
> CloseCrab 的 TTS 链路里 `normalize_tts_tags()` 会把它换成 `[casually]`,
> 所以写了也不生效 —— 但走本 skill 直接调 API 的场合没有那层兜底,别写。
**说明类**:`[informative] [explaining] [summary] [instruction] [suggestion]`
**多标签例子(好)**:
```
[curiosity] 我先看下日志。[realization] 哦原来是端口冲突。
[amused] 这种小坑最烦了。[suggestion] 你 kill 8080 那个就行。
```
**多标签例子(差)**:
```
[casually] 我看了日志发现端口冲突 你 kill 8080 就行
# 整段一个标签,且 [casually] 不是官方词,多标签场景下还会被丢
```
### `--style-mode metadata`(可选,官方 3.8 按段 style 写法,仅供 A/B)
12-04 上午曾短暂作为默认;当天 Chris 定回 inline:一段话里每 20 字左右换一个情绪标签、整段一次请求,不接受一句一个 style 的拆法。
脚本按方括号标签把文本切段,每段一个 content 项,标签翻成英文 `speech_metadata.style`
(映射表 `STYLE_MAP`,未知标签直接用原词),正文只留干净中文;开头没标签的段用
`natural, friendly, conversational`。`[laughs]` `[sighs]` `[pause]` 这类瞬时声音转成
3.8 的尖括号标签 `<laugh>` `<sigh>` `<short pause>`;正文里原有的 `<...>` 原样保留。
`[whispers]` 映射成 casual(同 `normalize_tts_tags()` 的规矩)。
| 后端 | 接口 | 备注 |
|---|---|---|
| Vertex(优先) | `generateContent`,`parts[].speechMetadata.style` | Vertex 的 Interactions API 不支持 3.8 TTS(400) |
| Developer API | `POST /v1beta/interactions`,`annotations[{type: speech_metadata, style}]` | 它的 `generateContent` 不认 `speechMetadata` |
两条都走 REST,不依赖 google-genai 版本。都失败就退回 inline 链,最后 Edge。
缓存 key 带模型、语言、模式和 style,换任何一项都不会串到旧音频。
## Edge TTS Voices (fallback)
- `xiaoxiao` — 女声(默认)
- `xiaoyi` — 女声,温柔
- `yunxi` — 男声,活力
- `yunjian` — 男声,成熟
- `yunyang` — 男声,新闻播报
- `yunxia` — 男声,少年
## Notes
- Output: OGG Opus (1ch, 48kHz, 48kbps)
- 3.8 unary 返回的已经是带 RIFF 头的 WAV,脚本检测到 `RIFF` 就直接写盘不再包一层
(以前双层头,开头 22 个假样本 = 一声咔哒)
- Gemini TTS needs `GOOGLE_API_KEY` env var or GCP Application Default Credentials
- Gemini supports 80+ languages with auto-detection
- If Gemini fails, automatically falls back to Edge TTS
Files in this skill
- SKILL.md
- scripts/tts-generate.py
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.