io.agora.rtc

## Class AgoraExternalAudioProcessor

- java.lang.Object
- - io.agora.rtc.AgoraExternalAudioProcessor

-     public class AgoraExternalAudioProcessor
      extends java.lang.Object

  External audio processor for processing audio data with 3A (AEC, ANS, AGC) and VAD. This class allows pushing PCM audio data for processing and receiving processed audio through observer callbacks.
  See Also:
    `IExternalAudioProcessorObserver`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private AgoraServiceConfig` | `agoraServiceConfig` Agora service configuration
    `private AudioFrame` | `audioFrame` Audio frame buffer
    `private AgoraAudioPcmDataSender` | `audioFrameSender` Audio PCM data sender
    `private long` | `cptr` Native pointer to the external audio processor
    `private AgoraLocalAudioTrack` | `customAudioTrack` Custom audio track
    `private boolean` | `initialized` Whether the processor has been initialized
    `private AgoraExternalAudioProcessorObserverWrapper` | `observerWrapper` Observer wrapper - must be kept alive to prevent GC

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AgoraExternalAudioProcessor(AgoraService agoraService, AgoraMediaNodeFactory mediaNodeFactory, AgoraServiceConfig agoraServiceConfig)` Constructs an AgoraExternalAudioProcessor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `destroy()` Releases the external audio processor and associated resources.
    `int` | `initialize(AgoraApmConfig apmConfig, int outputSampleRate, int outputChannels, AgoraAudioVadConfigV2 vadConfig, IExternalAudioProcessorObserver observer)` Initializes the external audio processor with specified audio parameters.
    `private long` | `nativeCreate()` Native method to create the processor.
    `private int` | `nativeDestroy(long cptr)` Native method to destroy the processor.
    `private int` | `nativeInitialize(long cptr, long trackerCptr, java.lang.String apmConfigJson, boolean enableDump, int outputSampleRate, int outputChannels, AgoraExternalAudioProcessorObserverWrapper externalAudioProcessorObserverWrapper)` Native method to initialize the processor.
    `int` | `pushAudioPcmData(byte[] data, int sampleRate, int channels, long presentationMs)` Pushes PCM audio data for processing.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### cptr

          private long cptr

      Native pointer to the external audio processor

    - #### audioFrameSender

          private volatile AgoraAudioPcmDataSender audioFrameSender

      Audio PCM data sender

    - #### customAudioTrack

          private volatile AgoraLocalAudioTrack customAudioTrack

      Custom audio track

    - #### initialized

          private volatile boolean initialized

      Whether the processor has been initialized

    - #### agoraServiceConfig

          private AgoraServiceConfig agoraServiceConfig

      Agora service configuration

    - #### audioFrame

          private AudioFrame audioFrame

      Audio frame buffer

    - #### observerWrapper

          private volatile AgoraExternalAudioProcessorObserverWrapper observerWrapper

      Observer wrapper - must be kept alive to prevent GC

  - ### Constructor Detail

    - #### AgoraExternalAudioProcessor

          AgoraExternalAudioProcessor(AgoraService agoraService,
                                      AgoraMediaNodeFactory mediaNodeFactory,
                                      AgoraServiceConfig agoraServiceConfig)

      Constructs an AgoraExternalAudioProcessor.
      Parameters:
        `agoraService` - The Agora service instance
        `mediaNodeFactory` - The media node factory
        `agoraServiceConfig` - The Agora service configuration

  - ### Method Detail

    - #### initialize

          public int initialize(AgoraApmConfig apmConfig,
                                int outputSampleRate,
                                int outputChannels,
                                AgoraAudioVadConfigV2 vadConfig,
                                IExternalAudioProcessorObserver observer)

      Initializes the external audio processor with specified audio parameters.
      Parameters:
        `apmConfig` - The APM (Audio Processing Module) configuration
        `outputSampleRate` - The output sample rate (e.g., 16000, 48000)
        `outputChannels` - The output number of channels (1 for mono, 2 for stereo)
        `vadConfig` - The VAD (Voice Activity Detection) configuration
        `observer` - The observer for receiving processed audio frames
      Returns:
        0 on success, negative value on failure

    - #### pushAudioPcmData

          public int pushAudioPcmData(byte[] data,
                                      int sampleRate,
                                      int channels,
                                      long presentationMs)

      Pushes PCM audio data for processing.
      Parameters:
        `data` - The PCM audio data buffer
        `sampleRate` - The sample rate
        `channels` - The number of channels
        `presentationMs` - The presentation timestamp in milliseconds
      Returns:
        0 on success, negative value on failure

    - #### destroy

          public int destroy()

      Releases the external audio processor and associated resources.
      Returns:
        0 on success, negative value on failure

    - #### nativeCreate

          private long nativeCreate()

      Native method to create the processor.
      Returns:
        Native pointer

    - #### nativeInitialize

          private int nativeInitialize(long cptr,
                                       long trackerCptr,
                                       java.lang.String apmConfigJson,
                                       boolean enableDump,
                                       int outputSampleRate,
                                       int outputChannels,
                                       AgoraExternalAudioProcessorObserverWrapper externalAudioProcessorObserverWrapper)

      Native method to initialize the processor.
      Parameters:
        `cptr` - Native pointer
        `trackerCptr` - Native pointer to the audio track
        `apmConfigJson` - APM configuration in JSON format
        `enableDump` - Whether to enable dump
        `outputSampleRate` - Output sample rate
        `outputChannels` - Output channels
        `externalAudioProcessorObserverWrapper` - Observer for callbacks
      Returns:
        Result code

    - #### nativeDestroy

          private int nativeDestroy(long cptr)

      Native method to destroy the processor.
      Parameters:
        `cptr` - Native pointer
      Returns:
        0 on success, negative value on failure