← back to SERVICE

Relay Live Translate

A web app that translates speech in real time with Gemini Live and saves the original and the translation per session in Supabase. A personal project I built alone for a business trip to the US.

stack
JavaScript, Gemini Live API, Web Audio API, Supabase, PostgreSQL, Google OAuth, Node.js test runner
Cost per minute (max)

$0.037

estimate from token prices

Build time

8 days

22 commits, 2026-07-03 to 07-10

What I did
  • Planned and built it alone, using an AI coding agent as an implementation partner.
  • Rebuilt an old single-file app as a state machine, a store, a router and a translation engine.
  • Added Google sign-in and session storage with Supabase, with row-level security so each person sees only their own records.

Problem

On a business trip to the US, I needed something that let me follow English conversations in real time and keep the original and the translation to read again later.

What I built

  • Audio from the microphone or a shared browser tab goes to Gemini Live as 16 kHz PCM, and the translated audio (24 kHz) and captions come back and play.
  • The original and the translation are saved per session. They are stored in the browser first, then synced to Supabase, and the app still works in a local-only mode without Supabase.
  • Supabase holds two tables, sessions and segments. Row-level security policies let people read and write only their own sessions and segments, and anonymous access is revoked.
  • Each session shows an estimated cost, and transcripts export as TXT.

Trial and error

  • Paragraphs that never ended: The model never sends an end-of-turn signal, so a paragraph closes after the text has paused for 2.5 seconds. Audio arrives seconds after the text, so audio does not restart that timer.
  • Ghost reconnects: After a connection closes, the app reconnects 0.6 seconds later, and a stop or language change in that gap brought the wrong session back. Each start and stop now bumps a generation number, and a reconnect runs only if the generation still matches. Changing the language uses the same path to open a session in the new language.
  • Lost records: A review found three real bugs, including a sync queue that dropped work added while a push was in flight. Failed work now goes to its own queue and retries when the app is back online.
  • Sign-in versus the router: The hash router (#/) clashed with the OAuth callback, so I used PKCE, which returns the callback as a query string. Sign-in also moved from email OTP to Google.
  • A slow CDN: The Supabase client loads only when needed, so a slow CDN cannot block translation or local saving.
  • Key exposure: A Gemini key in client code is visible to every visitor, so on a server it may live only behind Cloudflare Access. Supabase gets only its publishable key.

Quality

  • 27 unit tests (helpers, store, sync) run on the Node.js built-in test runner.
  • From token prices, the cost is at most about $0.037 per minute, or about $0.021 when people speak half the time.