Skip to main content

Add Audio

Use composition.addAudio() to add audio to a composition.

composition.addAudio() signature

addAudio(
    file: CompositionFile,
    config?: AudioLayerConfig,
): Promise<Audio>

Audio layer configuration

The config argument supports the following layer configuration properties:

Audio class

Calling composition.addAudio() returns an instance of the Audio class, which allows you to read/update its layer options and read/update its layer configuration through getters/setters.

Reading and updating layer options

audio.type; // "audio"

audio.setVolume(0.8);
audio.volume; // 0.8

audio.setMuted();
audio.volume; // 0

Examples

Minimal

await composition.addAudio(
"https://docs.editframe.com/layer-types/add-audio/audio-example.mp3"
);

Output

All layer configuration

await composition.addAudio(
// file
"https://docs.editframe.com/layer-types/add-audio/audio-example.mp3",

// options
{
volume: 0.5,
},

// config
{
timeline: {
start: 1,
},
trim: {
start: 1.5,
end: 5,
},
}
);

Output

Method Chaining Approach

const audio = await composition.addAudio(
"https://docs.editframe.com/layer-types/add-audio/audio-example.mp3"
);

audio

// Audio
.setVolume(0.5)

// Timeline
.setStart(1)

// Trim
.setTrim(
// start
1.5,
// end
5
);

Output