中文 | English
- Agora Linux Server Java SDK
- Table of Contents
- Introduction
- Development Environment Requirements
- SDK Download
- Integrate the SDK
- Quick Start
- API Reference
- Changelog
- Other References
- Other References
The Agora Linux Server Java SDK (v4.4.32.101) provides powerful real-time audio and video communication capabilities that can be seamlessly integrated into Linux server-side Java applications. With this SDK, your server can join Agora channels as a data source or processing node, accessing and processing audio and video streams in real-time to implement various business-related advanced features.
The Agora Linux Gateway SDK has not been released yet, and related features are currently not supported.
Note: If you are upgrading from a version earlier than v4.4.32.100 to v4.4.32.100 or later, please refer to the AIQoS Upgrade Guide for required API and integration changes.
- Operating System: Ubuntu 18.04+ or CentOS 7.0+
- CPU Architecture: x86-64
- Performance Requirements:
- CPU: 8 cores @ 1.8 GHz or higher
- Memory: 2 GB (4 GB+ recommended)
- Network Requirements:
- Public IP address
- Allow access to
.agora.io
and.agoralab.co
domains
- Apache Maven or other build tools
- JDK 8+
<dependency>
<groupId>io.agora.rtc</groupId>
<artifactId>linux-java-sdk</artifactId>
<version>4.4.32.101</version>
</dependency>
Agora-Linux-Java-SDK-v4.4.32.101-x86_64-860822-199c582312-20250901_154513
There are two ways to integrate the SDK: via Maven integration and local SDK integration.
Maven integration is the simplest method, automatically managing Java dependencies.
Add the following dependency to your project's pom.xml
file:
<!-- x86_64 platform -->
<dependency>
<groupId>io.agora.rtc</groupId>
<artifactId>linux-java-sdk</artifactId>
<version>4.4.32.101</version>
</dependency>
The Maven dependency includes the required JAR files, but you still need to manually handle the .so
library files to run the application. Please refer to the Loading Native Libraries (.so Files) section below.
The local SDK is a complete package containing all necessary files, suitable for scenarios requiring more flexible control.
The SDK package (zip format) downloaded from the official website contains the following:
- doc/ - JavaDoc documentation, detailed API descriptions
- examples/ - Example code and projects
- sdk/ - Core SDK files
agora-sdk.jar
- Java libraryagora-sdk-javadoc.jar
- JavaDoc documentation
You can integrate the JAR files in two ways:
Method 1: Install only the SDK JAR
mvn install:install-file \
-Dfile=sdk/agora-sdk.jar \
-DgroupId=io.agora.rtc \
-DartifactId=linux-java-sdk \
-Dversion=4.4.32.101 \
-Dpackaging=jar \
-DgeneratePom=true
Method 2: Install both SDK JAR and JavaDoc JAR
mvn install:install-file \
-Dfile=sdk/agora-sdk.jar \
-DgroupId=io.agora.rtc \
-DartifactId=linux-java-sdk \
-Dversion=4.4.32.101 \
-Dpackaging=jar \
-DgeneratePom=true \
-Djavadoc=sdk/agora-sdk-javadoc.jar
After installation, add the dependency to your pom.xml
:
<dependency>
<groupId>io.agora.rtc</groupId>
<artifactId>linux-java-sdk</artifactId>
<version>4.4.32.101</version>
</dependency>
-
Copy the JAR files to your project's
libs
directory:mkdir -p libs cp sdk/agora-sdk.jar libs/ cp sdk/agora-sdk-javadoc.jar libs/ # Optional, for IDE support
-
Add a classpath reference in your Java project:
# Use the SDK JAR java -cp .:libs/agora-sdk.jar YourMainClass # Configure JavaDoc in your IDE (Common IDEs like IntelliJ IDEA or Eclipse support direct association of JavaDoc JARs)
The downloaded SDK package already contains the .so
files. You need to ensure that the Java program can find these files at runtime. Please refer to the Loading Native Libraries (.so Files) section below.
The Agora Linux Server Java SDK depends on underlying C++ native libraries (.so
files). Whether integrating via Maven or locally, you must ensure the Java Virtual Machine (JVM) can find and load these libraries at runtime.
The .so
files are contained within the agora-sdk.jar
or linux-java-sdk-x.x.x.x.jar
file. You need to extract them first:
-
Create a directory in your project or deployment location to store the library files, for example,
libs
:mkdir -p libs cd libs
-
Use the
jar
command to extract the contents from the SDK's JAR file (assuming the JAR file is in thelibs
directory or Maven cache):# If using local integration, the JAR file is typically in the libs directory jar xvf agora-sdk.jar # If using Maven integration, the JAR file is in the Maven cache, e.g.: # jar xvf ~/.m2/repository/io/agora/rtc/linux-java-sdk/4.4.32.101/linux-java-sdk-4.4.32.101.jar
-
After extraction, a
native/linux/x86_64
subdirectory will be generated within thelibs
directory, containing the required.so
files:libs/ ├── agora-sdk.jar (or empty, if only used for extraction) ├── io/ # Java class files, ignore ├── META-INF/ # JAR and application metadata, ignore └── native/ # Native libraries for corresponding platforms └── linux/ └── x86_64/ # x86_64 platform .so libraries ├── libagora_rtc_sdk.so ├── libagora-fdkaac.so ├── libaosl.so └── libbinding.so
There are two main methods to help the JVM find the .so
files:
Method 1: Setting the LD_LIBRARY_PATH
Environment Variable (Recommended)
This is the most reliable method, especially when there are dependencies between .so
files.
# Determine the directory containing your .so files, assuming ./libs/native/linux/x86_64
LIB_DIR=$(pwd)/libs/native/linux/x86_64
# Set the LD_LIBRARY_PATH environment variable, adding the library directory to the beginning of the existing path
export LD_LIBRARY_PATH=$LIB_DIR:$LD_LIBRARY_PATH
# Run your Java application
java -jar YourApp.jar
# Or using classpath
# java -cp "YourClasspath" YourMainClass
Method 2: Using the JVM Parameter -Djava.library.path
This method directly tells the JVM where to look for library files.
# Determine the directory containing your .so files, assuming ./libs/native/linux/x86_64
LIB_DIR=$(pwd)/libs/native/linux/x86_64
# Run the Java application, specifying the library path via the -D parameter
java -Djava.library.path=$LIB_DIR -jar YourApp.jar
# Or using classpath
# java -Djava.library.path=$LIB_DIR -cp "YourClasspath" YourMainClass
Note:
- Method 1 (
LD_LIBRARY_PATH
) is recommended as it handles dependencies between libraries better. If only-Djava.library.path
is used, loading might fail sometimes because a library cannot find its dependencies.- Ensure
$LIB_DIR
points to the exact directory containing files likelibagora_rtc_sdk.so
.- You can include the command to set the environment variable in a startup script for automatic configuration when running the application.
Refer to the following script example, which combines both methods and sets the classpath:
#!/bin/bash
# Get the absolute path of the directory where the script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Determine the .so library file path (assuming under libs/native/linux/x86_64 in the script directory)
LIB_PATH="$SCRIPT_DIR/libs/native/linux/x86_64"
# SDK JAR path (assuming under libs in the script directory)
SDK_JAR="$SCRIPT_DIR/libs/agora-sdk.jar"
# Your application's main class
MAIN_CLASS="YourMainClass"
# Your application's other dependency classpath (if any)
APP_CP="YourOtherClasspath"
# Set the library path environment variable
export LD_LIBRARY_PATH=$LIB_PATH:$LD_LIBRARY_PATH
# Combine the classpath
CLASSPATH=".:$SDK_JAR:$APP_CP" # '.' represents the current directory
# Execute the Java program
# Use both LD_LIBRARY_PATH and -Djava.library.path for compatibility
java -Djava.library.path=$LIB_PATH -cp "$CLASSPATH" $MAIN_CLASS
Refer to the Official Example Documentation
Refer to Official Service Activation Guide
Examples-Mvn is a Maven example project built on the Spring Boot framework, providing a complete RESTful API service to demonstrate various features of the Agora Linux Server Java SDK.
This project has integrated C++ code compilation functionality, which can automatically compile and generate required .so library files during the Maven build process.
-
Install Maven Build Tool
Refer to Maven Installation Guide
sudo apt-get install maven -y sudo apt-get install lsof -y
-
C++ Compilation Environment (if native library compilation is needed)
Install basic compilation tools:
sudo apt-get update sudo apt-get install build-essential pkg-config gcc g++
-
Install C++ Runtime Library
The native libraries of the SDK depend on the
libc++
runtime. Please install it to avoid link errors:sudo apt-get install libc++1
-
FFmpeg Dependencies (if FFmpeg features need to be compiled)
sudo apt-get install libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libswresample-dev
-
Ensure JAVA_HOME is set correctly
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
-
Enter the
Examples-Mvn
directory:cd Examples-Mvn
-
Create a
.keys
file and add:APP_ID=your_app_id TOKEN=your_token
If certificates are not enabled, the TOKEN value can be empty, e.g.:
APP_ID=abcd1234 TOKEN=
If Gateway SDK is supported, create a
.keys_gateway
file and add:APP_ID=your_app_id LICENSE=your_license
-
Runtime Configuration (run_config)
The
run_config
file is used to configure various runtime options, located atExamples-Mvn/run_config
. You can modify the following configurations as needed:Configuration Type Default Description enable_asan boolean false Whether to enable AddressSanitizer for memory error detection enable_gateway boolean false Whether to enable Gateway SDK mode, which allows access to VAD and Audio 3A features Configuration Example:
# Enable Gateway SDK functionality enable_gateway=true # Enable memory checking (debug mode) enable_asan=true
Note:
- The project needs to be recompiled after modifying the configuration.
-
Configure Java SDK
This section describes how to configure the Linux Java SDK dependency for your Maven project.
Step 1: Configure JAR Dependency
You have two ways to configure the project's JAR dependency:
Method 1: Using Maven Central Repository (Recommended)
If your project can directly fetch dependencies from the Maven Central Repository, ensure that the correct version number is configured in
pom.xml
.<dependency> <groupId>io.agora.rtc</groupId> <artifactId>linux-java-sdk</artifactId> <version>4.4.32.101</version> <!-- Ensure the version number is consistent with the one you need to use --> </dependency>
Method 2: Using a Local SDK Package
If you need to use a local SDK package (e.g., a customized or internal version), follow these steps:
-
Place SDK Artifacts: Place the downloaded SDK JAR package (e.g.,
agora-sdk.jar
) and the corresponding Javadoc package (agora-sdk-javadoc.jar
) into theExamples-Mvn/libs/
directory. -
Install to Local Maven Repository: In the
linux_server_java
directory, execute the following script. This script will install the JAR files from thelibs
directory as Maven artifacts into your local repository (usually located at~/.m2/repository
)../build_install_local_maven.sh
-
Update Project Dependencies: In your project's
pom.xml
(e.g.,Examples-Mvn
), update the version of thelinux-java-sdk
dependency to match the version you installed locally.
Step 2: Configure Native Libraries (
.so
)To ensure the Java program can successfully load the native libraries (
.so
files) at runtime, you need to place them in the specified path.-
Enter the
libs
directory:cd linux_server_java/Examples-Mvn/libs/
-
Extract Native Libraries from JAR:
# -x: extract, -v: verbose, -f: file jar -xvf agora-sdk.jar native/
This command extracts the
native
directory fromagora-sdk.jar
, which contains the native libraries for all platforms. -
Verify Directory Structure: After extraction, the
libs
directory structure should be as follows, ensuring the.so
files are located under thenative/linux/x86_64/
path:libs/ ├── agora-sdk.jar ├── agora-sdk-javadoc.jar └── native/ └── linux/ └── x86_64/ ├── libagora_rtc_sdk.so ├── libagora-fdkaac.so └── ... (other .so files)
-
Return to the project root directory:
cd ../../..
-
Execute the build script:
# Standard Maven build (without compiling native code)
./build.sh
# Compile and start service
./build.sh start
# Compile all native libraries
./build.sh -native
# Compile all native libraries and start service
./build.sh -native start
# Compile only FFmpeg-related libraries
./build.sh -ffmpegUtils
# Compile only Media-related libraries
./build.sh -mediaUtils
Build Options:
- By default, only compiles the Java project without compiling C++ code
- Use
-native
option to compile all native libraries (FFmpeg + Media) - Use
-ffmpegUtils
option to compile only FFmpeg-related libraries (for MP4 processing) - Use
-mediaUtils
option to compile only Media-related libraries (for encoded audio/video processing) - Use
start
option to automatically start the service after compilation
Using Maven Commands:
You can also use Maven commands directly:
# Compile all native libraries
mvn clean package -Dbuild.native=true
# Compile only FFmpeg libraries
mvn clean package -Dbuild.ffmpeg=true
# Compile only Media libraries
mvn clean package -Dbuild.media=true
After starting the service, use a browser or Postman to access the following interface addresses to test various features:
Basic Feature Test Interface:
http://localhost:18080/api/server/basic?taskName=ReceiverPcmDirectSendTest
http://localhost:18080/api/server/basic?taskName=ReceiverPcmH264Test
http://localhost:18080/api/server/basic?taskName=ReceiverPcmVadTest
http://localhost:18080/api/server/basic?taskName=ReceiverPcmYuvTest
http://localhost:18080/api/server/basic?taskName=SendH264Test
http://localhost:18080/api/server/basic?taskName=SendMp4Test
http://localhost:18080/api/server/basic?taskName=SendOpusTest
http://localhost:18080/api/server/basic?taskName=SendPcmFileTest
http://localhost:18080/api/server/basic?taskName=SendPcmRealTimeTest
http://localhost:18080/api/server/basic?taskName=SendReceiverStreamMessageTest
http://localhost:18080/api/server/basic?taskName=SendYuvTest
Gateway SDK Exclusive Features:
http://localhost:18080/api/server/basic?taskName=VadV1Test
http://localhost:18080/api/server/basic?taskName=Audio3aTest
Configuration File Interface:
http://localhost:18080/api/server/start?configFileName=pcm_send.json
Note: Replace
localhost:18080
with your actual server address and port.
-
Send PCM Audio
Refer to SendPcmFileTest.java, implement looping PCM file sending
Refer to SendPcmRealTimeTest.java, implement streaming PCM data sending
-
Send YUV Video
Refer to SendYuvTest.java, implement streaming YUV data sending
-
Send H264 Video
Refer to SendH264Test.java, implement streaming H264 data sending
-
Send Opus Audio
Refer to SendOpusTest.java, implement streaming Opus data sending
-
Send MP4 Audio/Video
Refer to SendMp4Test.java, implement MP4 file sending
-
Receive PCM Audio
Refer to ReceiverPcmVadTest.java, implement receiving PCM data with VAD data
Refer to ReceiverPcmDirectSendTest.java, implement receiving PCM data and directly sending back
-
Receive PCM&H264 Audio/Video
Refer to ReceiverPcmH264Test.java, implement receiving PCM & H264 data
-
Receive PCM&YUV Audio/Video
Refer to ReceiverPcmYuvTest.java, implement receiving PCM & YUV data
-
Send/Receive Stream Messages
Refer to SendReceiverStreamMessageTest.java, implement sending and receiving stream messages
-
VadV1 Module (Only supported by Gateway SDK)
Refer to VadV1Test.java, implement VadV1 module functionality
-
Audio 3A Processing (Only supported by Gateway SDK)
Refer to Audio3aTest.java, implement audio 3A processing functionality
For complete API documentation, refer to the following resources:
- API-reference.md file (For reference only, based on the Chinese version)
- Official Documentation Agora Java Server SDK API Reference (Official documentation takes precedence)
AgoraAudioVad
is a Voice Activity Detection (VAD) module for processing audio frames. It detects speech activity in an audio stream and processes it based on configuration parameters. This module is the first version of VAD, providing basic voice activity detection functionality.
Constructor
public AgoraAudioVad()
- Description: Constructs an
AgoraAudioVad
instance.
Methods
public int initialize(AgoraAudioVadConfig config)
- Description: Initializes the VAD module. This must be called before using other methods.
- Parameters:
config
:AgoraAudioVadConfig
type, VAD configuration.
- Returns:
int
, 0 for success, -1 for failure.
public VadProcessResult processPcmFrame(byte[] frame)
- Description: Processes PCM audio frames.
- Parameters:
frame
:byte[]
type, PCM audio data.
- Returns:
VadProcessResult
type, VAD processing result.
public synchronized void destroy()
- Description: Destroys the VAD module and releases resources.
Main Properties
Property Name | Type | Description | Default | Range |
---|---|---|---|---|
fftSz | int | FFT size, supports only 128, 256, 512, 1024 | 1024 | [128, 256, 512, 1024] |
hopSz | int | FFT hop size, used for checking | 160 | [1, Integer.MAX_VALUE] |
anaWindowSz | int | FFT window size, used for calculating RMS | 768 | [1, Integer.MAX_VALUE] |
voiceProbThr | float | Voice probability threshold | 0.8 | [0.0, 1.0] |
rmsThr | float | RMS threshold (dB) | -40.0 | [-100.0, 0.0] |
jointThr | float | Joint threshold (dB) | 0.0 | [-100.0, 100.0] |
aggressive | float | Aggressive factor, higher value means more aggressive | 5.0 | [0.0, 10.0] |
startRecognizeCount | int | Start recognition count | 10 | [1, Integer.MAX_VALUE] |
stopRecognizeCount | int | Stop recognition count | 6 | [1, Integer.MAX_VALUE] |
preStartRecognizeCount | int | Pre-start recognition count | 10 | [0, Integer.MAX_VALUE] |
activePercent | float | Active percentage | 0.6 | [0.0, 1.0] |
inactivePercent | float | Inactive percentage | 0.2 | [0.0, 1.0] |
Here is a simple example showing how to use AgoraAudioVad
for audio frame processing:
import io.agora.rtc.AgoraAudioVad;
import io.agora.rtc.AgoraAudioVadConfig;
import io.agora.rtc.VadProcessResult;
import java.io.FileInputStream;
public class VadV1Example {
public static void main(String[] args) {
// Create VAD instance
AgoraAudioVad audioVad = new AgoraAudioVad();
// Create configuration
AgoraAudioVadConfig config = new AgoraAudioVadConfig();
// Configure parameters as needed, recommend using default values
// Initialize VAD
int ret = audioVad.initialize(config);
if (ret != 0) {
System.err.println("Failed to initialize VAD: " + ret);
return;
}
// Process audio frames
try {
// Assume we have PCM audio data
byte[] pcmData = new byte[320]; // 10ms 16kHz mono PCM16 data
VadProcessResult result = audioVad.processPcmFrame(pcmData);
if (result != null) {
System.out.println("VAD State: " + result.getState());
if (result.getOutFrame() != null) {
System.out.println("Output Frame Length: " + result.getOutFrame().length);
}
}
} catch (Exception e) {
e.printStackTrace();
}
// Destroy VAD instance
audioVad.destroy();
}
}
AgoraAudioVadV2
is the second version of the Voice Activity Detection (VAD) module for processing audio frames. It detects speech activity in an audio stream and processes it based on configuration parameters.
Constructor
public AgoraAudioVadV2(AgoraAudioVadConfigV2 config)
- Parameters
config
:AgoraAudioVadConfigV2
type, VAD configuration.
Property Name | Type | Description | Default | Range |
---|---|---|---|---|
preStartRecognizeCount | int | Number of audio frames saved before entering speaking state | 16 | [0, Integer.MAX_VALUE] |
startRecognizeCount | int | Number of audio frames to confirm speaking state | 30 | [1, Integer.MAX_VALUE] |
stopRecognizeCount | int | Number of audio frames to confirm stop speaking state | 20 | [1, Integer.MAX_VALUE] |
activePercent | float | Percentage of active frames required in startRecognizeCount frames | 0.7 | [0.0, 1.0] |
inactivePercent | float | Percentage of inactive frames required in stopRecognizeCount frames | 0.5 | [0.0, 1.0] |
startVoiceProb | int | Probability threshold to start voice detection | 70 | [0, 100] |
stopVoiceProb | int | Probability threshold to stop voice detection | 70 | [0, 100] |
startRmsThreshold | int | RMS threshold (dBFS) to start voice detection | -50 | [-100, 0] |
stopRmsThreshold | int | RMS threshold (dBFS) to stop voice detection | -50 | [-100, 0] |
startVoiceProb
: Lower value means higher probability of a frame being judged active, starting the phase earlier. Lower it for more sensitive detection.stopVoiceProb
: Higher value means higher probability of a frame being judged inactive, ending the phase earlier. Raise it for quicker end detection.startRmsThreshold
&stopRmsThreshold
:- Higher value means more sensitive to voice activity.
- Default -50 is recommended for quiet environments.
- In noisy environments, adjust between -40 and -30 to reduce false positives.
- Fine-tune based on the actual usage scenario and audio characteristics for optimal results.
public synchronized VadProcessResult processFrame(AudioFrame frame)
- Parameters
frame
:AudioFrame
type, the audio frame.
- Returns
VadProcessResult
type, the VAD processing result.
public synchronized void destroy()
- Destroys the VAD module and releases resources.
Stores the result of VAD processing.
public VadProcessResult(byte[] result, Constants.VadState state)
- Parameters
result
:byte[]
type, the processed audio data.state
:Constants.VadState
type, the current VAD state.
Here is a simple example showing how to use AgoraAudioVadV2
for audio frame processing:
import io.agora.rtc.AgoraAudioVadV2;
import io.agora.rtc.AgoraAudioVadConfigV2;
import io.agora.rtc.Constants;
import io.agora.rtc.AudioFrame;
import io.agora.rtc.VadProcessResult;
public class VadV2Example {
public static void main(String[] args) {
// Create VAD configuration
AgoraAudioVadConfigV2 config = new AgoraAudioVadConfigV2();
config.setPreStartRecognizeCount(16);
config.setStartRecognizeCount(30);
config.setStopRecognizeCount(20);
config.setActivePercent(0.7f);
config.setInactivePercent(0.5f);
config.setStartVoiceProb(70);
config.setStopVoiceProb(70);
config.setStartRmsThreshold(-50);
config.setStopRmsThreshold(-50);
// Create VAD instance
AgoraAudioVadV2 vad = new AgoraAudioVadV2(config);
// Simulate audio frame processing
AudioFrame frame = new AudioFrame();
// Set frame properties...
VadProcessResult result = vad.processFrame(frame);
if (result != null) {
System.out.println("VAD State: " + result.getState());
// Assuming getResult() exists on VadProcessResult (based on constructor)
// System.out.println("Processed Data Length: " + result.getResult().length);
System.out.println("Processed Data Length: " + result.getOutFrame().length); // Using getOutFrame based on API Ref
}
// Destroy VAD instance
vad.destroy();
}
}
The AgoraAudioProcessor
is a module designed for Audio 3A processing and Background Human Voice Suppression (BGHVS), which includes Acoustic Echo Cancellation (AEC), Automatic Noise Suppression (ANS), Automatic Gain Control (AGC), and Background Human Voice Suppression (BGHVS). It processes audio frames to enhance audio quality by mitigating echo, reducing noise, normalizing volume levels, and suppressing background human voices. This module requires corresponding model files to perform its processing tasks.
public AgoraAudioProcessor()
- Description: Constructs an
AgoraAudioProcessor
instance.
public int init(String appId, String license, IAgoraAudioProcessorEventHandler eventHandler, AgoraAudioProcessorConfig config)
- Description: Initializes the audio processor. This must be called before any other methods.
- Parameters:
appId
:String
, your App ID obtained from Agora Console.license
:String
, your License key obtained from Agora Console.eventHandler
:IAgoraAudioProcessorEventHandler
, a callback handler to receive processor events and errors.config
:AgoraAudioProcessorConfig
, the 3A processor configuration object, used for setting the model path, etc.
- Returns:
int
, 0 for success, other values indicate failure.
public AgoraAudioFrame process(AgoraAudioFrame nearIn)
- Description: Performs 3A processing (e.g., ANS, AGC) on the input near-end audio frame. Use this method when processing only near-end audio or when AEC is not required.
- Parameters:
nearIn
:io.agora.rtc.audio3a.AgoraAudioFrame
, the frame object containing near-end PCM audio data to be processed.
- Returns:
io.agora.rtc.audio3a.AgoraAudioFrame
, the processed audio frame. May returnnull
if processing fails.
public AgoraAudioFrame process(AgoraAudioFrame nearIn, AgoraAudioFrame farIn)
- Description: Performs 3A processing (e.g., AEC, ANS, AGC) on the input near-end and far-end audio frames. Use this method when Acoustic Echo Cancellation (AEC) or other processing that requires both near-end and far-end audio is needed.
- Parameters:
nearIn
:io.agora.rtc.audio3a.AgoraAudioFrame
, the frame object containing near-end PCM audio data to be processed.farIn
:io.agora.rtc.audio3a.AgoraAudioFrame
, the frame object containing far-end PCM audio data for reference, primarily used for Acoustic Echo Cancellation (AEC).
- Returns:
io.agora.rtc.audio3a.AgoraAudioFrame
, the processed near-end audio frame. May returnnull
if processing fails.
public int release()
- Description: Releases all resources occupied by the
AgoraAudioProcessor
instance. This should be called when processing is complete. - Returns:
int
, 0 for success, other values indicate failure.
This class is used to configure the AgoraAudioProcessor
.
public void setModelPath(String modelPath)
- Description: Sets the path to the model files required for 3A processing. Model files are typically provided with the SDK package, often in a
resources/model/
directory. - Parameters:
modelPath
:String
, the directory path where model files are located. For example,./resources/model/
.
public void setAecConfig(AecConfig aecConfig)
public AecConfig getAecConfig()
- Description: Sets and gets the Acoustic Echo Cancellation (AEC) configuration.
- Parameters:
aecConfig
:AecConfig
type, the AEC configuration object.
public void setAnsConfig(AnsConfig ansConfig)
public AnsConfig getAnsConfig()
- Description: Sets and gets the Automatic Noise Suppression (ANS) configuration.
- Parameters:
ansConfig
:AnsConfig
type, the ANS configuration object.
public void setAgcConfig(AgcConfig agcConfig)
public AgcConfig getAgcConfig()
- Description: Sets and gets the Automatic Gain Control (AGC) configuration.
- Parameters:
agcConfig
:AgcConfig
type, the AGC configuration object.
public void setBghvsConfig(BghvsConfig bghvsConfig)
public BghvsConfig getBghvsConfig()
- Description: Sets and gets the Background Human Voice Suppression (BGHVS) configuration.
- Parameters:
bghvsConfig
:BghvsConfig
type, the BGHVS configuration object.
AgoraAudioProcessorConfig config = new AgoraAudioProcessorConfig();
config.setModelPath("./resources/model/"); // Set according to the actual model file location
// Configure AEC
AecConfig aecConfig = new AecConfig();
aecConfig.setEnabled(true);
config.setAecConfig(aecConfig);
// Configure ANS
AnsConfig ansConfig = new AnsConfig();
ansConfig.setEnabled(true);
config.setAnsConfig(ansConfig);
// Configure AGC
AgcConfig agcConfig = new AgcConfig();
agcConfig.setEnabled(true);
config.setAgcConfig(agcConfig);
// Configure BGHVS
BghvsConfig bghvsConfig = new BghvsConfig();
bghvsConfig.setEnabled(true);
config.setBghvsConfig(bghvsConfig);
This interface is used to receive event and error notifications from the AgoraAudioProcessor
.
public void onEvent(Constants.AgoraAudioProcessorEventType eventType)
- Description: Reports events that occur during processor operation.
- Parameters:
eventType
:io.agora.rtc.Constants.AgoraAudioProcessorEventType
, the specific event type.
public void onError(int errorCode)
- Description: Reports errors that occur during processor operation.
- Parameters:
errorCode
:int
, the error code indicating the specific error that occurred.
This class is used to encapsulate audio data for processing by AgoraAudioProcessor
. (Note: This might be different from io.agora.rtc.AudioFrame
; use the version from the audio3a
package).
Property Name | Type | Description |
---|---|---|
type | int | Audio frame type, typically Constants.AudioFrameType.PCM16.getValue() . |
sampleRate | int | Audio sample rate (Hz), e.g., 16000, 32000, 48000. |
channels | int | Number of audio channels, e.g., 1 (mono) or 2 (stereo). |
samplesPerChannel | int | Number of samples per channel. For a 10ms frame, this is usually sampleRate / 100 . |
bytesPerSample | int | Number of bytes per sample. E.g., for PCM16, it's 2 bytes (Constants.BytesPerSample.TWO_BYTES_PER_SAMPLE.getValue() ). |
buffer | ByteBuffer | java.nio.ByteBuffer containing the raw PCM audio data. |
public void setType(int type);
public int getType();
public void setSampleRate(int sampleRate);
public int getSampleRate();
public void setChannels(int channels);
public int getChannels();
public void setSamplesPerChannel(int samplesPerChannel);
public int getSamplesPerChannel();
public void setBytesPerSample(int bytesPerSample);
public int getBytesPerSample();
public void setBuffer(java.nio.ByteBuffer buffer);
public java.nio.ByteBuffer getBuffer();
Below is a simple example demonstrating how to use AgoraAudioProcessor
for audio frame processing:
import io.agora.rtc.audio3a.AgoraAudioProcessor;
import io.agora.rtc.audio3a.AgoraAudioProcessorConfig;
import io.agora.rtc.audio3a.IAgoraAudioProcessorEventHandler;
import io.agora.rtc.audio3a.AgoraAudioFrame; // Use AgoraAudioFrame from the audio3a package
import io.agora.rtc.audio3a.AecConfig;
import io.agora.rtc.audio3a.AnsConfig;
import io.agora.rtc.audio3a.AgcConfig;
import io.agora.rtc.audio3a.BghvsConfig;
import io.agora.rtc.Constants; // SDK's constants class
import java.nio.ByteBuffer;
import java.util.Arrays; // For printing data in example
public class Audio3AProcessingExample {
public static void main(String[] args) {
// Replace with your App ID and License
String appId = "YOUR_APP_ID";
String license = "YOUR_LICENSE_KEY";
// 1. Create AgoraAudioProcessor instance
AgoraAudioProcessor audioProcessor = new AgoraAudioProcessor();
// 2. Configure AgoraAudioProcessorConfig
AgoraAudioProcessorConfig config = new AgoraAudioProcessorConfig();
// Set the model file path, usually in resources/model/ of the SDK package
// Ensure the path is correct, otherwise initialization might fail
config.setModelPath("./resources/model/"); // Modify according to your actual path
// Configure AEC (Acoustic Echo Cancellation)
AecConfig aecConfig = config.getAecConfig();
aecConfig.setEnabled(true); // Enable AEC
// Configure ANS (Automatic Noise Suppression)
AnsConfig ansConfig = config.getAnsConfig();
ansConfig.setEnabled(true); // Enable ANS
// Configure AGC (Automatic Gain Control)
AgcConfig agcConfig = config.getAgcConfig();
agcConfig.setEnabled(true); // Enable AGC
// Configure BGHVS (Background Human Voice Suppression)
BghvsConfig bghvsConfig = config.getBghvsConfig();
bghvsConfig.setEnabled(true); // Enable BGHVS
// 3. Initialize AgoraAudioProcessor
int initRet = audioProcessor.init(appId, license,
new IAgoraAudioProcessorEventHandler() {
@Override
public void onEvent(Constants.AgoraAudioProcessorEventType eventType) {
System.out.println("AgoraAudioProcessor Event: " + eventType);
}
@Override
public void onError(int errorCode) {
System.err.println("AgoraAudioProcessor Error: " + errorCode);
}
}, config);
if (initRet != 0) {
System.err.println("Failed to initialize AgoraAudioProcessor. Error code: " + initRet);
// Handle initialization failure based on the error code, e.g., check appId, license, modelPath
return;
}
System.out.println("AgoraAudioProcessor initialized successfully.");
// 4. Prepare audio frame (AgoraAudioFrame)
// Example parameters: 48kHz, mono, 10ms audio frame
int sampleRate = 48000;
int channels = 1;
int samplesPerChannel = sampleRate / 100; // 10ms frame -> 480 samples
int bytesPerSample = Constants.BytesPerSample.TWO_BYTES_PER_SAMPLE.getValue(); // PCM16
int bufferSize = samplesPerChannel * channels * bytesPerSample;
// Create near-end audio frame
AgoraAudioFrame nearInFrame = new AgoraAudioFrame();
nearInFrame.setType(Constants.AudioFrameType.PCM16.getValue());
nearInFrame.setSampleRate(sampleRate);
nearInFrame.setChannels(channels);
nearInFrame.setSamplesPerChannel(samplesPerChannel);
nearInFrame.setBytesPerSample(bytesPerSample);
// In a real application, pcmDataNear would come from a near-end audio source
byte[] pcmDataNear = new byte[bufferSize];
// ... Fill pcmDataNear with dummy data here ...
ByteBuffer nearAudioBuffer = ByteBuffer.allocateDirect(bufferSize);
nearAudioBuffer.put(pcmDataNear);
nearAudioBuffer.flip();
nearInFrame.setBuffer(nearAudioBuffer);
// Create far-end audio frame (for AEC)
AgoraAudioFrame farInFrame = new AgoraAudioFrame();
farInFrame.setType(Constants.AudioFrameType.PCM16.getValue());
farInFrame.setSampleRate(sampleRate);
farInFrame.setChannels(channels);
farInFrame.setSamplesPerChannel(samplesPerChannel);
farInFrame.setBytesPerSample(bytesPerSample);
// In a real application, pcmDataFar would come from a far-end audio source
byte[] pcmDataFar = new byte[bufferSize];
// ... Fill pcmDataFar with dummy data here ...
ByteBuffer farAudioBuffer = ByteBuffer.allocateDirect(bufferSize);
farAudioBuffer.put(pcmDataFar);
farAudioBuffer.flip();
farInFrame.setBuffer(farAudioBuffer);
// 5. Process the audio frame
// If you only need to process the near-end audio (e.g., only ANS, AGC),
// you can call the single-parameter process method:
// AgoraAudioFrame outputFrame = audioProcessor.process(nearInFrame);
// If AEC processing is required, pass both near-end and far-end audio frames
AgoraAudioFrame outputFrame = audioProcessor.process(nearInFrame, farInFrame);
if (outputFrame != null && outputFrame.getBuffer() != null) {
System.out.println("Audio frame processed successfully.");
ByteBuffer processedBuffer = outputFrame.getBuffer();
// processedBuffer contains the 3A + BGHVS-processed audio data
// The processed audio will have the following optimizations:
// - AEC: Acoustic echo cancellation
// - ANS: Background noise suppression
// - AGC: Automatic gain control
// - BGHVS: Background human voice suppression
// You can write this data to a file, send it over the network, or perform other operations
// Example: Get processed byte data:
// byte[] processedBytes = new byte[processedBuffer.remaining()];
// processedBuffer.get(processedBytes);
// System.out.println("Processed data sample (first 10 bytes): " +
// Arrays.toString(Arrays.copyOfRange(processedBytes, 0, Math.min(10, processedBytes.length))));
} else {
System.err.println("Failed to process audio frame or output frame is null.");
// Check for error callbacks or the return value of the process method
}
// 6. Release resources
int releaseRet = audioProcessor.release();
if (releaseRet == 0) {
System.out.println("AgoraAudioProcessor released successfully.");
} else {
System.err.println("Failed to release AgoraAudioProcessor. Error code: " + releaseRet);
}
}
}
-
API Changes
- AudioFrame: Added
presentationMs
field and getter/setter to carry audio frame PTS (ms). - EncodedVideoFrameInfo: Added
presentationMs
field and constructor parameter; can be used to pass video frame PTS (ms). - EncodedAudioFrameInfo: Added
captureTimeMs
field and constructor parameter; records capture timestamp (ms). - AgoraRtcConn: Added overload
pushAudioPcmData(byte[] data, int sampleRate, int channels, long presentationMs)
; the originalpushAudioPcmData(byte[] data, int sampleRate, int channels)
remains (equivalent topresentationMs=0
).
- AudioFrame: Added
-
Improvements & Optimizations
- Fixed a potential exception in
IAudioFrameObserver
callback under extreme scenarios, improving stability.
- Fixed a potential exception in
- This version supports AIQoS, and the API has changed, please refer to AIQoS Upgrade Guide
- Optimized the
onStreamMessage
callback parameters in theILocalUserObserver
interface. The original methodonStreamMessage(AgoraLocalUser agoraLocalUser, String userId, int streamId, String data, long length)
has been changed toonStreamMessage(AgoraLocalUser agoraLocalUser, String userId, int streamId, byte[] data)
to improve flexibility and efficiency in message handling.
- Fixed an issue in the
setLogFileSize
method ofAgoraServiceConfig
where the unit was incorrectly applied as bytes when set in KB. The log file size is now correctly set in KB.
AgoraService
: AddedgetSdkVersion
method to obtain the SDK version.AgoraAudioEncodedFrameSender
: Removedsend(byte[] payloadData, int payloadSize, EncodedAudioFrameInfo info)
method, replaced withsendEncodedAudioFrame(byte[] payloadData, EncodedAudioFrameInfo info)
.AgoraAudioPcmDataSender
: The methodsend(byte[] audioData, int captureTimestamp, int samplesPerChannel, int bytesPerSample, int numberOfChannels, int sampleRate)
is now deprecated, replaced withsendAudioPcmData(AudioFrame audioFrame)
.AgoraVideoEncodedImageSender
: Removedsend(byte[] imageBuffer, int length, EncodedVideoFrameInfo info)
method, replaced withsendEncodedVideoImage(byte[] imageBuffer, EncodedVideoFrameInfo info)
.AgoraVideoFrameSender
: Removedsend(ExternalVideoFrame frame)
method, replaced withsendVideoFrame(ExternalVideoFrame frame)
.
- Fixed a potential crash issue caused by the
destroy
method.
- Fixed potential crashes caused by exceptions in multi-threaded environments.
- Improved error handling processes, enhancing recovery capabilities in exceptional circumstances.
- Fixed exception handling issues potentially caused by memory reuse.
- Added
sendStreamMessage(int streamId, byte[] messageData)
method, deprecatedsendStreamMessage(int streamId, String message, int length)
method.
- Optimized code handling, improving system robustness.
- Optimized VAD function configuration; VAD is now enabled by default, manual configuration is not required.
- Added
DomainLimit
configuration option inAgoraServiceConfig
for domain limit management. - Added
VadDumpUtils
utility class, supporting export of debug data from the VAD process. - Added
AudioConsumerUtils
class, providing an optimized PCM data transmission mechanism. - Modified
registerAudioFrameObserver
method inAgoraLocalUser
to support configuration ofAgoraAudioVadConfigV2
parameters. - Added
vadResult
parameter to theonPlaybackAudioFrameBeforeMixing
callback inIAudioFrameObserver
. - Added
sendAudioMetaData
method inAgoraLocalUser
class to support sending audio metadata. - Added
onAudioMetaDataReceived
callback inILocalUserObserver
class for receiving audio metadata. - Added
ColorSpace
property inExternalVideoFrame
class to support custom color space settings.
- Optimized code logic architecture, significantly improving memory usage efficiency.
- Fixed multiple memory leak issues, enhancing system stability.
- Strengthened memory access security mechanisms, effectively preventing memory corruption issues.
- Enhanced
processFrame
handling in AgoraAudioVadV2, addingSTART_SPEAKING
andSTOP_SPEAKING
state callbacks. - Improved parameter types for encoded frame callbacks:
onEncodedAudioFrameReceived
,onEncodedVideoImageReceived
,onEncodedVideoFrame
now useByteBuffer
instead ofByte
arrays.
- VAD plugin startup optimization:
enableExtension
is now handled internally by the SDK; applications no longer need to call this method manually. - Fixed handling issues with
alphaBuffer
andmetadataBuffer
inVideoFrame
.
- Added AgoraAudioVad2 related
Vad2
interface, removed AgoraAudioVad relatedVad
interface. - Added callback interface
IAudioEncodedFrameObserver
for receiving encoded audio.
- Fixed crash issues related to
LocalAudioDetailedStats
callbacks. - Modified parameter types for the
onAudioVolumeIndication
callback.
- For detailed changelog, please refer to the Release Notes
Refer to the official website for details (https://docs.agora.io/en/rtc-server-sdk/java/landing-page/)
Official API documentation Agora Server Java SDK API Reference
- Fixed exception handling issues potentially caused by memory reuse.
- Added
sendStreamMessage(int streamId, byte[] messageData)
method, deprecatedsendStreamMessage(int streamId, String message, int length)
method.
- Optimized code handling, improving system robustness.
- Optimized VAD function configuration; VAD is now enabled by default, manual configuration is not required.
- Added
DomainLimit
configuration option inAgoraServiceConfig
for domain limit management. - Added
VadDumpUtils
utility class, supporting export of debug data from the VAD process. - Added
AudioConsumerUtils
class, providing an optimized PCM data transmission mechanism. - Modified
registerAudioFrameObserver
method inAgoraLocalUser
to support configuration ofAgoraAudioVadConfigV2
parameters. - Added
vadResult
parameter to theonPlaybackAudioFrameBeforeMixing
callback inIAudioFrameObserver
. - Added
sendAudioMetaData
method inAgoraLocalUser
class to support sending audio metadata. - Added
onAudioMetaDataReceived
callback inILocalUserObserver
class for receiving audio metadata. - Added
ColorSpace
property inExternalVideoFrame
class to support custom color space settings.
- Optimized code logic architecture, significantly improving memory usage efficiency.
- Fixed multiple memory leak issues, enhancing system stability.
- Strengthened memory access security mechanisms, effectively preventing memory corruption issues.
- Enhanced
processFrame
handling in AgoraAudioVadV2, addingSTART_SPEAKING
andSTOP_SPEAKING
state callbacks. - Improved parameter types for encoded frame callbacks:
onEncodedAudioFrameReceived
,onEncodedVideoImageReceived
,onEncodedVideoFrame
now useByteBuffer
instead ofByte
arrays.
- VAD plugin startup optimization:
enableExtension
is now handled internally by the SDK; applications no longer need to call this method manually. - Fixed handling issues with
alphaBuffer
andmetadataBuffer
inVideoFrame
.
- Added AgoraAudioVad2 related
Vad2
interface, removed AgoraAudioVad relatedVad
interface. - Added callback interface
IAudioEncodedFrameObserver
for receiving encoded audio.
- Fixed crash issues related to
LocalAudioDetailedStats
callbacks. - Modified parameter types for the
onAudioVolumeIndication
callback.
- For detailed changelog, please refer to the Release Notes
Refer to the official website for details (https://docs.agora.io/en/rtc-server-sdk/java/landing-page/)
Official API documentation Agora Server Java SDK API Reference