Scenario
This article details an example of implementing push-to-talk in an Unreal application. Push-to-talk (PTT) is a term used to describe the general technique of letting the local player decide and control when others can hear them in voice chat by pushing a button. Depending on your platform, this might be implemented with a key/controller binding, or a touch screen UI element. The method used to silence the user might also change depending on your particular game integration.
This article supplements the Push-to-talk topic in the Vivox Unreal Developer Guide, part of the Vivox Unreal SDK documentation.
Resolution
Push-to-talk versus Push-to-toggle
In a traditional push-to-talk implementation, the player is silenced at the start, and is only unsilenced while pushing a key/button/UI, in other words, while the button is held down. In these PPT implementations, ensure that you silence the player by default from the start, unsilence them in response to the key press event, then silence them again once the key is released.
A variant of this technique known as push-to-toggle can be utilized in cases where holding down a key while speaking is undesirable (such as on mobile platforms with primarily touch screen input). In this scenario, the player may be either silenced or unsilenced at the start, and each push of the button will "toggle" or switch this state between silenced and unsilenced. In the case of multiple channels, you might even add more states to this rotational cycle, such as (1) speaking in channel A only, (2) channel B only, (3) both channels, (4) then no channels.
Implementation
To begin the implementation process, bind some custom methods in your PlayerController to an Action defined in the input config. For this example, we bind to the keyboard key V
.
DefaultInput.ini
+ActionMappings=(ActionName="PushToTalk",Key=V,bShift=False,bCtrl=False,bAlt=False,bCmd=False)
MyPlayerController.h
/** Enable voice chat transmission */
void PushToTalkPressed();
/** Disable voice chat transmission */
void PushToTalkReleased();
MyPlayerController.cpp
void AMyPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("PushToTalk", IE_Pressed, this, &AMyPlayerController::PushToTalkPressed);
InputComponent->BindAction("PushToTalk", IE_Released, this, &AMyPlayerController::PushToTalkReleased);
}
The contents of PushToTalkPressed
and PushToTalkReleased
can vary depending on your implementation, however, you will generally end up calling one Vivox Unreal SDK method for each.
Note: For push-to-toggle, you might only need one or the other, not both.
Using SetMuted()
The simplest implementation is if your player is only going to be in one voice channel at a time, or if you're okay being muted everywhere all at once. In this scenario, call VivoxVoiceClient->AudioInputDevices().SetMuted(false);
(or true
), where VivoxVoiceClient
is your IClient
. This is how you globally unmute or mute audio input from the player. To ensure audio is in fact transmitted when you unmute the player, always join your channels with connectAudio
set to true
and with TransmitPolicy::Yes
.
Using SetIsTransmittingSession()
A more complex PTT example is when you are using multiple PTT keys for multiple voice channels at a time, such as simultaneous match-wide Positional area chat and Non-Positional team chat. In this scenario, you bind each PTT key with a separate Action, and have multiple pairs of Pressed and Released callbacks. You need to keep track of which channel is associated with each PTT Key, and when that key is pressed or released, you need to call IChannelSession::SetIsTransmittingSession(bool)
on the corresponding IChannelSession
to set it as either transmitting or not transmitting. If both or neither are held or toggled, you can instead set the transmission policy to All
or None
in the ILoginSession
. In this scenario, ensure that you join your channels with connectAudio
set to true
and TransmitPolicy::No
if you want your player silenced by default (or set to Yes
—or to All
in advance—in a push-to-toggle case where you want them heard by default in one or both channels).
Note: When using transmission for push-to-talk in this manner, you do not need to mute the player in advance or at any time using SetMuted()
because setting or unsetting transmission is sufficient to control letting audio through.
Note: The Vivox Unreal SDK allows players to transmit in only one specific channel at a time, even though they are capable of listening to audio from all channels that they are connected to. You can also transmit into All channels or None, but not 2 or more specific channels when joined to 3 or more.
Comments
0 comments
Article is closed for comments.