Web

更新时间:
复制 MD 格式

By reading this article, you can learn how to output audio data.

Output audio data

  1. Enable audio data receiving callback.
    aliWebrtc.enableAudioVolumeIndicator = true;
    Note This interface can be opened at any time after instantiation.
  2. Use the audio energy value callback.
    aliWebrtc.on("onAudioLevel", (data) => {
      console.log(data)
    })
    Note This callback can be invoked only after you call the enableAudioVolumeIndicator method to enable audio callbacks. After that, this callback returns the maximum volume of the audio track every second.
    Return value description:
    • After you ingest an audio stream, you can obtain the information about the audio stream in the returned array. The user ID for your audio stream is 0.
    • If you subscribe to remote audio streams, the returned array contains information about the remote audio streams.
    • The following table describes the parameters in the returned array.
      ParameterTypeDescription
      userIdStringThe ID of the user who ingests the stream for an audio track. The user ID for your audio track is 0.
      displayNameStringThe display name of the user.
      levelNumberThe volume of the audio track. Valid values: 0 to 100.
      bufferArrayThe pulse-code modulation (PCM) audio data in each second.
  3. Disable the audio data reception callback.
    If you need to stop receiving audio data, you can set Disable Audio Data Receiving.
    aliWebrtc.enableAudioVolumeIndicator = false;