Skip to main content

Integrate voice chat into your game

Last updated on April 9, 2024

Overview

This article walks you through how to integrate the AccelByte Gaming Services (AGS) Voice Chat feature into your game client as push-to-talk voice chat.

note

The AGS Voice Chat feature is currently only supported in Unreal Engine. Support for Unity SDK is coming soon.

Prerequisites

  • You are using Unreal Engine 4.27.2 or above
  • You have knowledge of using OnlineSubsystem (OSS)
  • You have installed the AGS SDK and OSS plugins into your project

Configuration

To support voice chat, configure the following settings in your game client:

DefaultEngine.ini
[OnlineSubsystem]
bHasVoiceEnabled=true

[Voice]
bEnabled=true

[/Script/Engine.GameSession]
bRequiresPushToTalk=false

Register local and remote talkers

You can include local and remote talker registration in the Session class by calling RegisterPlayers method. This will simplify the process of adding players to voice chat, providing a seamless experience when they are joining a game session or party (as parties are a type of session).

FName SessionName;
TArray<TSharedRef<const FUniqueNetId>> Players;
bool bWasInvited;

SessionInterface->RegisterPlayers(SessionName, Players, bWasInvited);

Assign a button for Push-to-Talk

To enable push-to-talk, assign a button that players can use to turn on or off their microphone to talk with other players. This setup will vary from game to game. The following sample code shows how to set up the forward slash (/) key to control the voice chat.

DefaultEngine.ini
[/Script/Engine.InputSettings]
...
+ActionMappings=(ActionName="ToggleSpeak",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Slash)
void AGamePlayerController::BeginPlay()
{
...
#if !UE_SERVER
InputComponent->BindAction("ToggleSpeak", EInputEvent::IE_Pressed, this, &APlayerController::StartTalking);
InputComponent->BindAction("ToggleSpeak", EInputEvent::IE_Released, this, &APlayerController::StopTalking);
#endif
}

Known issues

  1. There are some differences between a Windows server (Local DS) and a Linux server (Armada) that can lead to different behavior, such as a Linux server being unable to read push-to-talk settings. A Linux server can only use settings that are enabled by default. This means that the server will always send a command to disable network voice, requiring the game to implement a process to enable network voice so players can talk freely without pressing a key.

  2. The Voice Chat feature has been tested and works for game sessions that run on dedicated servers, but it is currently untested in peer-to-peer (P2P) network.

Troubleshooting

In this section, you can find common errors and issues that may occur when using the service, along with recommendations on how to resolve them.

Missing Push-to-Talk Audio when testing two clients locally

When running two clients locally using push-to-talk, you may experience an issue hearing the voice chat in one client. This is because Unreal, by default, mutes the audio of an instance when it's window loses focus. To resolve this when testing on the same machine, you can update the unfocused audio modifier in the DefaultEngine.ini to 1.0 instead of 0.0.

DefaultEngine.ini
[Audio]
UnfocusedVolumeMultiplier=1.0