Skip to main content

Voice Support

1. Overview

PGOS Overlay provide a real time voice chat in the party or the match.

Note: Voice is re-implemented in PGOS Overlay 0.5 as an optional plugin.

2. Integerating

Copy the plugin folders PgosWeaverVoiceGme and GMESDK into the Plugins directory of your game project (or the Plugins directory of the Unreal Engine you used).

PgosWeaverVoiceGme module will be automatically startup in your project.

2.1 Voice Mode

There are two voice modes available:

  • Free to Talk
  • Push to Talk.

You can control the voice mode with the methods in VoiceController.

// switch to Push2Talk mode (or false to Free2Talk mode)
UPgosBlueprintFunctionLibrary::GetOverlayVoiceController()->SetPushMode(true);

Free to Talk is used by default, the voice chat will automatically triggered when the player is talking.

If Push to Talk mode is used, you have responsibility to call SetPushState when the player pressed/released the key for triggering voice chat.

Note: SetPushState will be handled internally in Overlay in the future version after the keymap feature finished.

// call once the key is pressed (no need to call it continuously when pressing)
UPgosBlueprintFunctionLibrary::GetOverlayVoiceController()->SetPushState(true);

// call once the key is released
UPgosBlueprintFunctionLibrary::GetOverlayVoiceController()->SetPushState(false);

2.2 VoiceView Widget

VoiceView is a ready-to-use pre-made voice status overlay interface provided in PGOS Overlay. This interface does not include any interactions and displays players who are currently in an active voice state using a concise style. The only thing you need to do is create a VoiceView and add it to the panel widget you want as it's parent.

ingame_voice_view

// Create Login Widget and Setup
UUserWidget* VoiceWidget = UPgosBlueprintFunctionLibrary::CreateOverlayWidget(ParentPanel, EPgosOverlayWidgetType::VoiceView);
UPanelSlot* PanelSlot = ParentPanel->AddChild(VoiceWidget);

// PanelSlot: setup layout here
// ...

// the VoiceView widget does not contain any public methods for now.

2.3 Replaceable Speech-to-Text Functionality

The Speech-to-Text feature is enabled by default if PgosWeaverVoiceGme is integrated. However, it can also be replaced with custom implementation even without PgosWeaverVoiceGme.

2.3.1 Implement a Custom VoiceTextProcessor

#include "Addons/WeaverVoiceTextProcessor.h"

struct FMyCustomVoiceTextProcessor : public IWeaverVoiceTextProcessor
{
public:
virtual ~FMyCustomVoiceTextProcessor() {}

/**
* Broadcast update events in the implementation.
*
* - Raise `InProgress` event periodically after `StartVoiceText` is called:
* OnVoiceTextUpdated().Broadcast(EPgosVoiceTextState::InProgress, VoiceTextResult);
* - Raise `Done` event after the internal timeout reached or `FinishVoiceText` is called.
* OnVoiceTextUpdated().Broadcast(EPgosVoiceTextState::Done, VoiceTextResult);
* - Raise `Failed` event if something wrong occurs during the process.
* OnVoiceTextUpdated().Broadcast(EPgosVoiceTextState::Failed, LOCTEXT("YOUR_ERROR_MESSAGE"));
*/
virtual FDelegateOnVoiceTextUpdated& OnVoiceTextUpdated() override { return DelegateOnVoiceTextUpdated; }

/**
* Start a new session of speech-to-text process.
* OnVoiceTextUpdated() should be invoked after the internal process finished, and also be invoked in-progress for the better user experience.
*
* NOTE: If CancelVoiceText/FinishVoiceText is not called (this behavior is not expected), the processor should automatically discard the last session and start a new one.
* @param Language indicate the current language/dialect trying to process
* @return return true if starts successfully
*/
virtual bool StartVoiceText(const FString& Language = TEXT("cmn-Hans-CN")) override;

/**
* Discard the current session.
*
* NOTE: It's fine not to raise any OnVoiceTextUpdated event in this situation.
*/
virtual void CancelVoiceText() override;

/**
* Finish the current session immediately.
*
* NOTE: `Done`/`Failed` should be raised after finished.
*/
virtual void FinishVoiceText() override;

private:
FDelegateOnVoiceTextUpdated DelegateOnVoiceTextUpdated;
};

2.3.2 Register the Custom VoiceTextProcessor

Overlay will try to get an instance of VoiceTextProcessor via IPgosWeaverModule::OnInstantiateVoiceTextProcessor when players open the Speech-to-Text widget if there is a valid delegate registered.

Note: Returning a newly created VoiceTextProcessor instance is straightforward, but not always necessary.

IPgosWeaverModule::Get().OnInstantiateVoiceTextProcessor().BindLambda([] { return MakeShareable(new FMyCustomVoiceTextProcessor); });