• Public
  • Public/Protected
  • All

Class Sound

Defines a sound that can be played in the application. The sound can either be an ambient track or a simple sound played in reaction to a user action.




  • Sound




  • Create a sound and attach it to a scene


    • name: string

      Name of your sound

    • urlOrArrayBuffer: any

      Url to the sound to load async or ArrayBuffer, it also works with MediaStreams

    • scene: Scene

      defines the scene the sound belongs to

    • Optional readyToPlayCallback: Nullable<() => void>

      Provide a callback function if you'd like to load your code once the sound is ready to be played

    • Optional options: ISoundOptions

      Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel, streaming

    Returns Sound


autoplaySearch playground for autoplay

autoplay: boolean

Does the sound autoplay once loaded.

distanceModelSearch playground for distanceModel

distanceModel: string

Define the distance attenuation model the sound will follow.



isPausedSearch playground for isPaused

isPaused: boolean

Is this sound currently paused.

isPlayingSearch playground for isPlaying

isPlaying: boolean

Is this sound currently played.

maxDistanceSearch playground for maxDistance

maxDistance: number

Define the max distance the sound should be heard (intensity just became 0 at this point).



metadataSearch playground for metadata

metadata: any

Gets or sets an object used to store user defined information for the sound.

nameSearch playground for name

name: string

The name of the sound in the scene.

onEndedObservableSearch playground for onEndedObservable

onEndedObservable: Observable<Sound>

Observable event when the current playing sound finishes.

refDistanceSearch playground for refDistance

refDistance: number

Define the reference distance the sound should be heard perfectly.



rolloffFactorSearch playground for rolloffFactor

rolloffFactor: number

soundTrackIdSearch playground for soundTrackId

soundTrackId: number

The sound track id this sound belongs to.

spatialSoundSearch playground for spatialSound

spatialSound: boolean

useCustomAttenuationSearch playground for useCustomAttenuation

useCustomAttenuation: boolean

Does the sound use a custom attenuation curve to simulate the falloff happening when the source gets further away from the camera.





  • get currentTime(): number
  • Gets the current time for the sound.

    Returns number


  • get directionalConeInnerAngle(): number
  • set directionalConeInnerAngle(value: number): any
  • Gets or sets the inner angle for the directional cone.

    Returns number

  • Gets or sets the inner angle for the directional cone.


    • value: number

    Returns any


  • get directionalConeOuterAngle(): number
  • set directionalConeOuterAngle(value: number): any
  • Gets or sets the outer angle for the directional cone.

    Returns number

  • Gets or sets the outer angle for the directional cone.


    • value: number

    Returns any


  • get loop(): boolean
  • set loop(value: boolean): any
  • Does the sound loop after it finishes playing once.

    Returns boolean

  • Does the sound loop after it finishes playing once.


    • value: boolean

    Returns any


attachToMeshSearch playground for attachToMesh

cloneSearch playground for clone

  • Clone the current sound in the scene.

    Returns Nullable<Sound>

    the new sound clone

connectToSoundTrackAudioNodeSearch playground for connectToSoundTrackAudioNode

  • connectToSoundTrackAudioNode(soundTrackAudioNode: AudioNode): void
  • Connect this sound to a sound track audio node like gain...


    • soundTrackAudioNode: AudioNode

      the sound track audio node to connect to

    Returns void

detachFromMeshSearch playground for detachFromMesh

  • detachFromMesh(): void

disposeSearch playground for dispose

  • dispose(): void
  • Release the sound and its associated resources

    Returns void

getAudioBufferSearch playground for getAudioBuffer

  • getAudioBuffer(): Nullable<AudioBuffer>
  • Gets the current underlying audio buffer containing the data

    Returns Nullable<AudioBuffer>

    the audio buffer

getClassNameSearch playground for getClassName

  • getClassName(): string
  • Get the current class name.

    Returns string

    current class name

getSoundGainSearch playground for getSoundGain

  • Gets the WebAudio GainNode, gives you precise control over the gain of instances of this Sound.

    Returns Nullable<GainNode>

    the gain node

getSoundSourceSearch playground for getSoundSource

  • getSoundSource(): Nullable<AudioBufferSourceNode>
  • Gets the WebAudio AudioBufferSourceNode, lets you keep track of and stop instances of this Sound.

    Returns Nullable<AudioBufferSourceNode>

    the source node

getVolumeSearch playground for getVolume

  • getVolume(): number
  • Gets the volume of the sound.

    Returns number

    the volume of the sound

