Skip to content

API Variable Audio

github-actions[bot] edited this page Nov 24, 2026 · 5 revisions

Variable: Audio

const Audio: object;

Defined in: src/plugins/audio/runtime/Audio.ts:255

One-shot and global audio helpers.

Type Declaration

snapshot

snapshot: (name, fadeSeconds?) => AudioSnapshot = snapshotOf;

A snapshot of the project's mix by name (ADR 0344): Audio.snapshot("Underwater").start() and .stop() fade it in and out over its own times, blending with the other snapshots on (priority, Override or Add). With fadeSeconds, the shorthand: fade to it over that time, fading out the other snapshots game code started.

Audio.snapshot(name): the snapshot's handle; Audio.snapshot(name, fadeSeconds): the shorthand (fade to it), and its handle.

Parameters

name

string

fadeSeconds?

number

Returns

AudioSnapshot

buses

Get Signature

get buses(): readonly string[];

Names of the project's buses.

Returns

readonly string[]

calibration

Get Signature

get calibration(): number;

Seconds, default 0: subtracted from an input's offset (judged = offset - calibration). Kept per output device.

Returns

number

Set Signature

set calibration(seconds): void;
Parameters
seconds

number

Returns

void

calibrationStale

Get Signature

get calibrationStale(): boolean;

True after the output device changed, until a new calibration is set; the old value is kept meanwhile.

Returns

boolean

capture

Get Signature

get capture(): AudioCapture;

Record a take of the mix for the Profiler: await Audio.capture.start(), then Audio.capture.save(). The recorder loads on the first start(); a game that never calls it loads nothing.

Returns

AudioCapture

dialogue

Get Signature

get dialogue(): AudioDialogue;

ADR 0355 §5: the speaker channels and the dialogue memory.

Returns

AudioDialogue

horizon

Get Signature

get horizon(): number;

Seconds, read-only: the earliest heard time a stamped start is exact for a decoded clip (now + lookahead). Not a promise for a streamed clip (those need priming). On a backend without it: Audio.time.

Returns

number

language

Get Signature

get language(): string;

