[page:Object3D] →

# [name]

Create a non-positional ( global ) audio object.
This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].

## Example

[example:webaudio_sandbox webaudio / sandbox ]
[example:webaudio_visualizer webaudio / visualizer ]

`// create an AudioListener and add it to the camera var listener = new THREE.AudioListener(); camera.add( listener ); // create a global audio source var sound = new THREE.Audio( listener ); // load a sound and set it as the Audio object's buffer var audioLoader = new THREE.AudioLoader(); audioLoader.load( 'sounds/ambient.ogg', function( buffer ) { sound.setBuffer( buffer ); sound.setLoop( true ); sound.setVolume( 0.5 ); sound.play(); });`

## Constructor

### [name]( [param:AudioListener listener] )

listener — (required) [page:AudioListener AudioListener] instance.

## Properties

### [property:Boolean autoplay]

Whether to start playback automatically. Default is *false*.

### [property:AudioContext context]

The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener listener] given in the constructor.

### [property:Number detune]

Modify pitch, measured in cents. +/- 100 is a semitone. +/- 1200 is an octave. Default is *0*.

### [property:Array filters]

Represents an array of [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNodes]. Can be used to apply a variety of low-order filters to create more complex sound effects. Filters are set via [page:Audio.setFilter] or [page:Audio.setFilters].

### [property:GainNode gain]

A [link:https://developer.mozilla.org/en-US/docs/Web/API/GainNode GainNode] created using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createGain AudioContext.createGain]().

### [property:Boolean hasPlaybackControl]

Whether playback can be controlled using the [page:Audio.play play](), [page:Audio.pause pause]() etc. methods. Default is *true*.

### [property:Boolean isPlaying]

Whether the audio is currently playing.

### [property:AudioListener listener]

A reference to the listener object of this audio.

### [property:Number playbackRate]

Speed of playback. Default is *1*.

### [property:Number offset]

An offset to the time within the audio buffer that playback should begin. Same as the *offset* parameter of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start AudioBufferSourceNode.start](). Default is *0*.

### [property:Number duration]

Overrides the duration of the audio. Same as the *duration* parameter of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start AudioBufferSourceNode.start](). Default is *undefined* to play the whole buffer.

### [property:String source]

An [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode AudioBufferSourceNode] created using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBufferSource AudioContext.createBufferSource]().

### [property:String sourceType]

Type of the audio source. Default is string 'empty'.

### [property:String type]

String denoting the type, set to 'Audio'.

## Methods

### [method:Audio connect]()

Connect to the [page:Audio.source]. This is used internally on initialisation and when setting / removing filters.

### [method:Audio disconnect]()

Disconnect from the [page:Audio.source]. This is used internally when setting / removing filters.

### [method:BiquadFilterNode getFilter]()

Returns the first element of the [page:Audio.filters filters] array.

### [method:Array getFilters]()

Returns the [page:Audio.filters filters] array.

### [method:Boolean getLoop]()

Return the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] (whether playback should loop).

### [method:GainNode getOutput]()

Return the [page:Audio.gain gainNode].

### [method:Float getPlaybackRate]()

Return the value of [page:Audio.playbackRate playbackRate].

### [method:Float getVolume]( value )

Return the current volume.

### [method:Audio play]( delay )

If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts playback.

### [method:Audio pause]()

If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses playback.

### [method:null onEnded]()

Called automatically when playback finished.

### [method:Audio setBuffer]( audioBuffer )

Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'buffer'.
If [page:Audio.autoplay autoplay], also starts playback.

### [method:Audio setFilter]( filter )

Applies a single [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNode] to the audio.

### [method:Audio setFilters]( [param:Array value] )

value - arrays of filters.
Applies an array of [link:https://developer.mozilla.org/en-US/docs/Web/API/BiquadFilterNode BiquadFilterNodes] to the audio.

### [method:Audio setLoop]( [param:Boolean value] )

Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] to *value* (whether playback should loop).

### [method:Audio setLoopStart]( [param:Float value] )

Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loopStart source.loopStart] to *value*.

### [method:Audio setLoopEnd]( [param:Float value] )

Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loopEnd source.loopEnd] to *value*.

### [method:Audio setMediaElementSource]( mediaElement )

Applies the given object of type [link:https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement HTMLMediaElement] as the source of this audio.
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.

### [method:Audio setMediaStreamSource]( mediaStream )

Applies the given object of type [link:https://developer.mozilla.org/en-US/docs/Web/API/MediaStream MediaStream] as the source of this audio.
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.

### [method:Audio setNodeSource]( audioNode )

Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'audioNode'.
Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.

### [method:Audio setPlaybackRate]( [param:Float value] )

If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the [page:Audio.playbackRate playbackRate] to *value*.

### [method:Audio setVolume]( [param:Float value] )

Set the volume.

### [method:Audio stop]()

If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops playback.

## Source

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]