Skip to main content
This guide builds a working voice agent in a Vite + React project. Vite serves only static assets, so the one extra piece is a tiny Node server that proxies TTS requests — your Rime API key must never ship to the browser. There is no Rime npm package to install — and you don’t need one. Rime is a single HTTPS API; the proxy below is plain fetch.

Prerequisites

  • A Rime API key from the API Tokens page, exported as RIME_API_KEY
  • A Vite + React project (npm create vite@latest -- --template react-ts defaults work)
  • Express for the proxy: npm install express

1. The TTS proxy server

Create server.mjs in the project root:
server.mjs
Wire the Vite dev server to it in vite.config.ts, so the browser can call a same-origin /api/tts:
vite.config.ts
Run both and verify the proxy before touching the UI:
test.mp3 should be playable audio. A 401 means RIME_API_KEY isn’t visible to server.mjs.

2. Client: mic in, Rime audio out

Replace src/App.tsx. It uses the browser’s built-in SpeechRecognition for input (Chrome/Edge/Safari), a stub respond() function as the agent brain, and the proxy for the voice:
src/App.tsx
Open http://localhost:5173, click Speak, say something, and the agent answers in Rime’s astra voice.
In production, deploy server.mjs (or fold the route into whatever backend you already have) and serve Vite’s built assets from it — the same-origin /api/tts path keeps working. The API key lives only in the server environment.

Want streaming?

For incremental synthesis — audio starts playing while later sentences are still generating — connect your server to Rime’s WebSocket API and relay events to the browser. Rime’s WebSocket endpoints authenticate with an Authorization header, which browser WebSockets cannot send, so the bridge always lives server-side. The bridge pattern is identical to the one in the Next.js guide; the /ws3 message schema is in the Coda WebSocket reference.

Next steps

WebSocket API overview

Endpoints, word-level timestamps, context IDs, and interruption handling.

Voices

Swap astra for any Coda voice across six languages.

Streaming formats

Choose between Opus, MP3, WAV, PCM, and μ-law for your latency budget.

TTS in five minutes

The core API walkthrough in cURL, Python, JavaScript, and TypeScript.