Proximity voice chat with Opus and a microphone picker for Unreal Engine.
Proximity voice chat with Opus and a microphone picker for Unreal Engine.
NsVoice is proximity voice chat for multiplayer games. A component on the player pawn reads the microphone, encodes the voice with Opus, and sends it through the host. The other machines play the voice from that component, so your attenuation settings make it quieter with distance.
NsVoice has no input bindings, no UI, and no save of the options. The game binds push to talk, draws the meter, and saves the picked microphone and the volumes.
Set Transmitting.On Speaking Changed fires on every machine when a player starts or stops speaking.GetPlaybackVolume, for example for a radio.AudioCapture. NsVoice enables it.bEnabled=true in the [Voice] section of DefaultEngine.ini. Without it, the Opus encoder and decoder do not start.NsVoice folder into the Plugins folder of your project."NsVoice" to the dependencies of the game module that uses the components.Config/DefaultEngine.ini:
[Voice]
bEnabled=true
In Blueprint:
Ns Voice Chat component, and attach it to the head.Ns Voice Activity component, if the game must know who speaks.Transmit When Locally Controlled is on, so the microphone opens for the local player. For push to talk, turn it off and call Set Transmitting.
In C++:
#include "NsVoiceChatComponent.h"
#include "NsVoiceActivityComponent.h"
AMyHero::AMyHero()
{
VoiceChat = CreateDefaultSubobject<UNsVoiceChatComponent>(TEXT("VoiceChat"));
VoiceChat->SetupAttachment(GetMesh(), TEXT("head"));
VoiceChat->bTransmitWhenLocallyControlled = false; // push to talk
VoiceActivity = CreateDefaultSubobject<UNsVoiceActivityComponent>(TEXT("VoiceActivity"));
}
void AMyHero::StartTalk() { VoiceChat->SetTransmitting(true); }
void AMyHero::StopTalk() { VoiceChat->SetTransmitting(false); }
UNsVoiceChatComponent – An audio component. It sends the voice of the owner and plays the voice on the other machines.UNsVoiceActivityComponent – Replicates when a player speaks.UNsMicSubsystem – Game instance subsystem. It owns the microphone stream, the device, the gain, and the level.UNsVoiceSubsystem – Game instance subsystem. It holds the voice volume and the volume of each player.SetTransmitting / IsTransmitting – Open or close the microphone of the owner.GetTalkLevel – The smooth talk level of a player, on every machine.UNsMicSubsystem::GetDevices / SetDeviceId – List the microphones and pick one (C++).UNsMicSubsystem::SetGain / GetLevel – Set the gain, and read the level for a meter.SetVoiceVolume / SetPlayerVolume – Set the volume of all voices, or of one player.GetPlaybackVolume – Override it in a child component for a game rule.