Skip to content

Sound

engine.sound: Web Audio, loaded by name with engine.load, quiet while the host pauses, shows a break or is muted.

await engine.load({ pop: 'sounds/pop.mp3' })
engine.sound.play('pop', { volume: 0.8 })
engine.sound.tone(880, 0.15)

new Sound(): Sound

The engine makes it (engine.sound); browsers unlock its audio on the first touch, key or click.

Sound

muted: boolean

Muted by the host (the TV’s sound is off): set by the engine.


volume: number

Master volume, 0–1.

context(): AudioContext | null

The audio context, made on first use (null without Web Audio).

AudioContext | null


load(name, url): Promise<void>

Decodes a sound file (mp3, aac, ogg, wav) under a name.

string

string

Promise<void>


has(name): boolean

Whether a sound of that name is loaded.

string

boolean


play(name, o?): () => void

Plays a loaded sound; returns stop().

string

PlayOptions

() => void


tone(freq, seconds?, o?): void

A short tone (a “ding”): frequency Hz, seconds, fading out.

number

number

ToneOptions

void


hold(): void

Pauses and breaks: everything stops until release().

void


release(): void

Sound again after hold().

void


destroy(): void

Closes the audio context.

void