English | 中文
把微软 Edge 的神经网络语音合成能力,包装成 OpenAI TTS API 兼容格式,部署在 Cloudflare Workers 上。免费、快速、无需服务器!
- 🆓 完全免费 - 基于 Edge TTS,无需付费 API
- 🚀 超低延迟 - Cloudflare 全球边缘网络加速
- 🔌 OpenAI 兼容 - 直接替换 OpenAI TTS API,无缝迁移
- 🎭 多种音色 - 6 种预设音色 + 支持所有 Edge TTS 原生音色
- 🛡️ 安全可控 - 自定义 API Key 保护
- 📱 自带 WebUI - 浏览器直接测试,无需写代码
- 登录 Cloudflare Dashboard
- 进入 Workers & Pages → Create Application → Create Worker
- 随便起个名字,点击 Deploy
- 点击 Edit code,删除默认代码,粘贴
worker.js的内容 - 点击 Save and Deploy 🎉
git clone https://github.com/snakeying/edge-tts-worker.git
cd edge-tts-worker
npx wrangler deploy部署后,进入 Worker 设置:
Settings → Variables → Add variable
| Variable name | Value |
|---|---|
API_KEY |
你的自定义密钥(如 sk-my-secret-key) |
⚠️ 不设置 API Key 的话,API 会返回 500 错误哦!
POST https://your-worker.your-subdomain.workers.dev/v1/audio/speech
完全兼容 OpenAI TTS API:
{
"model": "tts-1",
"input": "你好,世界!",
"voice": "alloy",
"speed": 1.0
}基础用法 🎯
curl -X POST "https://your-worker.workers.dev/v1/audio/speech" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "你好,这是一段测试语音。",
"voice": "alloy"
}' \
--output speech.mp3调整语速 🏃
curl -X POST "https://your-worker.workers.dev/v1/audio/speech" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "这段话会说得比较快!",
"voice": "nova",
"speed": 1.5
}' \
--output fast.mp3使用原生 Edge TTS 音色 🎭
curl -X POST "https://your-worker.workers.dev/v1/audio/speech" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "Hello, this is a test with English voice.",
"voice": "en-US-JennyNeural"
}' \
--output english.mp3高级参数 🔧
curl -X POST "https://your-worker.workers.dev/v1/audio/speech" \
-H "Authorization: Bearer your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "tts-1",
"input": "这是一段**带格式**的文本,包含链接 https://example.com 和表情 😊",
"voice": "shimmer",
"speed": 1.2,
"pitch": 1.1,
"style": "cheerful",
"cleaning_options": {
"remove_markdown": true,
"remove_emoji": true,
"remove_urls": true
}
}' \
--output advanced.mp3curl "https://your-worker.workers.dev/v1/models" \
-H "Authorization: Bearer your-api-key"| Voice | 描述 | Edge TTS 音色 |
|---|---|---|
shimmer |
温柔女声 | zh-CN-XiaoxiaoNeural |
alloy |
专业男声 | zh-CN-YunyangNeural |
fable |
激情男声 | zh-CN-YunjianNeural |
onyx |
活泼女声 | zh-CN-XiaoyiNeural |
nova |
阳光男声 | zh-CN-YunxiNeural |
echo |
东北女声 | zh-CN-liaoning-XiaobeiNeural |
💡 也可以直接使用任何 Edge TTS 原生音色,如
en-US-JennyNeural、ja-JP-NanamiNeural等
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
model |
string | tts-1 |
模型名称(兼容用,实际不影响) |
input |
string | 必填 | 要转换的文本 |
voice |
string | shimmer |
音色名称 |
speed |
number | 1.0 |
语速 (0.5 - 2.0) |
pitch |
number | 1.0 |
音调 (0.5 - 1.5) |
style |
string | general |
语音风格 |
role |
string | - | 角色扮演 |
styleDegree |
number | 1.0 |
风格强度 (0.01 - 2.0) |
stream |
boolean | false |
流式输出 |
cleaning_options |
object | - | 文本清理选项 |
| 选项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
remove_markdown |
boolean | true |
移除 Markdown 格式 |
remove_emoji |
boolean | true |
移除 Emoji |
remove_urls |
boolean | true |
移除 URL |
remove_line_breaks |
boolean | false |
移除换行符 |
remove_citation_numbers |
boolean | true |
移除引用标记 [1] |
custom_keywords |
string | - | 自定义移除关键词(逗号分隔) |
部署后直接访问 Worker 根路径即可使用内置测试页面:
https://your-worker.workers.dev/
from openai import OpenAI
client = OpenAI(
api_key="your-api-key",
base_url="https://your-worker.workers.dev/v1"
)
response = client.audio.speech.create(
model="tts-1",
voice="alloy",
input="你好,世界!"
)
response.stream_to_file("output.mp3")import OpenAI from 'openai';
const openai = new OpenAI({
apiKey: 'your-api-key',
baseURL: 'https://your-worker.workers.dev/v1',
});
const mp3 = await openai.audio.speech.create({
model: 'tts-1',
voice: 'alloy',
input: '你好,世界!',
});
const buffer = Buffer.from(await mp3.arrayBuffer());
await fs.promises.writeFile('output.mp3', buffer);Q: 免费额度够用吗?
A: Cloudflare Workers 免费版每天 10 万次请求,个人使用绑绑有余 ✌️
Q: 支持哪些语言?
A: Edge TTS 支持 100+ 种语言和地区变体,完整列表看这里
Q: 为什么返回 500 错误?
A: 大概率是没设置 API_KEY 环境变量,去 Worker Settings 里加上就好
Q: 长文本会被截断吗?
A: 不会!代码会自动按句子边界智能分块,然后拼接成完整音频 🧠
MIT License - 随便用,开心就好 😄
- Microsoft Edge TTS - 提供高质量语音合成
- Cloudflare Workers - 提供免费边缘计算平台
如果觉得有用,给个 ⭐ Star 呗~
