Voice-only quickstart
Updated
Build a voice-only app using the Agora RTC SDK.
This Unreal Blueprint quickstart shows you how to create a basic Voice Calling app using the Agora RTC SDK.
Understand the tech
To start a Voice Calling session, implement the following steps in your app:
-
Initialize the Agora Engine: Before calling other APIs, create and initialize an Agora Engine instance.
-
Join a channel: Call methods to create and join a channel.
-
Send and receive audio: All users can publish streams to the channel and subscribe to audio streams published by other users in the channel.
Prerequisites
-
Unreal Engine 4.27 or higher
-
Prepare your development environment according to your target platform and engine version:
Dev environment requirements Other requirements Android - iOS A valid Apple developer signature. macOS A valid Apple developer signature. Windows 32-bit Windows only supports Unreal Engine 4 and below. To use Unreal Engine with 32-bit Windows, uncomment the code relating to Win32in theAgoraPluginLibrary.Build.csfile. -
Two physical devices for testing
-
A microphone
-
A valid Agora account and project. Please refer to Agora account management for details.
Set up your project
This section shows you how to set up your Unreal (Blueprint) project and install the Agora RTC SDK.
Refer to the following steps or the Unreal official guide to create a new project. If you already have an Unreal project, skip to the next section.
-
Open Unreal Engine. Select Games under New Project Categories, and click Next.
-
Configure your project as follows:
- Template: Select Blank.
- Project Defaults:
- Language: Select Blueprint.
- Target Platform: Pick Desktop.
- Project Location: Enter a project files storage path.
- Project Name: Type a suitable name for your project.
Click Create.
-
In the Unreal Project Browser, click on Browse and locate the
.uprojectfile. -
Select the project and click Open.
Install the SDK
Take the following steps to add the Unreal (Blueprint) RTC SDK to your project:
- Download the latest version of Agora Unreal RTC SDK from Download SDKs and unzip it.
- In your project root folder, create a
Pluginsfolder. - Copy
AgoraPluginfrom the Unreal SDK folder toPlugins.
Implement Voice Calling
This section guides you through the implementation of basic real-time audio interaction in your game.
Create a level
-
In the Content folder of the Content Browser, right-click and select Level to create a Level Blueprint and name it BasicAudioCallScene.
-
Double-click BasicAudioCallScene and click Blueprints > Open Level Blueprint above the editor to open the level blueprint.
Implement basic processes
In the My Blueprint panel, double-click Graphs > EventGraph to open the event graph. You see two event nodes: Event BeginPlay (game starts) and Event End Play (game ends). Create event nodes with the corresponding functions and variables, and connect them as shown in the following figure to implement the Voice Calling logic:
The following table lists the main nodes:
| # | Node | Type | Description |
|---|---|---|---|
| 1 | Set Show Mouse Cursor | Native* | (Optional) Set whether to display the mouse cursor. Check to display it. Information: This node is available on Windows and macOS only. If the node is not retrieved at creation time, uncheck Context Sensitive. |
| 2 | Load Agora Config | Custom** | Loads Agora configuration. Used to verify user identity when creating and joining channels. |
| 3 | Create BP Audio Widget | Native | Create user interface:
|
| 4 | Set Basic Audio Call Widget | Custom | Set up the user interface:
|
| 5 | BindUIEvent | Custom | Use Bind UI events to handle event logic after clicking the Join Channel and Leave Channel buttons. |
| 6 | Add to Viewport | Native | Add user interface to the viewport. |
| 7 | Check Permission | Custom | (Optional) Check whether you have obtained the system permissions required for real-time audio and video interaction, such as access to the camera and microphone. Note: If your target platform is Android, create this node to check system permissions. |
| 8 | Init Rtc Engine | Custom | Create and initialize the RTC engine. |
| 9 | Un Init Rtc Engine | Custom | Leave the channel and release resources. |
* Native nodes are nodes that come with the blueprint and can be added and called directly.
** Custom nodes are not included in the blueprint. You create a custom function before you can add the corresponding node.
Add channel-related variables
Add variables to create an engine instance and join a channel.
-
Create three variables:
Token, ChannelId, and AppId. Select the Variable Type as String.
-
In the Load Agora Config function, add the Sequence node, and then connect Set Token, Set Channel Id, and Set App Id respectively. Fill in the token, channel name, and app ID values obtained from Agora Console.
Initialize RTC engine
-
If your target platform is Android, check whether system permissions have been granted before initializing the RTC engine. Refer to the following figure to create nodes for adding permissions to access the microphone and camera in the CheckPermission function.
If your target platform is macOS or iOS, please refer to How do I add the permissions needed for real-time interaction to my Unreal Engine project?
-
To initialize the RTC engine, in the InitRtcEngine function, create and connect nodes as shown in the following figure:
-
Create
IRtcEngineandIRtcEngineEventHandler.-
To store references to the engine and event-handler interface classes, create
RtcEngineandEventHandlervariables, and set the Variable Type to Agora Rtc Engine and IRtc Engine Event Handler, respectively. -
Add two Construct Object From Class nodes, set Class to Agora Rtc Engine and IRtc Engine Event Handler respectively. Connect to Set Rtc Engine and Set Event Handler, respectively.
-
Bind
IRtcEngineEventHandlerclass-related callback functions. -
Create
onJoinChannelSuccess,onLeaveChannel,onUserJoined, andonUserOfflinecallback functions. Refer to the following table to configure the input parameters of the callbacks:Callback Description Input parameters FOnJoinChannelSuccessThe local user successfully joined a channel. channel: (String) Channel name.uid: (Integer64) The ID of the user joining the channel.elapsed: (Integer) The time (in milliseconds) that elapsed from the local call toJoinChanneltill the occurrence of this event.
FOnLeaveChannelThe local user left the channel. stats: Call statistics.
FOnUserJoinedA remote user joined the current channel. uid: (Integer64) The user ID of the remote user joining the channel.elapsed: (Integer) The time (in milliseconds) that elapsed from the local call toJoinChanneltill the occurrence of this event.
FOnUserOfflineA remote user left the current channel. uid: (Integer64) The ID of the user going offline.reason: Offline reason. For details, seeEUSER_OFFLINE_REASON_TYPE.
-
Create a Bind Event function. In this function, add a Sequence node, and then bind the
onJoinChannelSuccess,onLeaveChannel,onUserJoined, andonUserOfflinecallback events. -
IRtcEngineinitialization -
Call Initialize to initialize the RTC engine.
-
Connect to the RtcEngineContext configuration
IRtcEngineinstance and select Channel Profile asCHANNEL_PROFILE_COMMUNICATION.
-
Bind UI events
To bind UI events:
-
Create and implement the
OnJoinChannelClickedevent callback.- Call Enable Audio to enable the audio modules.
- Call Join Channel to join the channel.
- Set the following parameters in Make ChannelMediaOptions:
- Set Publish Microphone Track to
AGORA TRUE VALUEto publish the audio stream recorded by the microphone. - Set Auto Subscribe Video to
AGORA TRUE VALUEto automatically subscribe to all video streams. - Check Client Role Type Set Value and set Client Role Type to
CLIENT_ROLE_BROADCASTERorCLIENT_ROLE_AUDIENCE, to set the user role to host or audience. - Check Channel Profile Set Value and set Channel Profile to
CHANNEL_PROFILE_COMMUNICATION.
- Set Publish Microphone Track to
-
Create and implement the
OnLeaveChannelClickedevent callback. When the event is triggered, call Leave Channel to leave the channel. -
In the Bind UIEvent function, refer to the figure below to bind the
OnJoinChannelClickedandOnLeaveChannelClickedcallback functions to the Join Channel and Leave Channel buttons respectively. When the button is clicked, the corresponding event callback is triggered.
You can also bind UI events in Unreal Motion Graphics (UMG). This document only shows binding using the Bind UIEvent Function.
Implement callback function
Configure the previously created onJoinChannelSuccess, onLeaveChannel, onUserJoined, and onUserOffline callback functions as follows:
-
After the local user successfully joins the channel, the
onJoinChannelSuccesscallback is triggered and the local view is created. Theuidis set to0by default, but it is assigned a random value by the SDK. The video source type isVIDEO_SOURCE_CAMERA_PRIMARY(first camera): -
After the local user leaves the channel, the
onLeaveChannelcallback is triggered which releases the local view: -
When a remote user joins the channel, the
onUserJoinedcallback is triggeredd to create a remote view.uidis the uid sent from the remote end, and the video source type isVIDEO_SOURCE_REMOTE(remote video obtained from the network): -
When a remote user leaves the channel, the
onUserOfflinecallback is triggered to release the remote view:
Leave the channel and release resources
To leave the channel, implement the following steps:
- Leave the channel.
- Unregister Agora SDRTN® event callback.
- Destroy
IRtcEngineObjectto release all resources used by Agora SDK.
Refer to the figure below to implement the UnInitRtcEngine function:
Test the sample code
Take the following steps to test the sample code:
-
In the Load Agora Config function, fill in the app ID, channel name, and temporary token for your project.
-
In the Unreal Editor, click Play to run your project. Click JoinChannel to join a channel.
-
Invite a friend to run the demo game on a second device. Use the same app ID, channel name, and token to join. After your friend joins successfully, you can hear and see each other.
Reference
This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.
- If a firewall is deployed in your network environment, refer to Connect with Cloud Proxy to use Agora services normally.
Next steps
After implementing the quickstart sample, read the following documents to learn more:
- To ensure communication security in a test or production environment, best practice is to obtain and use a token from an authentication server. For details, see Secure authentication with tokens.
Sample project
Agora provides open source sample projects on GitHub for your reference. Download or view the JoinChannelVideo project for a more detailed example.
Frequently asked questions
- How can I listen for audience joining or leaving a channel?
- How can I fix black screen issues?
- Why can't I turn on the camera?
- How can I solve channel-related issues?
- How can I set the log file?
