Skip to main content
Voice Chat

Voice Chat (IVoiceChat)

warning

Requires EOSCore 2.2.0 and later.

EOSCore implements the engine's IVoiceChat and IVoiceChatUser interfaces on top of EOS RTC and RTC Audio. Code and plugins written for IVoiceChat work with EOS voice rooms, for example lobby voice rooms and rooms your server creates with the RTC Admin interface.

This is a C++ interface. There are no Blueprint nodes for it. In Blueprint, use the EOSCore > RTC and RTC Audio functions, see Voice Chat (RTC/EOS Voice).

Requirements​

  • Enable RTC is on in your EOS configuration, see Project Settings.
  • The player is logged in to the EOSCore Online Subsystem with a Product User ID before the voice chat login.
  • Add VoiceChat to the dependencies in your Build.cs.
  • Not available in dedicated server builds (Server targets).

Getting the interface​

The voice chat is registered as the EOSCORE modular feature. With Register Voice Chat Modular Feature (on by default) it is also registered as the engine voice chat, so IVoiceChat::Get() returns it. FOnlineSubsystemEOSCore::GetVoiceChatInterface() returns it too.

#include "VoiceChat.h"
#include "Features/IModularFeatures.h"

IVoiceChat* VoiceChat = IVoiceChat::Get();

// Or, when another voice chat is the engine default:
IVoiceChat* EOSCoreVoiceChat = &IModularFeatures::Get().GetModularFeature<IVoiceChat>(TEXT("EOSCORE"));

Call Initialize() before you use it. It returns false when RTC is not available.

Logging in​

  • Player names are Product User IDs as strings. Every function that takes a player name expects a Product User ID.
  • Login takes the Product User ID of the local player as the player name. An empty player name uses the Product User ID of the local user that belongs to the FPlatformUserId. The credentials are not used.
  • The IVoiceChat functions use a default voice user. For more than one local player, call CreateUser() once per player and log each user in with its own Product User ID. Release it with ReleaseUser().
  • Connect and Disconnect only change the connected state. You don't need to call Connect before Login.
IVoiceChat* VoiceChat = IVoiceChat::Get();
if (VoiceChat && VoiceChat->Initialize())
{
VoiceChat->Login(FPlatformUserId(), FString(), FString(), FOnVoiceChatLoginCompleteDelegate::CreateLambda([](const FString& PlayerName, const FVoiceChatResult& Result)
{
UE_LOG(LogTemp, Log, TEXT("Voice login %s: %s"), *PlayerName, Result.IsSuccess() ? TEXT("ok") : *Result.ErrorDesc);
}));
}

Channels​

Lobby voice rooms​

Lobbies created with RTC enabled have a voice room (for example lobby sessions with bUseLobbiesVoiceChatIfAvailable, or parties with bChatEnabled).

  • When EOS connects the lobby room, the room is added as a channel named after the lobby id. OnVoiceChatChannelJoined is called with that name and the lobby members are added as players.
  • JoinChannel with a lobby id and empty credentials joins the room of that lobby (EOS_Lobby_JoinRTCRoom), for lobbies that do not join the room automatically.
  • LeaveChannel with the lobby id leaves the room (EOS_Lobby_LeaveRTCRoom).

Other rooms​

JoinChannel with credentials joins a room with EOS_RTC_JoinRoom. The channel name is the room name. The credentials are either JSON:

{ "ClientBaseUrl": "<client base url>", "ParticipantToken": "<participant token>" }

or the two values separated by |: <client base url>|<participant token>.

Get the token from your server with the RTC Admin interface (EOS_RTCAdmin_QueryJoinRoomToken). InsecureGetJoinToken and InsecureGetLoginToken return an empty string, because the client cannot create its own tokens.

The Echo channel type joins with the echo flag, so you hear your own voice. Use it to test the microphone.

VoiceChat->JoinChannel(RoomName, Credentials, EVoiceChatChannelType::NonPositional, FOnVoiceChatChannelJoinCompleteDelegate::CreateLambda([](const FString& ChannelName, const FVoiceChatResult& Result)
{
UE_LOG(LogTemp, Log, TEXT("Joined %s: %s"), *ChannelName, Result.IsSuccess() ? TEXT("ok") : *Result.ErrorDesc);
}));

Audio controls​

FunctionDescription
SetAudioInputVolume, SetAudioOutputVolumeMicrophone and speaker volume. 1.0 is normal, 2.0 the maximum
SetAudioInputDeviceMuted, SetAudioOutputDeviceMutedMutes the microphone or all incoming voice
SetPlayerMutedMutes a player in all channels
SetChannelPlayerMutedMutes a player in one channel (UE5)
SetPlayerVolumeVolume of one player. 1.0 is normal, 2.0 the maximum
BlockPlayers, UnblockPlayersBlocks players with EOS_RTC_BlockParticipant, so they can't hear you and you can't hear them
TransmitToAllChannels, TransmitToNoChannels, TransmitToSpecificChannelsChooses which channels hear your microphone. TransmitToSpecificChannels needs UE 5.3, older versions have TransmitToSpecificChannel

Mute, volume and block settings are kept for each player and applied again when the player joins another channel.

Audio devices​

GetAvailableInputDeviceInfos and GetAvailableOutputDeviceInfos list the devices from EOS_RTCAudio_QueryInputDevicesInformation and EOS_RTCAudio_QueryOutputDevicesInformation. The lists are refreshed when the devices change, and OnVoiceChatAvailableAudioDevicesChanged is called.

SetInputDeviceId and SetOutputDeviceId select a device by its id. An empty id uses the default device. Set the voice chat setting PlatformAEC to true with SetSetting before you select the input device to turn on the platform's echo cancellation.

Delegates​

DelegateCalled when
OnVoiceChatLoggedIn, OnVoiceChatLoggedOutThe voice user logs in or out
OnVoiceChatChannelJoined, OnVoiceChatChannelExitedA channel is joined or left, also lobby rooms that EOS joins or leaves
OnVoiceChatPlayerAdded, OnVoiceChatPlayerRemovedA player joins or leaves a channel
OnVoiceChatPlayerTalkingUpdatedA player starts or stops talking, the local player too
OnVoiceChatPlayerMuteUpdatedA player is muted or unmuted
OnVoiceChatPlayerVolumeUpdatedThe volume of a player changes
OnVoiceChatCallStatsUpdatedA channel is left. Only the call length is set

The audio delegates (RegisterOnVoiceChatAfterCaptureAudioReadDelegate, RegisterOnVoiceChatBeforeCaptureAudioSentDelegate, the render delegates) and StartRecording receive the PCM buffers of the room.

Not supported​

  • Positional audio: EOS RTC has no positional audio. Set3DPosition does nothing, and positional channels are joined as non-positional channels.
  • Call stats: only the call length is reported. Latency and packet stats are not available.
  • Login and join tokens from the client: InsecureGetLoginToken and InsecureGetJoinToken return an empty string.