feat: add edge-tts demo - #24
Open
luke-speechify wants to merge 3 commits into
Open
Conversation
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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 callsPOST https://api.speechify.ai/v1/audio/streamwithfetchand pipes the upstream MP3 body straight back to the client. The@speechify/apiSDK is Node-only, so the edge route deliberately uses the REST API directly.app/page.tsx— minimal UI: textarea + Play button. POSTs text (plusx-turnstile-token) to the edge route, reads the streamed response as a blob, and plays it.Server-side key + Turnstile
SPEECHIFY_API_KEYis only ever read viaprocess.envinside the edge function and never reaches the browser. Every request to the route passes throughverifyTurnstile(req)first (fails open locally whenTURNSTILE_SECRET_KEYis unset), returning 403 otherwise.Hosting registration
vercel.json— added anedge-ttsservice and a/edge-tts/:path*rewrite before the/and catch-all rewrites.pnpm-workspace.yaml— addeddemos/edge-tts.pnpm install+pnpm generate(README table + site manifest regenerated).Verification
pnpm --filter edge-tts build✅ (edge route compiles as a dynamic function).POST https://api.speechify.ai/v1/audio/streamwithvoice_id: geffen_32,model: simba-3.2,audio_format: mp3returnedHTTP 200,content-type: audio/mpeg, ~40 KB of valid MP3.