ILocalSpatialAudioEngine

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

This class inherits from IBaseSpatialAudioEngine. Before calling other APIs in 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 not 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 computing resources after leaving the channel, you need to call this method to delete 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 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 be the same as the user ID used when joining 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, ranging from [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 apply to the user.
  • false: Does not force the use of attenuation to set the user's audio attenuation effect. There are two cases:
    • If the sound source and listener are inside and outside the sound insulation zone respectively, the attenuation effect is determined by audioAttenuation in SpatialAudioZone.
    • If the sound 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 the spatial audio parameters based on the relative position between 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 joining the channel.
posInfo
The spatial position information of the remote user. See RemoteVoicePositionInfo.

Return Values

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