Engineering BlueprintReact RouterTypeScriptWebAudioWebSocketsSpeakOnSecuritySSRVercel

SpeakOn Phase 3: Zero-Backend Web UI with OpenAPI Types, AudioWorklet Streaming, and PNA Loopback

Integrating SpeakOn into React Router 7 SSR without any server-side backend or database: openapi-fetch typed schemas, Push-to-Talk MediaRecorder, 16 kHz…

Célio Vieira573 words3 min read

Key Takeaways (TL;DR)

Summary
  • Zero Cloud Backend, Full Local Voice Immersion — Most web apps mirror every feature behind hosted database tables and metered API gateways.
  • Typed Browser Client & Safe React Router 7 Hydration — 1.
  • Push-to-Talk & 16 kHz AudioWorklet Hands-Free Streaming — The SpeakOn workspace supports two complementary low-latency capture paths:
  • Verification, Bundle Budgets, and Live Integration Smoke — Next up in Phase 4: building the native mobile client in speakon/mobile/ using Expo Prebuild (CNG), expo-sqlite…

Zero Cloud Backend, Full Local Voice Immersion#

Most web apps mirror every feature behind hosted database tables and metered API gateways. In Phase 3 of SpeakOn, we integrated the entire language tutor workspace (aldeon.app/speakon/* and speakon.aldeon.app) inside aldeon/app (develop) with zero api.*.ts endpoints and zero server-side fetches to localhost.

Every page renders cleanly on the server for SEO and accessibility, while authenticated voice turns, Ollama model discovery, history, streaks, and mobile QR pairing communicate strictly from the learner's browser directly to their local 127.0.0.1:8000 FastAPI orchestrator.

Typed Browser Client & Safe React Router 7 Hydration#

  1. OpenAPI Type Generation (schema.d.ts): Running openapi-typescript against speakon-services/openapi.json keeps request payloads and responses synchronized with FastAPI without hand-maintained DTOs. Because aldeon/app runs typescript@7.0.2, generating the declaration file isolates typescript@5.8.3 inside speakon:types so both OpenAPI codegen and native TypeScript 7 typechecking succeed cleanly.
  2. Rotating Refresh Sessions & Authenticated WAV Playback (api/client.ts): Wrapping openapi-fetch with single-flight POST /api/auth/refresh recovery prevents concurrent 401 storms, while fetchAudioBlobUrl() attaches Bearer credentials cleanly so private WAV tutor clips play back without exposing tokens in query parameters.
  3. Strict SSR Safety (SpeakOnContext.tsx): Server renders never touch localStorage during useState(...) initialization; persisted server URLs and rotating session tokens hydrate safely inside useEffect.

Push-to-Talk & 16 kHz AudioWorklet Hands-Free Streaming#

The SpeakOn workspace supports two complementary low-latency capture paths:

  • Push-to-Talk (lib/pttRecorder.ts): Captures compressed browser audio via MediaRecorder, renders real-time microphone RMS waveform bars from AnalyserNode, and posts multipart audio directly to POST /api/sessions/{id}/turn.
  • Hands-Free WebSocket (public/speakon-pcm-worklet.js & lib/voiceWs.ts): Loads an AudioWorkletProcessor that resamples browser audio to 16000 Hz mono Int16Array in 512-sample (1024-byte) frames matching Silero VAD's exact server frame size. Incoming WAV chunks queue seamlessly inside WebAudio (WebAudioPlaybackQueue), while hitting Interrupt / Stop Audio sends { type: 'cancel' } and clears active audio immediately for natural barge-in.

Multilingual UI, Mandarin Pinyin & Security Guardrails#

  • Two-Tier Language Picker: Features English, Spanish, and Mandarin Chinese upfront, groups Portuguese, German, Italian, and French under collapsible All Languages, and adds a dedicated Mandarin tone-colored Pinyin / Hanzi toggle alongside collapsible grammar corrections and word confidence breakdowns.
  • Browser Permissions & Subdomain Routing (vercel.json): Adds the speakon.aldeon.app 308 redirect rules and scopes Permissions-Policy: camera=(), microphone=(self), geolocation=() strictly to /speakon and /speakon/(.*) while leaving global camera/mic locked down elsewhere.
  • No innerHTML, No Passwords: Mobile QR codes generated via POST /api/pairing/start render strictly through an image element bound to the qr_svg_data_uri data URI, and password inputs are banned and asserted absent in speakon.test.ts.

Verification, Bundle Budgets, and Live Integration Smoke#

  • Typecheck, Lint & Tests: bun run check passed react-router typegen && tsc, biome lint across 582 files, and 225 / 225 bun test unit, AST i18n-parity, SEO/GEO, and SSR safety checks.
  • SSR & Performance Budget: bun run verify:ssr verified client bundle security rules and 218 production SSR renders cleanly; bun run perf:budget:strict kept SpeakOnLandingPage at 188.9 KB gzipped JS (budget 220 KB) and 44.4 KB gzipped CSS (budget 45 KB).
  • Live E2E & DNS Gate 3: Verified live OPTIONS CORS + Private Network Access preflight (https://aldeon.app -> http://127.0.0.1:8012), live HTTP 200 renders across all 7 workspace/onboarding routes, Mailpit passwordless OTP authentication, and real en, es, and zh turns producing valid audio and tone-marked Pinyin—plus verified speakon.aldeon.app wildcard resolution with intact Resend MX/SPF/DKIM records.

Next up in Phase 4: building the native mobile client in speakon/mobile/ using Expo Prebuild (CNG), expo-sqlite offline cache, USB adb reverse, and LAN QR pairing.

Célio Vieira

Célio Vieira

Founder & Architect

Engineering applied AI systems, distributed cloud platforms, and the Aldeon umbrella venture ecosystem.

Related Technical Dispatches

View all 90