Voice Chat (IVoiceChat)
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
VoiceChatto the dependencies in yourBuild.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.
Logintakes 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 theFPlatformUserId. The credentials are not used.- The
IVoiceChatfunctions use a default voice user. For more than one local player, callCreateUser()once per player and log each user in with its own Product User ID. Release it withReleaseUser(). ConnectandDisconnectonly change the connected state. You don't need to callConnectbeforeLogin.
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.
JoinChannelwith a lobby id and empty credentials joins the room of that lobby (EOS_Lobby_JoinRTCRoom), for lobbies that do not join the room automatically.LeaveChannelwith 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
| Function | Description |
|---|---|
SetAudioInputVolume, SetAudioOutputVolume | Microphone and speaker volume. 1.0 is normal, 2.0 the maximum |
SetAudioInputDeviceMuted, SetAudioOutputDeviceMuted | Mutes the microphone or all incoming voice |
SetPlayerMuted | Mutes a player in all channels |
SetChannelPlayerMuted | Mutes a player in one channel (UE5) |
SetPlayerVolume | Volume of one player. 1.0 is normal, 2.0 the maximum |
BlockPlayers, UnblockPlayers | Blocks players with EOS_RTC_BlockParticipant, so they can't hear you and you can't hear them |
TransmitToAllChannels, TransmitToNoChannels, TransmitToSpecificChannels | Chooses 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
| Delegate | Called when |
|---|---|
| OnVoiceChatLoggedIn, OnVoiceChatLoggedOut | The voice user logs in or out |
| OnVoiceChatChannelJoined, OnVoiceChatChannelExited | A channel is joined or left, also lobby rooms that EOS joins or leaves |
| OnVoiceChatPlayerAdded, OnVoiceChatPlayerRemoved | A player joins or leaves a channel |
| OnVoiceChatPlayerTalkingUpdated | A player starts or stops talking, the local player too |
| OnVoiceChatPlayerMuteUpdated | A player is muted or unmuted |
| OnVoiceChatPlayerVolumeUpdated | The volume of a player changes |
| OnVoiceChatCallStatsUpdated | A 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.
Set3DPositiondoes 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:
InsecureGetLoginTokenandInsecureGetJoinTokenreturn an empty string.