百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
C

cloudflare-edge-tts

> 编程语言
开源

Cloudflare-edge-tts 一个最小的 Cloudflare 工作程序,它通过 Worker 原生实现,通过 HTTP 将 Microsoft Edge 文本转换为语音。

198 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Cloudflare-edge-tts 一个最小的 Cloudflare 工作程序,它通过 Worker 原生实现,通过 HTTP 将 Microsoft Edge 文本转换为语音。

cloudflare-edge-tts

Minimal Cloudflare Worker that exposes Microsoft Edge Text-to-Speech over HTTP using a Worker-native implementation built on fetch(..., { Upgrade: "websocket" }).

Endpoints

GET /health

Returns a lightweight health response:

json
{
  "ok": true
}

GET /voices

Returns the available Edge TTS voices:

json
{
  "voices": [
    {
      "Name": "Microsoft Server Speech Text to Speech Voice (en-US, AvaMultilingualNeural)",
      "ShortName": "en-US-AvaMultilingualNeural"
    }
  ]
}

The voices payload includes ShortName values. This Worker's default voice is en-US-AvaMultilingualNeural. Callers may pass any discovered ShortName, and the Worker also accepts certain provider-style aliases when they can be mapped to a compatible Edge TTS voice.

POST /tts

Synthesizes speech and streams audio/mpeg back to the client.

Request body:

json
{
  "text": "你好,世界",
  "voice": "en-US-AvaMultilingualNeural"
}

voice is optional. When omitted, the Worker uses en-US-AvaMultilingualNeural.

Validation and error behavior:

  • Requires Content-Type: application/json
  • Requires a non-empty string text
  • Rejects empty voice strings
  • Returns 502 when the upstream TTS request fails before the audio response starts, for example before or while priming the first chunk

Setup

Install dependencies:

bash
npm install

Generate Worker environment types:

bash
npm run cf-typegen

Development

Remote runtime development with Cloudflare:

bash
npm run dev

Local runtime development:

bash
npm run dev:local

Testing

Run the test suite:

bash
npm test

Run TypeScript checks:

bash
npm run typecheck

Remote Smoke Test

Real-runtime validation uses wrangler dev --remote.

Confirm the authenticated Cloudflare account:

bash
npx wrangler whoami

Start the remote dev server on localhost:

bash
npm run dev

Use the actual URL printed by Wrangler if it differs from http://127.0.0.1:8787.

In another terminal, run the smoke test:

…

Expected checks:

  • /health should return 200
  • /voices should write headers to /tmp/cloudflare-edge-tts-voices.headers, write JSON to /tmp/cloudflare-edge-tts-voices.json, and report an HTTP 200 status
  • The voices response should contain one or more ShortName entries
  • /tts should write headers to /tmp/cloudflare-edge-tts-tts.headers, write the response body to /tmp/cloudflare-edge-tts-tts.body, and report the HTTP status
  • A successful /tts call should be 200 with audio/mpeg; a failure should remain inspectable as headers plus a non-audio body, such as a JSON error response

Deployment

Deploy the Worker:

bash
npm run deploy

Implementation Note

This Worker does not rely on edge-tts-universal at runtime. It performs the voice-list fetch and WebSocket synthesis handshake directly inside the Worker runtime.

Notes

Observed remote validation result on 2026-04-10 with wrangler 4.81.1:

  • npx wrangler whoami succeeded
  • The authenticated Cloudflare account context used for the run was 1f1d1678a2413a54c944b3081bab5c84
  • npm run dev started wrangler dev --remote, uploaded a remote preview, and reported Ready on http://localhost:8787
  • curl -i --max-time 20 http://127.0.0.1:8787/health returned 200 OK
  • The /voices smoke test returned 200, produced /tmp/cloudflare-edge-tts-voices.headers, and wrote a JSON payload containing ShortName entries to /tmp/cloudflare-edge-tts-voices.json
  • The /tts smoke test returned 200, produced /tmp/cloudflare-edge-tts-tts.headers, and wrote an audio/mpeg body to /tmp/cloudflare-edge-tts-tts.body

This means the current Worker-native implementation was verified successfully against both wrangler dev --local and wrangler dev --remote in this environment.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言