How can I make in game voice communication?

I have not been able to find any examples online so I’m trying to use information in the documentation to help develop a means of in game voice chat.

I’m trying to check for voice input from a microphone.

OnlineVoiceImpl and VoiceEngineImp look good places to start but including either of the headers for these classes breaks my build.

Any help will be greatly appreciated.

VoiceInterface.h generates errors on the following line
DEFINE_ONLINE_DELEGATE_TWO_PARAM(OnPlayerTalkingStateChanged, TSharedRef, bool);

syntax error : identifier ‘OnPlayerTalkingStateChanged’
missing type specifier int assumed

Voice support is fully supported on any Steam platform. Additionally I have implemented voice support using the Opus Codec. The codec itself is implemented and integrated for Mac/Linux/Windows, but I have only implemented voice capture support for Windows via DirectSound. The Mac/Linux mic capture would need to be implemented.

  • Voice capture is implemented in the IVoiceCapture interface.
    • this handles all voice capture for a platform
  • Voice codec is implemented via the IVoiceEncoder/IVoiceDecoder interfaces.
    • these are separated out because we need a decoder per player in opus, since it is stateful
  • VoIP is handled via IVoiceEngine and IVoiceInterface
    • the engine handles putting the capture/codec together to provide a packet of data to transmit
    • the interface handles hooking up the game to the engine so that we can provide muting and transmission

Right now OnlineSubsystemSteam and OnlineSubsystemNull both provide voice chat support using their respective interfaces.

  • OnlineSubsystem::Tick
    • Retrieve any local voice data ProcessLocalVoicePackets and add it to an array to be sent out (FVoiceDataImpl for example)
  • NetDriver::ProcessLocalClientPackets sends packets to the server
  • NetDriver::ProcessLocalServerPackets sends packets to other clients
  • Clients receive packets in UVoiceChannel::ReceivedBunch
    • Packets are opened and given to the IOnlineVoice for processing
      • IOnlineVoice decompresses the audio and plays it via IVoiceEngine in ProcessRemoteVoicePackets

It should be working in Shootergame, although there may be a few ini settings that need to be verified. Most things should be handled for you, if you use the OnlineSubsystem IOnlineSession. Creating sessions and registering players will set them up to be able to use voice.

DefaultEngine.ini

[Voice] 
bEnabled=true

[OnlineSubsystem] 
bHasVoiceEnabled=true

In DefaultGame.ini

[/Script/Engine.GameSession]
bRequiresPushToTalk=false

If you want push to talk, you’ll need to implement a key input binding and then call Start/StopNetworkedVoice. Look at ToggleSpeaking, an exec function on PlayerController. I’m not well versed on the Input mapping code, but the entries here call exec functions or bind to keys.

Base/DefaultInput.ini

[/Script/Engine.PlayerInput]
+DebugExecBindings=(Key=T,Command="ToggleSpeaking true | OnRelease ToggleSpeaking false")

[/Script/Engine.InputSettings]
+ActionMappings=(ActionName="PushToTalk", Key=T)
1 Like

Should I be able to hear myself if I talk into a microphone with two players registered to one session? I made the changes to the ini settings that you mentioned and hold down the ‘T’ key in a session with two players but still get no feedback.

I’m not sure Shootergame has push to talk implemented, so you would want to set the bRequiresPushToTalk=false to leave the voice on all the time.

There is a cheat command call DumpVoiceMutingState that will print out a bunch of information when the two players are connected. If you could run that and paste it here it would be helpful.

Any estimate on when this will be implemented? 4.3? By August?

See the answer above. Voice chat is already implemented in Steam and via Opus for Windows.

Hey, can I catch the reception of the voice packets? Because I want to apply a filter on them AND play them in a certain position in world.

There is no support for this out of the box right now. The voice packets are handled internally and either routed to the platform APIs (LIVE/Steam) or to our AudioComponent system (NULL) for playback.

You could modify code in the following place to intercept the voice packets.

UVoiceChannel::ReceivedBunch(FInBunch& Bunch)

This serializes the network voice packet and adds it to the VoiceData.RemotePackets variable on most platforms. If you take the packet yourself you’d have to put it back on that array or make sure to play the data somehow.

Does this mean that a client on mac should be able to play voice chat from remote client but not to capture and send voice?

So sorry for the delay here, it totally slipped the cracks.

Yes, as it currently stands Opus is compiled for Mac and the code should be cross platform. If you received an Opus voice packet it should be decompressed and routed to our AudioComponent which would play on Mac.

That being said, I haven’t tested and in fact think that the factory method for the voice codec interface is probably not enabled on Mac. Could/should be doable.

Implementing Mic capture on Mac hasn’t been prioritized.

dont know what wrong happening on my side.
not OnlineSubsystemSteam .
i am trying it through lan.
do i supposed to do anything for OnlineSubsystemNull ?

Not sure exactly what the problem you are having is. Are you trying to get Steam and instead getting NULL? Do you want NULL and its not working?

Both Steam and NULL interfaces have voice support, but they do require you use the Session APIs to create/join a multiplayer session so UniqueIds for each player are involved. That will allow you to mute players and do other game logic.

There is a thread on the forums where I try to answer this in great detail here.

Hey, just want to make it clear to others something that I’ve only really determined now. The voice module itself is essentially implicit. The only things to implement the basic model is to just make the required changes to the .ini files, and then set up a multiplayer session. There’s no need to delve into the source code yourself.

Setting up a voice audio class in the project settings is also important. not assigned by default.

this will allow you to control the volume of voice independently.

Hi, I used “OnlineSubsystemNull” to creat/join sessions and followed the setting with Josh. Client could send and receive voice when I tested in editor ,but Server was no voice. When I packaged to two computers and tested each other, there weren’t voice, What 's going wrong? any one can help me,please?

hey guys, that’s my fault, two computer all need microphones.

How can I assign non-PushToTalk voice its own sound class without C++?

How can I switch between PushToTalk and Non-PushToTalk in Blueprints?
Basically re-write the .ini file every time I change a bool?

I know this is an old topic but i recently released my VoiceChat plugin on the marketplace. Source code is included. So in case you want a working solution check out Ultimate Voice Chat (VoiceChat for Blueprints) in Code Plugins - UE Marketplace