cloudflare-edge-tts Minimal Cloudflare Worker that exposes Microsoft Edge Text-to-Speech over HTTP using a Worker-native implementation bui…
cloudflare-edge-tts Minimal Cloudflare Worker that exposes Microsoft Edge Text-to-Speech over HTTP using a Worker-native implementation bui…
Minimal Cloudflare Worker that exposes Microsoft Edge Text-to-Speech over HTTP using a Worker-native implementation built on fetch(..., { Upgrade: "websocket" }).
GET /healthReturns a lightweight health response:
{
"ok": true
}GET /voicesReturns the available Edge TTS voices:
{
"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 /ttsSynthesizes speech and streams audio/mpeg back to the client.
Request body:
{
"text": "你好,世界",
"voice": "en-US-AvaMultilingualNeural"
}voice is optional. When omitted, the Worker uses en-US-AvaMultilingualNeural.
Validation and error behavior:
Content-Type: application/jsontextvoice strings502 when the upstream TTS request fails before the audio response starts, for example before or while priming the first chunkInstall dependencies:
npm installGenerate Worker environment types:
npm run cf-typegenRemote runtime development with Cloudflare:
npm run devLocal runtime development:
npm run dev:localRun the test suite:
npm testRun TypeScript checks:
npm run typecheckReal-runtime validation uses wrangler dev --remote.
Confirm the authenticated Cloudflare account:
npx wrangler whoamiStart the remote dev server on localhost:
npm run devUse 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 statusShortName 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/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 responseDeploy the Worker:
npm run deployThis 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.
Observed remote validation result on 2026-04-10 with wrangler 4.81.1:
npx wrangler whoami succeeded1f1d1678a2413a54c944b3081bab5c84npm run dev started wrangler dev --remote, uploaded a remote preview, and reported Ready on http://localhost:8787curl -i --max-time 20 http://127.0.0.1:8787/health returned 200 OK/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/tts smoke test returned 200, produced /tmp/cloudflare-edge-tts-tts.headers, and wrote an audio/mpeg body to /tmp/cloudflare-edge-tts-tts.bodyThis means the current Worker-native implementation was verified successfully against both wrangler dev --local and wrangler dev --remote in this environment.
No open issues yet, or sync has not completed.