Guide · Developer
How to Add Voice Chat to a Browser Game
Add voice chat to a browser game with VoltKit's JavaScript SDK: a room per match, tokens from your backend, push-to-talk, speaking rings, emotes and the cost.
- Author
- VoltKit
- Published
- Reading time
- 8 min read
Voice makes a multiplayer browser game feel like a table: players call moves, laugh at mistakes and keep each other in the game. Building that from the browser's WebRTC API alone means signalling, relay servers and reconnection logic. With VoltKit RTC a match is a room, each player joins it with a token from your backend, and the JavaScript SDK does the rest. This guide adds voice chat to a browser game with @voltkit-rtc/client: one room per match, a token endpoint, push-to-talk, speaking rings, emotes in chat and the cost of a match.
The game can be any web game: a board such as Connect Four, a quiz or an arena. The SDK gives you tracks and events and leaves the screen to you. The games on VoltKit run entirely in the browser with no server at all; voice is the one feature that needs a service, since sound has to reach the other players.
Before you start
You need a VoltKit account and an RTC project; the quickstart creates both and gives you the API base URL and secret. A new project starts with every media option off: open the project's Settings tab, find Media and quality, and switch on standard voice, or the SDK refuses the microphone with the code media-disabled.
Browsers offer the microphone only on HTTPS or localhost, so serve the game over HTTPS before you test on a phone.
Every account gets 10,000 free participant-minutes every month, shared by all your projects, at any quality. They are spent before anything paid, so you can build and test the whole feature before you recharge anything. What the free minutes cover has the rules.
Step 1: one room per match
A match is a room. When your game server creates a match, it creates the room with the same id, and every player who is admitted to the match gets a token for that room. Use an id nobody can guess, such as a random UUID, so a player cannot join a match they were not invited to.
Roles decide who may speak:
| Role | Speaks | Typical use |
|---|---|---|
host | yes | the player who made the lobby, with moderation calls |
cohost | yes | every other player |
viewer | no | a spectator who listens |
Step 2: mint tokens on your backend
The browser never holds your API secret. Your backend signs the player in with your own login, creates the room if needed and returns a short-lived token for that player with the role you decide. With the Node.js server SDK:
// Create the room, or get it back if it already exists.
const room = await rtc.ensureRoom({ roomId: "show-42", hostIdentity: "user-7" });
// -> { roomId, originNode, hostToken, wsUrl, expiresAt, existed, ... }
// Let someone in, with the role YOU decide.
const { token, wsUrl, expiresAt } = await rtc.createToken({ roomId: "show-42", identity: "user-99", role: "viewer" });
For a match, use the match id as roomId, the player's own user id as identity, and cohost as the role for every player who may talk. When the match ends, rtc.deleteRoom(roomId) ends the voice room for everyone. The same endpoint in Python, Go, PHP and Spring Boot is in build a token server. Ask for a token right before joining: tokens are short-lived, and the service refreshes them during the session.
Step 3: join the room from the game
npm install @voltkit-rtc/client
Fetch the token, make a client, wire the events and connect. Wire the events before connect(), because players who are already talking arrive during the join:
import { StreamClient } from "@voltkit-rtc/client";
const { token, wsUrl } = await fetch(`/api/calls/${callId}/token`, { method: "POST" }).then((r) => r.json());
const client = new StreamClient(wsUrl, token);
// Wire events before connecting: tracks that are already
// being published arrive during connect().
client.on("track", ({ producerId, identity, kind, source, track }) => {
const element = mediaElementFor(producerId, identity, kind, source); // your <video> or <audio>
element.srcObject = new MediaStream([track]);
void client.play(element); // see "Sound that needs a tap"
});
client.on("trackEnded", ({ producerId }) => removeMediaElement(producerId));
client.on("participantJoined", (p) => addToRoster(p));
client.on("participantLeft", ({ identity, reason }) => removeFromRoster(identity, reason));
client.on("closed", (reason) => leaveScreen(reason));
const joined = await client.connect(); // rejects when the join is refused: see Errors
In a game, mediaElementFor returns a hidden <audio> element per player: there is nothing to draw for sound. participantLeft says why someone went: left when they closed the tab, disconnected when their connection dropped, in which case their SDK reconnects and they come back within seconds, so keep their seat.
Browsers often refuse to play sound until the player has touched the page. Join from the "Start match" click; for safety, ask for a tap when the browser refuses:
client.on("autoplayFailed", ({ resume }) => showTapToUnmute(resume)); // call resume() from the tap
Step 4: the microphone and push-to-talk
Players with the cohost or host role publish their microphone: open it with navigator.mediaDevices.getUserMedia({ audio: true }) from a click, then pass the stream to client.publish(stream). There is no camera, so the project's video setting can stay off.
Most games want push-to-talk rather than an open microphone. Publish once, then switch the microphone on with client.setMicEnabled(true) on the key down and off with client.setMicEnabled(false) on the key up. Switching is instant, and the other players see it on the trackMuted event, the moment to draw a muted icon. A mute button is the same call.
Games are played in noisy rooms. The SDK's noise suppressor, createNoiseSuppressor from @voltkit-rtc/client/noise-suppression, runs in the browser and takes keyboard clatter and fans out of the microphone; pass it to client.setAudioProcessor before or after you publish.
Step 5: show who is talking
A speaking ring around the player's avatar tells everyone who is on the microphone, which matters more in a game than in a call, because players look at the board:
client.on("audioLevels", (levels) => levels.forEach((l) => tileFor(l.identity).ring(l.speaking)));
client.on("activeSpeakers", ({ speakers }) => showLarge(speakers[0]));
audioLevels arrives a few times a second for every voice you receive and for your own microphone, so your own ring doubles as a push-to-talk check: if it never lights, the key binding or the permission is wrong.
Step 6: emotes and quick chat
Every room has a chat channel on the same connection, so "gg" and emotes need no second service. A reaction sent as an ephemeral message is delivered to everyone and never stored, which is what an emote should be:
await client.sendMessage("hello everyone");
await client.sendMessage("psst", { to: "user-42" }); // direct message
await client.sendMessage("", { type: "reaction", metadata: { emoji: "heart" }, ephemeral: true }); // not stored
Every message, your own included, arrives on the message event. Chat messages are not billed. A direct message reaches one player, so a team can whisper, and the host can mute a player in chat with muteChat without touching their voice. Add live chat to a web app covers history, moderation and spectators who only read; live chat sets out what the room's chat does.
Step 7: leaving and the end of the match
Call client.close() when the player leaves the match or the game screen goes away: it releases the microphone and tells the room they left. When your game server ends the match with deleteRoom, every client receives closed with the reason room-closed, so the voice screen can return to the lobby by itself. A closed client is finished; make a new StreamClient for the next match.
Test it with two players
Open the game in two browsers signed in as two players and start a match. Talk, hold the push-to-talk key, release it, and check the rings. Turn Wi-Fi off on one laptop for a few seconds: the SDK reports reconnecting on connectionStateChanged and comes back without a rejoin. If both players sit in the same physical room, put one of them on headphones, or each microphone picks up the other's speakers; Echo shows how to find the device that causes it. A player on a weak connection can check it first:
What a match costs
Each connected player is billed per second at the rate of the media they use, and an empty room costs nothing. Voice chat in a game is standard voice, so a four-player match for twenty minutes is 80 participant-minutes:
4 people × 20 minutes = 80 participant-minutes
80 participant-minutes × 39 ÷ 1,000 = 3.12 credits, ₹3.12 (≈ $0.03) at today's rate
Standard Voice: 39 credits per 1,000 participant-minutes. Billed per second, so a 7½-minute call costs 7½ minutes.
Prices are in Indian rupees; dollar figures are approximate, at ₹95 per US dollar on 24 October 2026, for orientation only. You are billed in rupees.
The free minutes of the month are spent first and reset on the 1st (UTC); used up, the rest is billed from your wallet at the same rates.
What is a participant-minute? explains the unit, and the pricing page has every rate, with a calculator on pricing in India.
Where to go next
- JavaScript SDK: every event, the error codes and reconnection.
- Voice calling API: what VoltKit does and what your game builds.
- Free minutes on VoltKit RTC: what counts, when they reset and what happens after them.
- Build a voice chat app: a stage, seats and raise hand, for a lobby with an audience.
While you develop, the JWT Decoder shows a test token's expiry on your own device and never sends it anywhere:
Inspect a test token with theJWT DecoderUse test tokens only: a token is a credential for a room, and production tokens belong only to the game that asked for them.
Frequently asked questions
Can I add voice chat to a browser game without running a media server?
Yes. VoltKit RTC runs the media servers and the relays. What you run is a small endpoint on your backend that creates a room for the match and mints a short-lived token for each player. The game itself only needs the JavaScript SDK.
Does in-game voice chat work on phones?
Yes, in the phone's browser. Chrome, Safari, Edge and Firefox all offer the microphone to a page served over HTTPS, and the SDK handles reconnection when a phone changes network. Ask for the microphone from a tap, not on page load.
How many players can talk at the same time?
Every player you give the cohost role can speak, and the service forwards each voice to everyone else. A handful of speakers at once is typical for a match. Spectators join as viewers: they hear the room and cost less, because they only receive audio.
What does voice chat in a game cost?
Each connected player is billed per second at the standard voice rate from VoltKit's live price list, and nothing while the room is empty. Every account also gets a monthly allowance of free participant-minutes, spent before anything paid, so a small game can run on it for a long time. The live number is on the free minutes page.
Why do players hear an echo?
Because one player's loudspeaker reaches their own microphone, or two players are in the same physical room. Headphones on that device stop it. The SDK uses the browser's echo canceller, so a laptop at normal volume is usually fine.