ILocalSpatialAudioEngine

This class implements spatial audio by calculating user coordinates through the SDK.

This class inherits from IBaseSpatialAudioEngine. Before calling other APIs under this class, you need to call the initialize method to initialize it.

clearRemotePositions

Deletes the spatial position information of all remote users.

abstract clearRemotePositions(): number;

After successfully calling this method, the local user will no longer hear any remote users. After leaving the channel, you can also call this method to delete all remote users' spatial position information to avoid wasting computing resources.

Return Values

  • 0: Success.
  • < 0: Failure. See Error Codes for details and resolution suggestions.

removeRemotePosition

Deletes the spatial position information of the specified remote user.

abstract removeRemotePosition(uid: number): number;

After this method is successfully called, the local user will no longer hear the specified remote user. To avoid wasting computational resources after leaving the channel, you need to call this method to remove the spatial position information of the specified remote user. Otherwise, the spatial position information of that user will be retained. When the number of remote users exceeds the maximum number of audio streams that can be received as set in setMaxAudioRecvCount, the SDK will automatically unsubscribe from the audio streams of the farthest users based on relative distance.

Parameters

uid
User ID. Must match the user ID used when the user joined the channel.

Return Values

  • 0: Success.
  • < 0: Failure. See Error Codes for details and resolution suggestions.

setRemoteAudioAttenuation

Sets the audio attenuation effect for the specified user.

abstract setRemoteAudioAttenuation(
    uid: number,
    attenuation: number,
    forceSet: boolean
  ): number;

Parameters

uid
User ID. Must be the same as the user ID used when joining the channel.
attenuation
The audio attenuation coefficient for the user. The range is [0,1].
forceSet
Whether to force the audio attenuation effect for the user:
  • true: Forces the use of attenuation to set the user's audio attenuation effect. In this case, the audioAttenuation set in SpatialAudioZone does not take effect for this user.
  • false: Does not force the use of attenuation to set the user's audio attenuation effect. There are two cases:
    • If the audio source and listener are inside and outside the sound insulation zone respectively, the attenuation effect is determined by audioAttenuation in SpatialAudioZone.
    • If the audio source and listener are both inside the same sound insulation zone or both outside, the attenuation effect is determined by attenuation in this method.

Return Values

  • 0: Success.
  • < 0: Failure. See Error Codes for details and resolution suggestions.

updateRemotePosition

Updates the spatial position information of a remote user.

abstract updateRemotePosition(
    uid: number,
    posInfo: RemoteVoicePositionInfo
  ): number;

After successfully calling this method, the SDK calculates spatial audio parameters based on the relative positions of the local and remote users.

Note: This method must be called after joinChannel.

Parameters

uid
User ID. Must be the same as the user ID used when the user joined the channel.
posInfo
Spatial position information of the remote user. See RemoteVoicePositionInfo.

Return Values

  • 0: Success.
  • < 0: Failure. See Error Codes for details and resolution suggestions.