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

Placeholders

The snippets below use these placeholders. Replace them with your own values before running the code.

Prerequisites

  • A configured Voice Agent with its agent ID
  • An SLNG key (get one at app.slng.ai)
  • 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 Voice Agents 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.

Step 1: Create a backend endpoint

Your backend proxies the Voice Agents API so the SLNG key never reaches the browser.
Never call the Voice Agents 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:

Step 2: Install the LiveKit client SDK

Step 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.

Step 4: Play the agent’s audio

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

Step 5: Show live transcripts

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

Step 6: Add mute and disconnect controls

Step 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. Adding an animated persona (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:

Next steps