# RoomClient: voice event

> The voice event of the RoomClient interface fires when the router grants voice for this connection.

The **`voice`** event of the [`RoomClient`](/docs/client/room-client) interface fires when the router grants voice for this connection, and sets [`voice`](/docs/client/room-client/voice).

## Syntax

```ts
addEventListener("voice", (event) => {})
```

## Event type

A `CustomEvent` whose `detail` is the new `room.voice`, an object with these properties:

`url`
: A string. The voice server's URL.

`token`
: A string. This connection's token for the voice server.

## Description

The router grants voice only when the project uses voice. It grants it again on each connection, so `voice` fires again after a reconnect; until then, `room.voice` is `undefined`.

[`joinVoice()`](/docs/client/joinvoice) from `@irtio/client/voice` uses `room.voice` to join the voice server, so most games don't need this event. Listen for it to know when voice is on offer, such as to enable a microphone button.

## Examples

### Enabling a microphone button

The button stays disabled until the router grants voice. The grant can arrive before `connect()` resolves, so the code also checks `room.voice`.

```ts
// mic-button.ts
import { connect } from "@irtio/client";

const room = await connect("https://rooms.irt.io/my-game/camp");
const mic = document.querySelector<HTMLButtonElement>("#mic")!;

mic.disabled = room.voice === undefined;
room.addEventListener("voice", () => {
  mic.disabled = false;
});
room.addEventListener("reconnecting", () => {
  mic.disabled = true;
});
```

## See also

- [`RoomClient.voice`](/docs/client/room-client/voice)
- [`peers` event](/docs/client/room-client/peers-event)
- [Proximity voice](/docs/room/guides/voice#client)
