NsVoice gives proximity voice chat to a multiplayer game. 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, with its attenuation. The player can pick the microphone, the gain, and the volumes.
NsVoice does not bind input, draw UI, or save options. The game binds push to talk, draws the meter, and saves the picked microphone, the gain, and the volumes. NsVoice does not use the voice chat of the online subsystem.
| Setting | Value | Effect |
|---|---|---|
| Gain (NsMicSubsystem) | 1.5 | Multiplies the microphone level, from 0 to 4 |
| Talk Rise Speed | 18 | How fast the talk level goes up |
| Talk Fall Speed | 6 | How fast the talk level goes down |
| Remote Level Gain | 10 | Multiplier of the heard voice level in the talk level of a listener |
| Frames Per Packet | 2 | Opus frames of 20 ms in one packet |
| Level Hold Seconds | 0.15 | Time after the last packet until the heard level is 0 |
| Speech Level | 0.12 | Microphone level that counts as speech |
| Speech Hold Seconds | 0.4 | Speech stays on for this time after the level drops |
| Heard level (example) | 0.1 | Packet peak as a part of the sent level. The widget sets this value. It is not a plugin setting |
NsVoice folder into the Plugins folder of your project."NsVoice" to the dependencies of the game module that uses the components.Config/DefaultEngine.ini.bEnabled=true to the [Voice] section.AudioCapture turns on with it.The [Voice] line is required. Without it, the engine does not create the Opus encoder and decoder.
These lines are a common setup for this kind of voice chat. They are not required by the code:
[OnlineSubsystem]
bHasVoiceEnabled=false
[/Script/Engine.Player]
ConfiguredInternetSpeed=300000
ConfiguredLanSpeed=300000
The first line keeps the engine voice chat off. The other two lines give the connection more bandwidth for the voice packets.
The plugin has no project settings page.
In Blueprint:
Ns Voice Chat.In C++:
#include "NsVoiceChatComponent.h"
AMyHero::AMyHero()
{
VoiceChat = CreateDefaultSubobject<UNsVoiceChatComponent>(TEXT("VoiceChat"));
VoiceChat->SetupAttachment(GetMesh(), TEXT("head"));
}
Transmit When Locally Controlled is on by default. The microphone opens one time, when this machine controls the pawn.
Ns Voice Chat component.Set Transmitting with New Transmitting on.Set Transmitting with New Transmitting off.Is Transmitting returns true while the microphone is open.
UNsMicSubsystem::GetDevices() to get the list. Each FNsMicDevice has an Id and a Name.Name values to the player.UNsMicSubsystem::Get(this)->SetDeviceId(Device.Id) with the picked device.SetDeviceId again.An empty ID picks the default microphone. An open stream opens again on the new device at once. GetDeviceName returns the name of a saved ID.
Get Game Instance Subsystem node and the class NsMicSubsystem.Set Gain with a value from 0 to 4.The gain applies to the meter, the talk level, and the voice that the other players hear.
NsMicSubsystem.Get Level each frame. The value goes from 0 to 1, after the gain.Get Level returns 0 while the microphone is closed. In C++, call OpenListener to keep the microphone open for a meter, and CloseListener when the meter closes.
Get Game Instance Subsystem node and the class NsVoiceSubsystem.Set Voice Volume with a value from 0 to 2. It applies to every voice.Set Player Volume with the player name and a value from 0 to 2. It applies to one player.The player name is the name in the player state of the speaker. A player volume lasts for the session.
Ns Voice Activity component to the same pawn as the Ns Voice Chat component.On Speaking Changed of the activity component.Is Speaking at any time.The event fires on every machine. The voice chat component gives the microphone level to the activity component while the microphone is open.
Get Talk Level on the Ns Voice Chat component each frame.On the speaker, the value comes from the microphone. On the other machines, it comes from the voice that the machine hears. Get Voice Level gives the raw level of the heard voice.
UNsVoiceChatComponent.GetPlaybackVolume_Implementation.Super::GetPlaybackVolume_Implementation() to keep the voice volume and the player volume.Ns Voice Chat component (UNsVoiceChatComponent), category Voice:
| Setting | Default | Effect |
|---|---|---|
| Transmit When Locally Controlled | On | Opens the microphone when this machine controls the pawn. Turn it off for push to talk |
| Frames Per Packet | 2 | Opus frames of 20 ms in one packet, from 1 to 5. Edit it in the Blueprint defaults only |
| Max Packet Bytes | 2000 | The host drops a larger packet. Edit it in the Blueprint defaults only |
| Max Queued Seconds | 0.4 | When more voice waits to play, the old voice drops. Edit it in the Blueprint defaults only |
| Level Hold Seconds | 0.15 | Time after the last packet until Get Voice Level is 0. Edit it in the Blueprint defaults only |
Ns Voice Chat component, category Voice > Talk Level:
| Setting | Default | Effect |
|---|---|---|
| Remote Level Gain | 10 | Multiplier of the heard voice level in the talk level |
| Talk Rise Speed | 18 | How fast the talk level goes up |
| Talk Fall Speed | 6 | How fast the talk level goes down |
Ns Voice Activity component (UNsVoiceActivityComponent), category Voice:
| Setting | Default | Effect |
|---|---|---|
| Speech Level | 0.12 | Microphone level that counts as speech, from 0.01 to 1 |
| Speech Hold Seconds | 0.4 | Speech stays on for this time after the level drops, so short pauses do not stop it |
Subsystems, set at runtime:
| Setting | Default | Effect |
|---|---|---|
Gain (NsMicSubsystem) |
1.5 | Microphone gain, from 0 to 4 |
Voice Volume (NsVoiceSubsystem) |
1 | Volume of every voice, from 0 to 2 |
Player Volume (NsVoiceSubsystem) |
1 | Volume of one player, from 0 to 2 |
LogNsVoice. Set it to Verbose with Log LogNsVoice Verbose to see each received packet, with its size and peak.Log level, LogNsVoice shows the sample rate when the microphone opens, and warnings when a microphone does not open.| Problem | Cause | Fix |
|---|---|---|
| Ensure: “The voice encoder did not start” or “The voice decoder did not start” | The [Voice] section of DefaultEngine.ini does not have bEnabled=true |
Add bEnabled=true to the [Voice] section, then restart the editor |
| Log: “No microphone opened. Voice chat stays off.” | No microphone is connected, or the device does not open | Connect a microphone, then call Set Transmitting again. The automatic start runs one time only |
| Log: “The picked microphone … is not connected” | The saved device ID is not in the device list | The game uses the default microphone. Pick a device again |
| No one hears the voice | The owner of the component is not a pawn, or the pawn is not locally controlled | Put the component on the pawn that the player controls |
| The voice is equally loud at every distance | The component has no attenuation | Set an attenuation on the component |
Is Speaking stays false |
The pawn has no Ns Voice Chat component, or its microphone is closed |
Add both components to the same pawn, and open the microphone |
Is Speaking stays true or does not start |
Speech Level does not match the microphone | Change Speech Level, or change the gain |
GetDevices, SetDeviceId, OpenListener, and CloseListener are C++ only.