Skip to main content
You can let visitors talk to your SLNG voice agent directly in the browser. You need a small backend to create the web session (this keeps your API key off the client) and a frontend that connects to LiveKit for real-time audio.

Prerequisites

  • A configured agent and its agent ID. If you do not have one, see Create an agent.
  • An SLNG API key. See How to set up.
  • A backend you can deploy server-side code to (Node.js, Deno, Python, etc.)
  • A frontend project with React (the examples below use React, but the LiveKit client SDK works with any framework)

How it works

  1. The browser asks your backend to start a session.
  2. Your backend calls the SLNG web-sessions endpoint and forwards the LiveKit credentials back.
  3. The browser connects to the LiveKit room, publishes the mic, and plays the agent’s audio.

Build the integration

1

Create a backend endpoint

Your backend proxies the SLNG API so the API key never reaches the browser.
Never call the SLNG API directly from client-side code. Your SLNG_API_KEY must stay server-side.
The only call you need is:
The response includes the fields you need for the frontend:
Response
2

Install the LiveKit client SDK

livekit-client is LiveKit’s browser SDK. It opens the WebRTC connection to the room, publishes your microphone, subscribes to the agent’s audio, and delivers transcripts over a data channel. It ships TypeScript types and runs in any framework or in plain JavaScript.
This guide uses a few of its primitives:The SDK needs a secure context, so serve your page over HTTPS or localhost for the browser to allow microphone capture and WebRTC. For the full API, see the LiveKit JS client reference.
3

Connect to the LiveKit room

Call your backend to get a session, then connect to the room:
The browser will prompt the user for microphone access on createLocalAudioTrack(). If your page is not served over HTTPS, most browsers will block the request.
4

Play the agent's audio

Attach the agent’s remote audio track to the DOM so the browser plays it:
5

Show live transcripts

Transcript updates arrive over a LiveKit data channel on the slng.transcript.v1 topic:
Each transcript item has:
6

Add mute and disconnect controls

7

Detect who is speaking

The active-speakers event tells you when the agent is talking, so you can drive a visual indicator or avatar animation:

Optional: Add a visual persona

A voice-only interface gives users no visual cue about what the agent is doing. An animated persona such as an orb, waveform, or avatar makes the experience feel more responsive. Two ready-made libraries work well here:

Vercel AI SDK Persona

A React component with built-in states: idle, listening, speaking, thinking. Drop it in and map LiveKit events to states.

ElevenLabs Conversational UI

Orb and avatar components designed for voice interfaces, with audio-reactive animations.
To wire either library up, map your session and LiveKit events to persona states:

Putting it all together

A minimal React component with all the steps above wired together:
VoiceSession.tsx

Next steps