isReadySearch playground for isReady

  • isReady(): boolean
  • Gets if the sounds is ready to be played or not.

    Returns boolean

    true if ready, otherwise false

pauseSearch playground for pause

  • pause(): void
  • Put the sound in pause

    Returns void

playSearch playground for play

  • play(time?: number, offset?: number, length?: number): void
  • Play the sound


    • Optional time: number

      (optional) Start the sound after X seconds. Start immediately (0) by default.

    • Optional offset: number

      (optional) Start the sound at a specific time in seconds

    • Optional length: number

      (optional) Sound duration (in seconds)

    Returns void

serializeSearch playground for serialize

  • serialize(): any
  • Serializes the Sound in a JSON representation

    Returns any

    the JSON representation of the sound

setAttenuationFunctionSearch playground for setAttenuationFunction

  • setAttenuationFunction(callback: (currentVolume: number, currentDistance: number, maxDistance: number, refDistance: number, rolloffFactor: number) => number): void
  • Parameters

    • callback: (currentVolume: number, currentDistance: number, maxDistance: number, refDistance: number, rolloffFactor: number) => number

      Defines the function used for the attenuation

        • (currentVolume: number, currentDistance: number, maxDistance: number, refDistance: number, rolloffFactor: number): number
        • Parameters

          • currentVolume: number
          • currentDistance: number
          • maxDistance: number
          • refDistance: number
          • rolloffFactor: number

          Returns number

    Returns void

setAudioBufferSearch playground for setAudioBuffer

  • setAudioBuffer(audioBuffer: AudioBuffer): void
  • Sets the data of the sound from an audiobuffer


    • audioBuffer: AudioBuffer

      The audioBuffer containing the data

    Returns void

setDirectionalConeSearch playground for setDirectionalCone

  • setDirectionalCone(coneInnerAngle: number, coneOuterAngle: number, coneOuterGain: number): void
  • Transform this sound into a directional source


    • coneInnerAngle: number

      Size of the inner cone in degree

    • coneOuterAngle: number

      Size of the outer cone in degree

    • coneOuterGain: number

      Volume of the sound outside the outer cone (between 0.0 and 1.0)

    Returns void

setLocalDirectionToMeshSearch playground for setLocalDirectionToMesh

  • setLocalDirectionToMesh(newLocalDirection: Vector3): void
  • Sets the local direction of the emitter if spatial sound is enabled


    • newLocalDirection: Vector3

      Defines the new local direction

    Returns void

setPlaybackRateSearch playground for setPlaybackRate

  • setPlaybackRate(newPlaybackRate: number): void
  • Set the sound play back rate


    • newPlaybackRate: number

      Define the playback rate the sound should be played at

    Returns void

setPositionSearch playground for setPosition

  • setPosition(newPosition: Vector3): void
  • Sets the position of the emitter if spatial sound is enabled


    • newPosition: Vector3

      Defines the new position

    Returns void

setVolumeSearch playground for setVolume

  • setVolume(newVolume: number, time?: number): void
  • Sets a dedicated volume for this sounds


    • newVolume: number

      Define the new volume of the sound

    • Optional time: number

      Define time for gradual change to new volume

    Returns void

stopSearch playground for stop

  • stop(time?: number): void
  • Stop the sound


    • Optional time: number

      (optional) Stop the sound after X seconds. Stop immediately (0) by default.

    Returns void

switchPanningModelToEqualPowerSearch playground for switchPanningModelToEqualPower

  • switchPanningModelToEqualPower(): void

switchPanningModelToHRTFSearch playground for switchPanningModelToHRTF

  • switchPanningModelToHRTF(): void

updateOptionsSearch playground for updateOptions

  • Updates the current sounds options such as maxdistance, loop...


    • options: ISoundOptions

      A JSON object containing values named as the object properties

    Returns void

Static ParseSearch playground for Parse

  • Parse(parsedSound: any, scene: Scene, rootUrl: string, sourceSound?: Sound): Sound
  • Parse a JSON representation of a sound to instantiate in a given scene


    • parsedSound: any

      Define the JSON representation of the sound (usually coming from the serialize method)

    • scene: Scene

      Define the scene the new parsed sound should be created in

    • rootUrl: string

      Define the rooturl of the load in case we need to fetch relative dependencies

    • Optional sourceSound: Sound

      Define a sound place holder if do not need to instantiate a new one

    Returns Sound

    the newly parsed sound


  • Constructor
  • Property
  • Method
  • Accessor
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method