Skip to main content

Class: AudioManager

Defined in: core/AudioManager.ts:91

Manages audio playback synchronized with the manim-web Scene timeline.

Usage:

const audio = new AudioManager();
await audio.addSound('/sounds/click.wav', { time: 0.5 });
audio.play(); // start playback
audio.seek(2.0); // jump to 2 s
const wav = await audio.exportWAV();

Constructors

Constructor

new AudioManager(): AudioManager

Returns

AudioManager

Accessors

context

Get Signature

get context(): AudioContext

Defined in: core/AudioManager.ts:136

Get the underlying AudioContext (creates one if needed).

Returns

AudioContext


isPlaying

Get Signature

get isPlaying(): boolean

Defined in: core/AudioManager.ts:356

Whether audio is currently playing.

Returns

boolean


tracks

Get Signature

get tracks(): readonly AudioTrack[]

Defined in: core/AudioManager.ts:349

Get a readonly copy of the current track list.

Returns

readonly AudioTrack[]

Methods

addSound()

addSound(url, options): Promise<AudioTrack>

Defined in: core/AudioManager.ts:175

Add a sound to the timeline.

Parameters

url

string

URL of the audio file

options

AddSoundOptions = {}

Scheduling and playback options

Returns

Promise<AudioTrack>

The created AudioTrack (buffer may still be loading)


addSoundAtAnimation()

addSoundAtAnimation(animation, url, options): Promise<AudioTrack>

Defined in: core/AudioManager.ts:208

Add a sound that starts when a given animation begins on the timeline.

The animation must already be scheduled (i.e. have a non-null startTime). If the animation has not been scheduled yet, time falls back to 0.

Parameters

animation

Animation

Animation whose start time to sync with

url

string

URL of the audio file

options

Omit<AddSoundOptions, "time"> & object = {}

Additional options (time is overridden by animation)

Returns

Promise<AudioTrack>

The created AudioTrack


clearTracks()

clearTracks(): void

Defined in: core/AudioManager.ts:339

Remove all tracks and stop playback.

Returns

void


createStreamDestination()

createStreamDestination(): MediaStreamAudioDestinationNode

Defined in: core/AudioManager.ts:448

Get an AudioNode destination suitable for muxing with a MediaRecorder. This creates a MediaStreamAudioDestinationNode that can be combined with a video stream for video+audio export.

Returns

MediaStreamAudioDestinationNode

MediaStreamAudioDestinationNode connected to the master gain


dispose()

dispose(): void

Defined in: core/AudioManager.ts:520

Release all audio resources.

Returns

void


exportWAV()

exportWAV(duration?, sampleRate?): Promise<Blob>

Defined in: core/AudioManager.ts:436

Export all audio tracks as a WAV Blob.

Parameters

duration?

number

Total duration (seconds). Defaults to getDuration().

sampleRate?

number = 44100

Sample rate. Defaults to 44100.

Returns

Promise<Blob>

WAV Blob


getCurrentTime()

getCurrentTime(): number

Defined in: core/AudioManager.ts:279

Get the current playback position on the timeline (seconds).

Returns

number


getDuration()

getDuration(): number

Defined in: core/AudioManager.ts:363

Get the total duration of the audio timeline (end of the latest track).

Returns

number


loadBuffer()

loadBuffer(url): Promise<AudioBuffer>

Defined in: core/AudioManager.ts:149

Load and decode an audio file, with caching.

Parameters

url

string

URL of the audio resource

Returns

Promise<AudioBuffer>

Decoded AudioBuffer


mixdown()

mixdown(duration?, sampleRate?): Promise<AudioBuffer>

Defined in: core/AudioManager.ts:383

Render all audio tracks into a single stereo AudioBuffer (offline).

Parameters

duration?

number

Total duration to render (seconds). Defaults to getDuration().

sampleRate?

number = 44100

Output sample rate. Defaults to 44100.

Returns

Promise<AudioBuffer>

Mixed-down AudioBuffer


pause()

pause(): void

Defined in: core/AudioManager.ts:239

Pause audio playback, remembering the current position.

Returns

void


play()

play(): void

Defined in: core/AudioManager.ts:225

Start (or resume) audio playback from the current position.

Returns

void


removeTrack()

removeTrack(trackId): void

Defined in: core/AudioManager.ts:321

Remove a track by id.

Parameters

trackId

number

Returns

void


seek()

seek(time): void

Defined in: core/AudioManager.ts:254

Seek to an absolute time on the timeline (seconds). If currently playing, audio restarts from the new position.

Parameters

time

number

Returns

void


setGlobalGain()

setGlobalGain(value): void

Defined in: core/AudioManager.ts:292

Set the master output volume.

Parameters

value

number

Gain value (0 = silent, 1 = unity)

Returns

void


setTrackGain()

setTrackGain(trackId, value): void

Defined in: core/AudioManager.ts:304

Set the gain for a specific track.

Parameters

trackId

number

Track identifier

value

number

Gain value (0 = silent, 1 = unity)

Returns

void


stop()

stop(): void

Defined in: core/AudioManager.ts:270

Stop playback and reset to the beginning.

Returns

void


audioBufferToWAV()

static audioBufferToWAV(buffer): Blob

Defined in: core/AudioManager.ts:462

Encode an AudioBuffer as a WAV Blob (PCM 16-bit).

Parameters

buffer

AudioBuffer

Returns

Blob