e01.org

AudioListener

Web Audio API

Web Audio API

The `AudioListener` interface represents the position and orientation of the unique person listening to the audio scene, and is used in [audio spatialization](/docs/Web/API/Web_Audio_API/Web_audio_spatialization_basics). All PannerNodes spatialize in relation to the `AudioListener` stored in the BaseAudioContext.listener attribute.

It is important to note that there is only one listener per context and that it isn't an AudioNode.

![We see the position, up and front vectors of an AudioListener, with the up and front vectors at 90° from the other.](webaudiolistenerreduced.png)

## Instance properties

> [!NOTE]
> The position, forward, and up value are set and retrieved using different syntaxes. Retrieval is done by accessing, for example, `AudioListener.positionX`, while setting the same property is done with `AudioListener.positionX.value`.

- AudioListener.positionX
- : Represents the horizontal position of the listener in a right-hand cartesian coordinate system. The default is 0.
- AudioListener.positionY
- : Represents the vertical position of the listener in a right-hand cartesian coordinate system. The default is 0.
- AudioListener.positionZ
- : Represents the longitudinal (back and forth) position of the listener in a right-hand cartesian coordinate system. The default is 0.
- AudioListener.forwardX
- : Represents the horizontal position of the listener's forward direction in the same cartesian coordinate system as the position (`positionX`, `positionY`, and `positionZ`) values. The forward and up values are linearly independent of each other. The default is 0.
- AudioListener.forwardY
- : Represents the vertical position of the listener's forward direction in the same cartesian coordinate system as the position (`positionX`, `positionY`, and `positionZ`) values. The forward and up values are linearly independent of each other. The default is 0.
- AudioListener.forwardZ
- : Represents the longitudinal (back and forth) position of the listener's forward direction in the same cartesian coordinate system as the position (`positionX`, `positionY`, and `positionZ`) values. The forward and up values are linearly independent of each other. The default is -1.
- AudioListener.upX
- : Represents the horizontal position of the top of the listener's head in the same cartesian coordinate system as the position (`positionX`, `positionY`, and `positionZ`) values. The forward and up values are linearly independent of each other. The default is 0.
- AudioListener.upY
- : Represents the vertical position of the top of the listener's head in the same cartesian coordinate system as the position (`positionX`, `positionY`, and `positionZ`) values. The forward and up values are linearly independent of each other. The default is 1.
- AudioListener.upZ
- : Represents the longitudinal (back and forth) position of the top of the listener's head in the same cartesian coordinate system as the position (`positionX`, `positionY`, and `positionZ`) values. The forward and up values are linearly independent of each other. The default is 0.

## Instance methods

- AudioListener.setOrientation()
- : Sets the orientation of the listener.
- AudioListener.setPosition()
- : Sets the position of the listener.

> [!NOTE]
> Although these methods are deprecated they are currently the only way to set the orientation and position in Firefox (see [Firefox bug 1283029](https://bugzil.la/1283029)).

## Deprecated features

The `setOrientation()` and `setPosition()` methods have been replaced by setting their property value equivalents. For example `setPosition(x, y, z)` can be achieved by setting `positionX.value`, `positionY.value`, and `positionZ.value` respectively.

## Example

See [`BaseAudioContext.createPanner()`](/docs/Web/API/BaseAudioContext/createPanner#examples) for example code.

## Specifications

## Browser compatibility

## See also

- [Using the Web Audio API](/docs/Web/API/Web_Audio_API/Using_Web_Audio_API)

source: MDN Web Docs mirror · page

Cite this

"AudioListener". MDN Web Docs. CC BY-SA 2.5 (MDN). https://developer.mozilla.org/en-US/docs/Web/API/AudioListener

JSON record · API collection · BibTeX · RIS · CSL-JSON · citation policy

Save to pass ·