Add audio¶
Place a clip on the project's audio timeline, select the part of its source you want, then adjust its sound. Rendering includes authored audio by default. Audio placement is independent of visual layers: moving a title does not move its soundtrack.
Place and trim a clip¶
Start soundtrack.py with your own assets/music.wav. The file must contain
at least fourteen seconds of audio. This project plays source seconds 4–14
starting at project second 2, after two seconds of silence:
The render calls below use overwrite=True; rerunning a script replaces its
named output files.
from vestra import Project, Text
project = Project(
size=(640, 360),
fps=30,
duration=12,
background="#101c24",
)
project.root.add(Text("Soundtrack excerpt", font_size=32, fill="#eff4ec"))
music = project.audio.track("music")
soundtrack = music.add(
"assets/music.wav",
start=2,
trim_start=4,
trim_end=14,
)
Keep the clocks explicit¶
Changing start moves the excerpt on the project timeline. Changing a trim
boundary selects different source audio. Before any playback-speed effect,
project second 7 therefore reads source second 9, five seconds into the clip.
| Value | Meaning |
|---|---|
start=2 |
Place this clip at project second 2. |
trim_start=4, trim_end=14 |
Read source seconds 4–14. |
fade_in=0.25 |
Fade over the first quarter-second of the selected clip. |
| Gain-automation keyframe time | Time since the selected clip starts, rather than project time or source-file position. |
At normal playback speed, an excerpt's duration is trim_end - trim_start.
A clip-scoped playback-speed effect changes that output duration. See
the audio reference for supported effects and
validation limits.
Set levels and fades¶
Continue soundtrack.py with the same clip and track:
Clip gain 0.8 applies before track gain 0.9. The quarter-second fade in and
half-second fade out are within the selected excerpt. Keep headroom when mixing
several clips: gains multiply through the processing scopes, and overlapping
clips add together.
Process the intended scope¶
| Attach effects to | What changes |
|---|---|
soundtrack.effects |
This clip only. |
music.effects |
All clips mixed on the music track. |
project.audio.effects |
All tracks in the master mix, including clips added later. |
Optionally continue the same project with clip playback speed and master EQ:
from vestra import BassBoost, PlaybackSpeed
soundtrack.effects.add(PlaybackSpeed(rate=1.05))
project.audio.effects.add(BassBoost(gain_db=3.0, frequency_hz=120.0))
PlaybackSpeed makes this clip shorter; the explicit twelve-second project
keeps its duration, leaving a short silent tail. The master BassBoost affects
every track. Effects run in authored stack order. Add a treatment at the scope
you intend rather than accumulating it at all three scopes.
Publish sound or retain analysis only¶
Finish soundtrack.py with:
This writes the twelve-second soundtrack.mp4 in the current directory and
replaces it on a rerun. Project(..., output_audio=None) follows whether clips
exist. Set project.output_audio = True or False to choose explicitly.
Disabling publication retains the prepared master mix needed by
signals and spectrum sources.
Crossfade two clips¶
An audio crossfade blends overlapping clips; it is separate from a visual
transition. Start a new audio_crossfade.py using the same required
assets/music.wav. This example has no playback-speed effects:
from vestra import Project
project = Project(size=(640, 360), fps=30, duration=10)
music = project.audio.track("music")
outgoing = music.add("assets/music.wav", start=0, trim_start=0, trim_end=6)
incoming = music.add("assets/music.wav", start=4, trim_start=6, trim_end=12)
project.audio.crossfade(outgoing, incoming)
project.render("audio-crossfade.mp4", backend="cpu", overwrite=True)
This writes audio-crossfade.mp4 in the current directory and replaces it on a
rerun. Its picture is the default black background. The outgoing clip ends at
project second 6; the incoming starts at second 4, so their two-second overlap
becomes matching fade-out and fade-in durations.
The helper does not move clips or add a visual transition. It needs an existing
positive overlap and an explicit outgoing trim_end; conflicting fade settings
are rejected. It calculates overlap from authored trim spans, so do not use it
to infer overlap after a duration-changing playback-speed effect. See
audio contracts.
Try an example with no external recording¶
The audio response program generates its own bass-and-melody phrase and renders silent videos with a waveform, playhead and measured response curves:
It replaces audio-pulses.wav, audio-bounded.mp4, audio-smoothing.mp4 and
audio-spectra.mp4 in the current directory. Continue with the
audio-reactivity guide to make a visual
respond to that recording.