RIME_API_KEY on the server. Call Rime over HTTPS with fetch; no Rime-specific npm package is required. The optional WebSocket bridge adds the only new dependency, ws.
Architecture: the browser never talks to Rime directly. Your API key stays server-side, and the browser calls your own /api/tts route:
Prerequisites
- A Rime API key from the API Tokens page. Put it in
.env.localasRIME_API_KEY=... - A Next.js 14+ project using the App Router (
npx create-next-app@latestdefaults work)
1. Server: the TTS proxy route
Createapp/api/tts/route.ts (or src/app/api/tts/route.ts if your project uses src/):
app/api/tts/route.ts
test.mp3 should be playable audio. If you get a 401, check that RIME_API_KEY is set in .env.local and the dev server was restarted after adding it.
2. Client: mic in, Rime audio out
Createapp/voice-agent/page.tsx. It uses the browser’s built-in SpeechRecognition for input (Chrome/Edge/Safari), a stub respond() function as the agent brain, and your /api/tts route for the voice:
app/voice-agent/page.tsx
http://localhost:3000/voice-agent, select Speak, say something, and the agent answers in Rime’s astra voice.
3. Stream over WebSockets when latency matters
The HTTP route above is the right default for most apps. Switch to WebSockets for incremental synthesis, where audio starts while the rest of the sentence is still being generated, or for barge-in handling with word-level timestamps. Two things make the WebSocket setup different:- Rime’s WebSocket endpoints authenticate with an
Authorizationheader, which browser WebSockets cannot send. The bridge must live on your server, where it also keeps the API key off the client. - Next.js route handlers can’t hold WebSocket connections, so you need a small custom server.
ws, then create server.mjs in the project root:
server.mjs
dev/start scripts at it:
package.json
/ws3 schema, including chunk, timestamps, done, and error events plus the flush, clear, and eos operations. The WebSocket overview covers segmentation and interruption patterns.
Production building blocks
WebSocket API overview
Endpoints, word-level timestamps, context IDs, and interruption handling.
Voices
Swap
astra for any Coda voice. Coda covers eight languages, and each voice serves one of them.Streaming formats
Choose between Opus, MP3, WAV, PCM, and μ-law for your latency budget.
LiveKit & Pipecat
Use the ready-made Rime plugins when a framework should own transport and orchestration.

