Skip to content

feat: add edge-tts demo - #24

Open
luke-speechify wants to merge 3 commits into
mainfrom
feat/edge-tts
Open

feat: add edge-tts demo#24
luke-speechify wants to merge 3 commits into
mainfrom
feat/edge-tts

Conversation

@luke-speechify

Copy link
Copy Markdown
Contributor

Pairs with the upcoming speechify.ai post "One-file serverless TTS on an edge function".

What this adds

A demo whose entire backend is a single serverless edge function that streams Speechify text-to-speech audio to the browser.

  • demos/edge-tts/app/api/stream/route.ts — the one file. export const runtime = "edge". It verifies Turnstile, then calls POST https://api.speechify.ai/v1/audio/stream with fetch and pipes the upstream MP3 body straight back to the client. The @speechify/api SDK is Node-only, so the edge route deliberately uses the REST API directly.
  • app/page.tsx — minimal UI: textarea + Play button. POSTs text (plus x-turnstile-token) to the edge route, reads the streamed response as a blob, and plays it.
  • The appeal is that the backend is one small edge file — ideal for widgets and light integrations.

Server-side key + Turnstile

SPEECHIFY_API_KEY is only ever read via process.env inside the edge function and never reaches the browser. Every request to the route passes through verifyTurnstile(req) first (fails open locally when TURNSTILE_SECRET_KEY is unset), returning 403 otherwise.

Hosting registration

  • vercel.json — added an edge-tts service and a /edge-tts/:path* rewrite before the / and catch-all rewrites.
  • pnpm-workspace.yaml — added demos/edge-tts.
  • Ran pnpm install + pnpm generate (README table + site manifest regenerated).

Verification

  • pnpm --filter edge-tts build ✅ (edge route compiles as a dynamic function).
  • Live API call ✅ — POST https://api.speechify.ai/v1/audio/stream with voice_id: geffen_32, model: simba-3.2, audio_format: mp3 returned HTTP 200, content-type: audio/mpeg, ~40 KB of valid MP3.

One serverless edge function that streams Speechify TTS audio to the
browser. Calls the REST audio/stream endpoint with fetch (the SDK is
Node-only), pipes the upstream MP3 body straight through, and keeps the
API key server-side. Turnstile-gated. Registered as a Vercel Service.
@vercel

vercel Bot commented Aug 20, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
speechify-api-demos Ready Ready Preview Aug 21, 2026 12:28am

Request Review

demos.speechify.ai is one Vercel project of many Services, and the Edge
runtime isn't supported there — the preview failed at deploy with 'Edge
Runtime is not supported in services'. Switch the streaming route to the
Node runtime (which streams the response body just the same) and reword the
demo to a serverless streaming function, noting the same one file runs on
Edge in a standalone project.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant