Skip to Content
Welcome to Diffusion Studio Core v4.0 - Now Available! 🎉

Audio Clip

This guide will walk you through the steps of splitting an audio file into multiple clips, offsetting the start time of each clip, and trimming them.

Manual Approach

Setup

First, let’s fetch an MP3 file of a piano recording and create an audio clip from it:

import * as core from '@diffusionstudio/core'; const source = await core.Source.from<core.AudioSource>('https://diffusion-studio-public.s3.eu-central-1.amazonaws.com/audio/piano.mp3'); const layer = await composition.add(new core.Layer()); const clip0 = await layer.add(new core.AudioClip(source));

Hint: The MP3 file contains 16 seconds of audio.

Splitting the AudioClip

Splitting a clip creates a new copy of the clip that starts after the specified split time (in seconds). The original clip is shortened to end at the split time.

const clip1 = await clip0.split(8);

In this example, 8 represents the midpoint of the audio clip.

Manipulating the Clips

We can then manipulate each clip individually:

clip0.range = [0.5, 4]; clip0.delay = -0.5;

This code trims the first clip from 0.5s to 4s and offsets it by -0.5s, moving it to the start of the composition.

clip1.range = [14, 16] clip1.delay = clip0.end - 14; clip1.volume = 0.5;

For the second clip:

  • It is trimmed from 14s to 16s.
  • Its start is then aligned with the end of the first clip.
  • The volume is then set to 50% of the digital maximum.

Automated Approach

To achieve the same result more efficiently, we can use a sequential layer:

const layer = await composition.add( new core.Layer({ mode: 'SEQUENTIAL' }) ); await layer.add(new core.AudioClip(source)); await layer.clips[0].split(8); // Split the first clip layer.clips[0].range = [0.5, 4]; layer.clips[1].range = [14, 16];

The delay will be automatically adjusted to align the clips

Removing Silences

The AudioClip also makes it easy to remove silences from the audio.

await clip.removeSilences();

This will remove all silences from the audio clip. Keep in mind that the clip must be added to a composition for this to work.

Last updated on