Used to play audio in a Lens. You can assign an AudioTrackAsset to play through script or through the AudioComponent's inspector in Lens Studio. See the Playing Audio guide for more information.

//@input Component.AudioComponent audio
// Play once
script.audio.play(1);
// Play forever
script.audio.play(-1);
// If playing, stop
if(script.audio.isPlaying())
{
script.audio.stop(true);
}
// Set a callback for when the sound stops playing
script.audio.setOnFinish(function()
{
print("sound finished playing");
});
interface AudioComponent {
    audioTrack: AudioTrackAsset;
    duration: number;
    enabled: boolean;
    fadeInTime: number;
    fadeOutTime: number;
    mixToSnap: boolean;
    playbackMode: Audio.PlaybackMode;
    position: number;
    recordingVolume: number;
    sceneObject: SceneObject;
    spatialAudio: SpatialAudio;
    uniqueIdentifier: string;
    volume: number;
    destroy(): void;
    getSceneObject(): SceneObject;
    getTransform(): Transform;
    getTypeName(): string;
    isOfType(type: string): boolean;
    isPaused(): boolean;
    isPlaying(): boolean;
    isSame(other: ScriptObject): boolean;
    pause(): boolean;
    play(loops: number): void;
    resume(): boolean;
    setOnFinish(eventCallback: ((audioComponent: AudioComponent) => void)): void;
    stop(fade: boolean): void;
}

Hierarchy (view full)

Properties

audioTrack: AudioTrackAsset

The audio asset currently assigned to play.

duration: number

The length (in seconds) of the current sound assigned to play.

enabled: boolean

If disabled, the Component will stop enacting its behavior.

fadeInTime: number

Length (in seconds) of a volume fade in applied to the beginning of sound playback.

fadeOutTime: number

Length (in seconds) of a volume fade out applied to the end of sound playback.

mixToSnap: boolean

When true, records sound directly into the snap. This mode works only when all Audio Components in the scene are using mix to snap. In this case input from microphone will be ignored.

playbackMode: Audio.PlaybackMode
position: number

The current playback time in seconds

recordingVolume: number

The volume of audio recorded to the snap, from 0 to 1.

sceneObject: SceneObject
spatialAudio: SpatialAudio

Spatial Audio settings.

uniqueIdentifier: string
volume: number

A volume multiplier for any sounds played by this AudioComponent.

Methods

  • Destroys the component.

    Returns void

  • Returns the name of this object's type.

    Returns string

  • Returns true if the object matches or derives from the passed in type.

    Parameters

    • type: string

    Returns boolean

  • Returns whether the sound is currently paused.

    Returns boolean

  • Returns whether the AudioComponent is currently playing sound.

    Returns boolean

  • Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

    Parameters

    Returns boolean

  • Pauses the sound.

    Returns boolean

  • Plays the current sound loops number of times. If loops is -1, the sound will repeat forever.

    Parameters

    • loops: number

    Returns void

  • Resumes a paused sound.

    Returns boolean

  • Sets the callback function to be called whenever this sound stops playing.

    Parameters

    Returns void

  • Stops the current sound if already playing.

    Parameters

    • fade: boolean

    Returns void