The current audio language (a shipped voice language's code). Setting it is void Audio.setLanguage(code).

Returns

string

Set Signature

set language(code): void;
Parameters
code

string

Returns

void

languages

Get Signature

get languages(): readonly AudioLanguage[];

The shipped voice languages: code, name and own fallbacks.

Returns

readonly AudioLanguage[]

latency

Get Signature

get latency(): AudioLatency;

Seconds, read-only: base, output and limiter latency, their total, and whether the output figure is reliable.

Returns

AudioLatency

loudnessTarget

Get Signature

get loudnessTarget(): string | null;

The entry of audio.loudnessTargets the loudness meters check against (default the first); an unknown name is ignored with one warning.

Returns

string | null

Set Signature

set loudnessTarget(name): void;
Parameters
name

string | null

Returns

void

masterVolume

Get Signature

get masterVolume(): number;

Same property as volume; kept.

Returns

number

Set Signature

set masterVolume(v): void;
Parameters
v

number

Returns

void

muted

Get Signature

get muted(): boolean;

Mute everything.

Returns

boolean

Set Signature

set muted(m): void;
Parameters
m

boolean

Returns

void

packages

Get Signature

get packages(): readonly AudioPackage[];

ADR 0351 §9: every package this game has for its platform, in audio.json's order.

Returns

readonly AudioPackage[]

pendingLanguage

Get Signature

get pendingLanguage(): string | null;

The language a switch in progress goes to; null when none is.

Returns

string | null

rhythmMode

Get Signature

get rhythmMode(): boolean;

Read-only: the project's audio.rhythmMode setting.

Returns

boolean

status

Get Signature

get status(): AudioStatus;

"locked" until the browser allows audio, "running", or "failed".

Returns

AudioStatus

subtitleLanguage

Get Signature

get subtitleLanguage(): string | null;

The language subtitles resolve in; null (default) follows the text language (Locale.language).

Returns

string | null

Set Signature

set subtitleLanguage(code): void;
Parameters
code

string | null

Returns

void

take

Get Signature

get take(): AudioTake;

ADR 0348: record a take of the game run for the audio designer: what the game asked of audio and the engine's profile, in one *.sporesample file. await Audio.take.start(), Audio.take.mark("boss"), then Audio.take.save(). The recorder loads on the first start(); a game that never calls it loads nothing.

Returns

AudioTake

time

Get Signature

get time(): number;

The heard audio clock in seconds: 0 before the context runs; independent of game pause and Time.scale; updated once per frame.

Returns

number

volume

Get Signature

get volume(): number;

Master volume, 0..1. New alias of masterVolume (ADR 0157 delta D1).

Returns

number

Set Signature

set volume(v): void;
Parameters
v

number

Returns

void

bus()

bus(name): Bus;

A mixer bus by name (ADR 0097): Audio.bus("Music").volume = 0.5.

Parameters

name

string

Returns

Bus

clearSnapshot()

clearSnapshot(fadeSeconds?): void;

Fade out every snapshot game code started (the shorthand's way back to the plain mix). Default fade 0.5 s.

Parameters

fadeSeconds?

number = 0.5

Returns

void

debug()

debug(): AudioDebugState;

A copy of the state for tools and "why is there no sound?". Allocates; never per frame.

Returns

AudioDebugState

getParameter()

getParameter(name): string | number | undefined;

A global audio parameter's value (a label for labelled ones); undefined if there is none by that name.

Parameters

name

string

Returns

string | number | undefined

line()

line(key, options?): AudioLineHandle;

ADR 0354 §5: play a voice-over line by key (keys are unique across the project's line tables), through its table's template or as a one-shot Clip on its table's output, in the current language's file (falling back through its chain). A line no language has runs subtitle-only for its reading time (localisation.missing: "subtitleOnly"). An unknown key gives an inert handle with reason "unknownLine". Plays now (no queueing: Audio.say has channels). Never throws.

Parameters

key

string

options?

LineOptions

Returns

AudioLineHandle

onCaption()

onCaption(fn): () => void;

ADR 0357 §4: hear the captions of playlists that have one, as their instances start sounding and end. Returns the unsubscribe.

Parameters

fn

(e) => void

Returns

() => void

onLine()

onLine(fn): () => void;

ADR 0354 §5: hear every line's start, end and Cue marker events, with its subtitle. Returns the unsubscribe.

Parameters

fn

(e) => void

Returns

() => void

package()

package(name): AudioPackage;

ADR 0351 §9: a package of sounds from audio.json (Wwise's SoundBanks, FMOD's banks): await Audio.package("Forest").load() before playing its sounds, unload() when they're done. Loads are reference-counted; an unknown name gives a handle whose load() rejects, with one warning. With strict packaging (the default) a packaged sound whose packages are all unloaded doesn't play: its handle's reason is "notLoaded".

Parameters

name

string

Returns

AudioPackage

play()

play(pathOrSample, options?): AudioPlaylistHandle;

Play a playlist (*.playlist.json, ADR 0343), a sample or a sound generator (*.generator.json, ADR 0360; each as a one-entry Clip playlist). Always returns a handle (an inert one when nothing played: no World with the view, a missing asset, a trigger the playback rules refused, or an old audio event file, which is refused with a message naming the migration; Audio.debug().playlistTotals says why); never throws.

Parameters

pathOrSample

string

options?

EventOptions

Returns

AudioPlaylistHandle

playOneShot()

playOneShot(clip, options?): AudioHandle;

Start a clip once. A bare number is the volume. Always returns a handle (refused or failed plays give an inert one with playing false); never throws.

Parameters

clip

string

options?

number | OneShotOptions

Returns

AudioHandle

say()

say(event, options?): AudioLineHandle;

ADR 0355 §5: say a dialogue event: it picks a line by best match over its arguments (options.args, else the global parameters, else the defaults) and speaks it on a speaker channel, with priority, interruption, queueing, cooldowns and memory. An unknown event gives an inert handle with reason "unknownEvent". Never throws.

Parameters

event

string

options?

SayOptions

Returns

AudioLineHandle

setLanguage()

setLanguage(code, options?): Promise<void>;

Switch the audio language atomically: the new language's package parts load first, then Audio.language changes in one step and is remembered (player storage, when the project remembers it). playing: "finish" (default) lets voice-over playing in the old language finish; "stop" stops it with a 50 ms fade. An unknown or unshipped code rejects with one warning and changes nothing; a later switch supersedes a pending one.

Parameters

code

string

options?

SetLanguageOptions

Returns

Promise<void>

setParameter()

setParameter(name, value): void;

Set a global audio parameter (the Studio's Parameters; labelled ones by label). Snapshots started by conditions on it follow (ADR 0344).

Parameters

name

string

value

string | number

Returns

void

timeAt()

timeAt(performanceTime): number;

The raw heard time (seconds, Audio.time's base) of a performance.now() instant in ms, such as event.timeStamp. Calibration is never applied here. Audio.time before the clock has an estimate.

Parameters

performanceTime

number

Returns

number

Clone this wiki locally