콘텐츠로 이동

Voice chat

이 콘텐츠는 아직 번역되지 않았습니다.

GDMP has voice chat built in. You turn it on for your experience; players set up their microphone once in the launcher (Settings → Voice chat) or in the game (ESC → Voice). Your scripts can put players in channels, mute them, and react when someone speaks.

Add voice to the manifest’s capabilities. Optionally, say how it sounds:

{
"capabilities": ["players", "net", "voice"],
"voice": { "mode": "proximity", "range": 900 }
}
voice field
mode "global" (default) everyone in the same channel hears everyone, at full volume
"proximity" closer is louder, with left / right from where the speaker stands; silent past range
range 30 .. 30000, default 900 in level units (30 units = one block); proximity only

Without the capability nothing is sent: the relay drops voice for experiences that do not declare it.

  • Voice activity (the microphone opens when they speak, with a sensitivity they set) or push to talk (V by default, any key or a side mouse button), or the microphone off.
  • In ESC → Players: a ring around whoever is speaking, a mute button and a volume slider for every player (only for them). Block also mutes.
  • In ESC → Voice: their microphone and its level, mute, deafen, volumes, voice sounds, the channel they are in.
  • Short voice sounds when someone joins or leaves their channel, and when they mute.

Voice is Opus at 24 kbps in 20 ms frames, over UDP (TCP when UDP is blocked), with error correction for lost packets.

Channels and mutes are the server’s: a client cannot change them.

setChannel(playerId, name) puts the player in a channel; "" = the default channel (everyone). A name is 1..23 of A-Z a-z 0-9 _ - and spaces
getChannel(playerId) → string
setMuted(playerId, muted) the server’s mute: nobody hears that player until you unmute them
isMuted(playerId) → boolean the server’s mute only
isSpeaking(playerId) → boolean a voice frame from them in the last 300 ms
// teams hear only their own team; the dead are muted until the next round
gdmp.players.onJoin(p => gdmp.voice.setChannel(p.id, teamOf(p.id)));
gdmp.players.onDeath(p => gdmp.voice.setMuted(p.id, true));
function newRound() { for (const p of gdmp.players.list()) gdmp.voice.setMuted(p.id, false); }
isEnabled() → boolean voice chat runs on this PC (the experience has it and the engine started)
isSpeaking(playerId) → boolean that player is speaking (this player too, while their microphone is open)
onSpeaking(callback) callback(playerId, speaking) when someone starts or stops speaking
setVolume(playerId, volume) your game’s own volume for that player, 0 .. 2 (multiplied with the player’s choice)
getVolume(playerId) → number
channel() → string the channel this player is in ("" = the default one)
playSound(name) one of the voice sounds: "join", "leave", "mute", "unmute" (if the player has voice sounds on)
// a speaking bubble over the player's name tag
gdmp.voice.onSpeaking((id, speaking) => setBubble(id, speaking));

A player can always mute anyone for themselves, whatever your script sets.

The declarations from the GDMP types (namespace GDMP):

interface VoiceServer {
/** `""` = the default channel. */
setChannel(playerId: PlayerId, name: string): void;
getChannel(playerId: PlayerId): string;
setMuted(playerId: PlayerId, muted: boolean): void;
isMuted(playerId: PlayerId): boolean;
isSpeaking(playerId: PlayerId): boolean;
}
interface VoiceClient {
isEnabled(): boolean;
isSpeaking(playerId: PlayerId): boolean;
onSpeaking(cb: Callback<[playerId: PlayerId, speaking: boolean]>): void;
/** 0..2. */
setVolume(playerId: PlayerId, volume: number): void;
getVolume(playerId: PlayerId): number;
channel(): string;
playSound(sound: 'join' | 'leave' | 'mute' | 'unmute'): void;
}