This article details an example of implementing push-to-talk (PTT) in an Unreal application.
To begin the implementation process, bind some custom methods in your PlayerController to an Action defined in the input config:
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 slightly depending on your implementation, however, you call one Vivox Core Unreal method.
The simplest implementation is if your player is only going to be in one voice channel at a time. In this scenario, call VivoxVoiceClient->AudioInputDevices().SetMuted(false);
(or true), where VivoxVoiceClient is your IClient. This is how you globally mute or unmute audio input from the player (ensure that you also mute the player at the start). To get audio when you unmute the player, join your channels with connectAudio set to true and with TransmitPolicy::Yes.
A more complex PTT example is when you are using multiple push-to-talk 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 PTTKey, and when that key is pressed or released, you need to call IChannelSession::SetIsTransmittingSession(bool)
on the corresponding ChannelSession to set it as either transmitting or not transmitting. In this scenario, ensure that you join your channels with connectAudio set to true and TransmitPolicy::No. However, you do not need to mute the player, because setting or unsetting transmission handles letting audio through.
Note: Vivox Core Unreal allows players to transmit in only one channel at a time, even though they are capable of listening to audio from all channels that they are connected to.
Comments
0 comments
Article is closed for comments.