Aduio Panning in Unity WebGL?

I need to play one audio clip in left ear and second audio clip at right ear, both simulatenously. I have tried using stereoPan and spatial positioning using 3d audio as a workaround, neither works.

audioLeft.clip = audioClips[audioClipIndex];

//Solution 1
audioLeft.panStereo = -1f;

//Solution 2
audioLeft.spatialBlend = 1f; // 3D sound
audioLeft.spread = 0f;        
audioLeft.transform.position = new Vector3(-10f, 0f, 1f);

audioLeft.Play();

//Same code for audioRight

Unity docs specifically mention that panning is supported on WebGL

The AudioSource API supports basic positional audio playback, including:

  • Pausing and resuming
  • Panning
  • Rolloff
  • Pitch setting
  • Doppler effect support

yet in the docs, I dont see any exposed panning api.

I had upgraded project multiple times to see if the issue is related to Unity version
( from 2022.13 to to 2022.3.32 to 2023.1.5 )

None of these solutions work. I am now messing around with directly accessing webaudio through jslib, which is a headache due to the complexity of the code that would be essentially two lines of code with working default stereoPanning in Unity.

I have checked that panning audio using webaudio is working just fine through regular javascript on regular website, so that’s possible. Not sure why Unity is not making panning avaialable through the api.

Any tips how to make this work appreaciated.

Edit: If anyone encounters this issue, I implemented solution through javascript web audio. Could not find any other solution. Nothing in Unity worked, neither basic solution with HtmlAudioElement. Only thing that worked for me was Web Audio api.

Hi!

This seems to be an error in the documentation the Web platform does not support stereo audio panning. However, 3D positional audio should work. You can simulate the 2D panning behavior if you attach the AudioListener to a GameObject (not the main camera as per default!) and place it at 0,0,0. You can then place the audio sources to the left or right of the AudioListener to simulate stereo audio panning.