AudioFrame

Raw audio data.

public class AudioFrame {
    public byte[] bytes;
    public int sampleRataHz;
    public int bytesPerSample;
    public int channelNums;
    public int samplesPerChannel;
    public long timestamp;
    @CalledByNative
    public AudioFrame(byte[] bytes, int sampleRataHz, int bytesPerSample, int channelNums,
        int samplesPerChannel, long timestamp) {
      this.sampleRataHz = sampleRataHz;
      this.bytesPerSample = bytesPerSample;
      this.channelNums = channelNums;
      this.samplesPerChannel = samplesPerChannel;
      this.timestamp = timestamp;
      this.bytes = bytes;
    }
    @CalledByNative
    public byte[] getBytes() {
      return bytes;
    }
    @CalledByNative
    public int getBytesPerSample() {
      return bytesPerSample;
    }
    @CalledByNative
    public int getChannelNums() {
      return channelNums;
    }
    @CalledByNative
    public int getSampleRataHz() {
      return sampleRataHz;
    }
    @CalledByNative
    public int getSamplesPerChannel() {
      return samplesPerChannel;
    }
    @CalledByNative
    public long getTimestamp() {
      return timestamp;
    }
    @Override
    public String toString() {
      return "AudioFrame{sampleRataHz=" + sampleRataHz + ", bytesPerSample=" + bytesPerSample
          + ", channelNums=" + channelNums + ", samplesPerChannel=" + samplesPerChannel
          + ", timestamp=" + timestamp + '}';
    }
  }

Attributes

samplesPerChannel
The number of samples per channel in the audio frame.
bytesPerSample
The number of bytes per audio sample, which is usually 16-bit (2 bytes).
channelNums
The number of audio channels (the data are interleaved if it is stereo).
  • 1: Mono.
  • 2: Stereo.
sampleRataHz
The number of samples per channel in the audio frame.
bytes

The data buffer of the audio frame. When the audio frame uses a stereo channel, the data buffer is interleaved.

The size of the data buffer is as follows: buffer = samples ×channels × bytesPerSample.

timestamp
The timestamp (ms) of the audio frame.